Skip to content

Commit

Permalink
fix(commonjs): ignoreDynamicRequires should default to false (vit…
Browse files Browse the repository at this point in the history
  • Loading branch information
sodatea authored and aleclarson committed Nov 8, 2021
1 parent 64c3207 commit 3bc9624
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 1 addition & 4 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,7 @@ export function resolveBuildPlugins(config: ResolvedConfig): {
return {
pre: [
buildHtmlPlugin(config),
commonjsPlugin({
ignoreDynamicRequires: true,
...options.commonjsOptions
}),
commonjsPlugin(options.commonjsOptions),
dataURIPlugin(),
dynamicImportVars(options.dynamicImportVarsOptions),
assetImportMetaUrlPlugin(config),
Expand Down
12 changes: 12 additions & 0 deletions packages/vite/types/commonjs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ export interface RollupCommonJSOptions {
* @default true
*/
sourceMap?: boolean
/**
* Some `require` calls cannot be resolved statically to be translated to
* imports.
* When this option is set to `false`, the generated code will either
* directly throw an error when such a call is encountered or, when
* `dynamicRequireTargets` is used, when such a call cannot be resolved with a
* configured dynamic require target.
* Setting this option to `true` will instead leave the `require` call in the
* code or use it as a fallback for `dynamicRequireTargets`.
* @default false
*/
ignoreDynamicRequires?: boolean
/**
* Instructs the plugin whether to enable mixed module transformations. This
* is useful in scenarios with modules that contain a mix of ES `import`
Expand Down

0 comments on commit 3bc9624

Please sign in to comment.