Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(commonjs): ignoreDynamicRequires should default to false #4015

Merged
merged 1 commit into from
Jun 29, 2021
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
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