Skip to content

Commit 3bc9624

Browse files
haoqunjiangaleclarson
authored andcommitted
fix(commonjs): ignoreDynamicRequires should default to false (vitejs#4015)
See vitejs#3353 (comment) Fixes vitejs#3426 Fixes vitejs#3997
1 parent 64c3207 commit 3bc9624

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

packages/vite/src/node/build.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,7 @@ export function resolveBuildPlugins(config: ResolvedConfig): {
272272
return {
273273
pre: [
274274
buildHtmlPlugin(config),
275-
commonjsPlugin({
276-
ignoreDynamicRequires: true,
277-
...options.commonjsOptions
278-
}),
275+
commonjsPlugin(options.commonjsOptions),
279276
dataURIPlugin(),
280277
dynamicImportVars(options.dynamicImportVarsOptions),
281278
assetImportMetaUrlPlugin(config),

packages/vite/types/commonjs.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ export interface RollupCommonJSOptions {
4141
* @default true
4242
*/
4343
sourceMap?: boolean
44+
/**
45+
* Some `require` calls cannot be resolved statically to be translated to
46+
* imports.
47+
* When this option is set to `false`, the generated code will either
48+
* directly throw an error when such a call is encountered or, when
49+
* `dynamicRequireTargets` is used, when such a call cannot be resolved with a
50+
* configured dynamic require target.
51+
* Setting this option to `true` will instead leave the `require` call in the
52+
* code or use it as a fallback for `dynamicRequireTargets`.
53+
* @default false
54+
*/
55+
ignoreDynamicRequires?: boolean
4456
/**
4557
* Instructs the plugin whether to enable mixed module transformations. This
4658
* is useful in scenarios with modules that contain a mix of ES `import`

0 commit comments

Comments
 (0)