Skip to content

Commit e4aafaf

Browse files
committed
refactor: use rolldown inject config for composable auto-imports during build
Replace the iles:composables transform plugin with Vite's build.rolldownOptions.transform.inject config option for builds, falling back to the existing transform-based auto-import for dev mode where the rolldown inject option is not available. https://claude.ai/code/session_01NZyaWN67FYx9xFUQP6nEFG
1 parent 35722be commit e4aafaf

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

packages/iles/src/node/plugin/composables.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ const composables = [
1414
'useRoute',
1515
]
1616

17+
export const composablesInjectConfig: Record<string, [string, string]> = Object.fromEntries(
18+
composables.map(name => [name, ['iles', name]]),
19+
)
20+
1721
export async function autoImportComposables (code: string, id: string): Promise<string | undefined> {
1822
const matches = Array.from(code.matchAll(composableUsageRegex))
1923
if (matches.length === 0) return

packages/iles/src/node/plugin/plugin.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { parseId } from './parse'
1414
import { wrapIslandsInSFC, wrapLayout } from './wrap'
1515
import { extendSite } from './site'
1616
import { detectMDXComponents } from './markdown'
17-
import { autoImportComposables, writeComposablesDTS } from './composables'
17+
import { autoImportComposables, composablesInjectConfig, writeComposablesDTS } from './composables'
1818
import documents from './documents'
1919

2020
function isMarkdown (path: string) {
@@ -159,7 +159,17 @@ export default function IslandsPlugins (appConfig: AppConfig): PluginOption[] {
159159
{
160160
name: 'iles:composables',
161161
enforce: 'post',
162+
config () {
163+
return {
164+
build: {
165+
rolldownOptions: {
166+
transform: { inject: composablesInjectConfig },
167+
},
168+
},
169+
}
170+
},
162171
async transform (code, id) {
172+
if (isBuild) return
163173
if (!id.startsWith(appConfig.srcDir)) return
164174

165175
const { path, query } = parseId(id)

0 commit comments

Comments
 (0)