From ddd93e9865fe3b05ca5d8d473650c8265f3fb5c3 Mon Sep 17 00:00:00 2001 From: Naoyuki Kanezawa Date: Sat, 4 Feb 2017 05:18:44 +0900 Subject: [PATCH] Improve babel settings (#976) * fix babelrc settings * use only transform-es2015-modules-commonjs for transpiling emitting files --- package.json | 1 + server/build/webpack.js | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 64d4b6a6..8d10b4d6 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "babel-plugin-react-require": "^3.0.0", "babel-plugin-transform-async-to-generator": "6.22.0", "babel-plugin-transform-class-properties": "6.22.0", + "babel-plugin-transform-es2015-modules-commonjs": "6.22.0", "babel-plugin-transform-object-rest-spread": "6.22.0", "babel-plugin-transform-runtime": "6.22.0", "babel-preset-es2015": "6.22.0", diff --git a/server/build/webpack.js b/server/build/webpack.js index 044db528..eb8c9297 100644 --- a/server/build/webpack.js +++ b/server/build/webpack.js @@ -109,7 +109,6 @@ export default async function createCompiler (dir, { dev = false, quiet = false .filter((p) => !!p) const mainBabelOptions = { - babelrc: true, cacheDirectory: true, sourceMaps: dev ? 'both' : false, presets: [] @@ -119,8 +118,10 @@ export default async function createCompiler (dir, { dev = false, quiet = false if (configLocation) { console.log(`> Using external babel configuration`) console.log(`> location: "${configLocation}"`) + mainBabelOptions.babelrc = true } else { mainBabelOptions.presets.push(require.resolve('./babel/preset')) + mainBabelOptions.babelrc = false } const rules = (dev ? [{ @@ -158,7 +159,7 @@ export default async function createCompiler (dir, { dev = false, quiet = false const babelRuntimePath = require.resolve('babel-runtime/package') .replace(/[\\/]package\.json$/, '') const transpiled = babelCore.transform(content, { - presets: [require.resolve('babel-preset-es2015')], + babelrc: false, sourceMaps: dev ? 'both' : false, // Here we need to resolve all modules to the absolute paths. // Earlier we did it with the babel-preset. @@ -166,6 +167,7 @@ export default async function createCompiler (dir, { dev = false, quiet = false // That's why we need to do it here. // See more: https://github.com/zeit/next.js/issues/951 plugins: [ + [require.resolve('babel-plugin-transform-es2015-modules-commonjs')], [ require.resolve('babel-plugin-module-resolver'), {