From fb92fdef54443b72045fe06776a96b4fa97c375c Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Wed, 28 Nov 2018 17:53:49 +0100 Subject: [PATCH] Make sure const/async is transpiled (#5760) * Make sure const/async is transpiled * Use babel common compilation instead --- packages/next/build/webpack.js | 4 ++-- .../next/build/webpack/loaders/next-babel-loader.js | 11 +++++++++++ packages/next/client/router.js | 2 +- packages/next/{lib => client}/with-router.js | 0 packages/next/package.json | 1 + 5 files changed, 15 insertions(+), 3 deletions(-) rename packages/next/{lib => client}/with-router.js (100%) diff --git a/packages/next/build/webpack.js b/packages/next/build/webpack.js index d6fffd11..0052415a 100644 --- a/packages/next/build/webpack.js +++ b/packages/next/build/webpack.js @@ -273,9 +273,9 @@ export default async function getBaseWebpackConfig (dir, {dev = false, isServer }, { test: /\.(js|jsx)$/, - include: [dir, NEXT_PROJECT_ROOT_DIST_CLIENT, DEFAULT_PAGES_DIR], + include: [dir, NEXT_PROJECT_ROOT_DIST_CLIENT, DEFAULT_PAGES_DIR, /next-server[\\/]dist[\\/]lib/], exclude: (path) => { - if (path.indexOf(NEXT_PROJECT_ROOT_DIST_CLIENT) === 0 || path.indexOf(DEFAULT_PAGES_DIR) === 0) { + if (path.indexOf(NEXT_PROJECT_ROOT_DIST_CLIENT) === 0 || path.indexOf(DEFAULT_PAGES_DIR) === 0 || /next-server[\\/]dist[\\/]lib/.exec(path)) { return false } diff --git a/packages/next/build/webpack/loaders/next-babel-loader.js b/packages/next/build/webpack/loaders/next-babel-loader.js index 6d7a0c2d..eb84cc6d 100644 --- a/packages/next/build/webpack/loaders/next-babel-loader.js +++ b/packages/next/build/webpack/loaders/next-babel-loader.js @@ -2,6 +2,7 @@ import babelLoader from 'babel-loader' module.exports = babelLoader.custom(babel => { const presetItem = babel.createConfigItem(require('../../babel/preset'), {type: 'preset'}) + const commonJsItem = babel.createConfigItem(require('@babel/plugin-transform-modules-commonjs'), {type: 'plugin'}) const configs = new Set() @@ -36,6 +37,16 @@ module.exports = babelLoader.custom(babel => { options.presets = [...options.presets, presetItem] } + options.overrides = [ + ...(options.overrides || []), + { + test: /next-server[\\/]dist[\\/]lib/, + plugins: [ + commonJsItem + ] + } + ] + return options } } diff --git a/packages/next/client/router.js b/packages/next/client/router.js index 50ee28ac..18c96ceb 100644 --- a/packages/next/client/router.js +++ b/packages/next/client/router.js @@ -73,7 +73,7 @@ function throwIfNoRouter () { export default SingletonRouter // Reexport the withRoute HOC -export { default as withRouter } from '../lib/with-router' +export { default as withRouter } from './with-router' // INTERNAL APIS // ------------- diff --git a/packages/next/lib/with-router.js b/packages/next/client/with-router.js similarity index 100% rename from packages/next/lib/with-router.js rename to packages/next/client/with-router.js diff --git a/packages/next/package.json b/packages/next/package.json index bd3faf3a..bc818e84 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -40,6 +40,7 @@ "@babel/plugin-proposal-class-properties": "7.1.0", "@babel/plugin-proposal-object-rest-spread": "7.0.0", "@babel/plugin-syntax-dynamic-import": "7.0.0", + "@babel/plugin-transform-modules-commonjs": "7.1.0", "@babel/plugin-transform-runtime": "7.1.0", "@babel/preset-env": "7.1.0", "@babel/preset-react": "7.0.0",