Skip to content

Commit

Permalink
Disable usage of esmodules when commonjs is enabled on the preset
Browse files Browse the repository at this point in the history
  • Loading branch information
timneutkens committed Dec 4, 2018
1 parent 29ed67b commit 2d5b56a
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/next/build/babel/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'])],
Expand Down

0 comments on commit 2d5b56a

Please sign in to comment.