mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Disable usage of esmodules when commonjs is enabled on the preset
This commit is contained in:
parent
29ed67b020
commit
2d5b56a181
|
@ -48,14 +48,15 @@ type BabelPreset = {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = (context: any, options: NextBabelPresetOptions = {}): BabelPreset => {
|
module.exports = (context: any, options: NextBabelPresetOptions = {}): BabelPreset => {
|
||||||
|
const presetEnvConfig = {
|
||||||
|
// In the test environment `modules` is often needed to be set to true, babel figures that out by itself using the `'auto'` option
|
||||||
|
// In production/development this option is set to `false` so that webpack can handle import/export with tree-shaking
|
||||||
|
modules: isDevelopment || isProduction ? false : 'auto',
|
||||||
|
...options['preset-env']
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
presets: [
|
presets: [
|
||||||
[require('@babel/preset-env').default, {
|
[require('@babel/preset-env').default, presetEnvConfig],
|
||||||
// In the test environment `modules` is often needed to be set to true, babel figures that out by itself using the `'auto'` option
|
|
||||||
// In production/development this option is set to `false` so that webpack can handle import/export with tree-shaking
|
|
||||||
modules: isDevelopment || isProduction ? false : 'auto',
|
|
||||||
...options['preset-env']
|
|
||||||
}],
|
|
||||||
[require('@babel/preset-react'), {
|
[require('@babel/preset-react'), {
|
||||||
// This adds @babel/plugin-transform-react-jsx-source and
|
// This adds @babel/plugin-transform-react-jsx-source and
|
||||||
// @babel/plugin-transform-react-jsx-self automatically in development
|
// @babel/plugin-transform-react-jsx-self automatically in development
|
||||||
|
@ -74,7 +75,7 @@ module.exports = (context: any, options: NextBabelPresetOptions = {}): BabelPres
|
||||||
corejs: 2,
|
corejs: 2,
|
||||||
helpers: true,
|
helpers: true,
|
||||||
regenerator: true,
|
regenerator: true,
|
||||||
useESModules: !isTest,
|
useESModules: !isTest && presetEnvConfig.modules !== 'commonjs',
|
||||||
...options['transform-runtime']
|
...options['transform-runtime']
|
||||||
}],
|
}],
|
||||||
[require('styled-jsx/babel'), styledJsxOptions(options['styled-jsx'])],
|
[require('styled-jsx/babel'), styledJsxOptions(options['styled-jsx'])],
|
||||||
|
|
Loading…
Reference in a new issue