Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions docs/config/build-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,10 @@ This option is an alias of `build.rolldownOptions` option. Use `build.rolldownOp

## build.dynamicImportVarsOptions

- **Type:** [`RollupDynamicImportVarsOptions`](https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#options)
- **Type:** `{ include?: string | RegExp | (string | RegExp)[], exclude?: string | RegExp | (string | RegExp)[] }`
- **Related:** [Dynamic Import](/guide/features#dynamic-import)

Options to pass on to [@rollup/plugin-dynamic-import-vars](https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars).

<!-- TODO: we need to have a more detailed explanation here as we no longer use @rollup/plugin-dynamic-import-vars. we should say it's compatible with it though -->
Whether to transform dynamic imports with variables.

## build.lib

Expand Down
8 changes: 8 additions & 0 deletions docs/guide/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,14 @@ const module = await import(`./dir/${file}.js`)

Note that variables only represent file names one level deep. If `file` is `'foo/bar'`, the import would fail. For more advanced usage, you can use the [glob import](#glob-import) feature.

Also note that the dynamic import must match the following rules to be bundled:

- Imports must start with `./` or `../`: ``import(`./dir/${foo}.js`)`` is valid, but ``import(`${foo}.js`)`` is not.
- Imports must end with a file extension: ``import(`./dir/${foo}.js`)`` is valid, but ``import(`./dir/${foo}`)`` is not.
- Imports to the own directory must specify a file name pattern: ``import(`./prefix-${foo}.js`)`` is valid, but ``import(`./${foo}.js`)`` is not.

These rules are enforced to prevent accidentally importing files that are not intended to be bundled. For example, without these rules, `import(foo)` would bundle everything in the file system.

## WebAssembly

Pre-compiled `.wasm` files can be imported with `?init`.
Expand Down
1 change: 1 addition & 0 deletions docs/guide/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ The following options are deprecated and will be removed in the future:
- `build.rollupOptions`: renamed to `build.rolldownOptions`
- `worker.rollupOptions`: renamed to `worker.rolldownOptions`
- `build.commonjsOptions`: it is now no-op
- `build.dynamicImportVarsOptions.warnOnError`: it is now no-op

## General Changes [<Badge text="NRV" type="warning" />](#migration-from-v7)

Expand Down
1 change: 0 additions & 1 deletion packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,6 @@ const _buildEnvironmentOptionsDefaults = Object.freeze({
extensions: ['.js', '.cjs'],
},
dynamicImportVarsOptions: {
warnOnError: true,
exclude: [/node_modules/],
},
write: true,
Expand Down
6 changes: 1 addition & 5 deletions packages/vite/src/node/plugins/dynamicImportVars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,7 @@ export function dynamicImportVarsPlugin(config: ResolvedConfig): Plugin {
config.root,
)
} catch (error) {
if (environment.config.build.dynamicImportVarsOptions.warnOnError) {
this.warn(error)
} else {
this.error(error)
}
this.warn(error)
}

if (!result) {
Expand Down
3 changes: 1 addition & 2 deletions packages/vite/src/types/dynamicImportVars.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ export interface RollupDynamicImportVarsOptions {
*/
exclude?: string | RegExp | (string | RegExp)[]
/**
* By default, the plugin quits the build process when it encounters an error. If you set this option to true, it will throw a warning instead and leave the code untouched.
* @default false
* @deprecated This option is no-op and will be removed in future versions.
*/
warnOnError?: boolean
}