Skip to content

Commit 3f07670

Browse files
authored
feat: update rolldown and support custom configs for native dynamic import vars plugin (#310)
1 parent a657265 commit 3f07670

File tree

4 files changed

+184
-18
lines changed

4 files changed

+184
-18
lines changed

packages/vite/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
"lightningcss": "^1.30.1",
8787
"picomatch": "^4.0.2",
8888
"postcss": "^8.5.6",
89-
"rolldown": "1.0.0-beta.23",
89+
"rolldown": "1.0.0-beta.24",
9090
"tinyglobby": "^0.2.14"
9191
},
9292
"optionalDependencies": {
@@ -99,7 +99,7 @@
9999
"@oxc-project/runtime": "^0.75.0",
100100
"@oxc-project/types": "^0.75.0",
101101
"@polka/compression": "^1.0.0-next.25",
102-
"@rolldown/pluginutils": "1.0.0-beta.23",
102+
"@rolldown/pluginutils": "1.0.0-beta.24",
103103
"@rollup/plugin-alias": "^5.1.1",
104104
"@rollup/plugin-commonjs": "^28.0.6",
105105
"@rollup/plugin-dynamic-import-vars": "2.1.4",

packages/vite/src/node/plugins/dynamicImportVars.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { parseAst } from 'rolldown/parseAst'
66
import { dynamicImportToGlob } from '@rollup/plugin-dynamic-import-vars'
77
import { dynamicImportVarsPlugin as nativeDynamicImportVarsPlugin } from 'rolldown/experimental'
88
import { exactRegex } from '@rolldown/pluginutils'
9-
import type { Plugin } from '../plugin'
9+
import { type Plugin, perEnvironmentPlugin } from '../plugin'
1010
import type { ResolvedConfig } from '../config'
1111
import { CLIENT_ENTRY } from '../constants'
1212
import { createBackCompatIdResolver } from '../idResolver'
@@ -167,19 +167,30 @@ export async function transformDynamicImport(
167167
}
168168

169169
export function dynamicImportVarsPlugin(config: ResolvedConfig): Plugin {
170-
if (
171-
config.experimental.enableNativePlugin === true &&
172-
config.command === 'build'
173-
) {
174-
return nativeDynamicImportVarsPlugin()
175-
}
176-
177170
const resolve = createBackCompatIdResolver(config, {
178171
preferRelative: true,
179172
tryIndex: false,
180173
extensions: [],
181174
})
182175

176+
if (
177+
config.experimental.enableNativePlugin === true &&
178+
config.command === 'build'
179+
) {
180+
return perEnvironmentPlugin('native:dynamic-import-vars', (environment) => {
181+
const { include, exclude } =
182+
environment.config.build.dynamicImportVarsOptions
183+
184+
return nativeDynamicImportVarsPlugin({
185+
include,
186+
exclude,
187+
resolver(id, importer) {
188+
return resolve(environment, id, importer)
189+
},
190+
})
191+
})
192+
}
193+
183194
const getFilter = perEnvironmentState((environment: Environment) => {
184195
const { include, exclude } =
185196
environment.config.build.dynamicImportVarsOptions

playground/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
"convert-source-map": "^2.0.0",
1111
"css-color-names": "^1.0.1",
1212
"kill-port": "^1.6.1",
13-
"rolldown": "1.0.0-beta.23"
13+
"rolldown": "1.0.0-beta.24"
1414
}
1515
}

0 commit comments

Comments
 (0)