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 => {
|
||||
return {
|
||||
presets: [
|
||||
[require('@babel/preset-env').default, {
|
||||
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 {
|
||||
presets: [
|
||||
[require('@babel/preset-env').default, presetEnvConfig],
|
||||
[require('@babel/preset-react'), {
|
||||
// This adds @babel/plugin-transform-react-jsx-source and
|
||||
// @babel/plugin-transform-react-jsx-self automatically in development
|
||||
|
@ -74,7 +75,7 @@ module.exports = (context: any, options: NextBabelPresetOptions = {}): BabelPres
|
|||
corejs: 2,
|
||||
helpers: true,
|
||||
regenerator: true,
|
||||
useESModules: !isTest,
|
||||
useESModules: !isTest && presetEnvConfig.modules !== 'commonjs',
|
||||
...options['transform-runtime']
|
||||
}],
|
||||
[require('styled-jsx/babel'), styledJsxOptions(options['styled-jsx'])],
|
||||
|
|
Loading…
Reference in a new issue