1
0
Fork 0
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:
Tim Neutkens 2018-12-04 20:10:05 +01:00
parent 29ed67b020
commit 2d5b56a181

View file

@ -48,14 +48,15 @@ type 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 {
presets: [
[require('@babel/preset-env').default, {
// 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-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'])],