From 5bcecf01cc3ece26a412429d8a1865462051c0de Mon Sep 17 00:00:00 2001 From: Kamal Bennani Date: Mon, 23 Oct 2017 12:25:09 +0200 Subject: [PATCH] Remove ModuleScopePlugin and add common-js alias --- packages/react-scripts/config/botifyConfig.js | 11 +++-- .../config/webpack.config.dev.js | 45 ++++++++----------- .../config/webpack.config.prod.js | 42 ++++++++--------- packages/react-scripts/package-lock.json | 16 +++---- 4 files changed, 54 insertions(+), 60 deletions(-) diff --git a/packages/react-scripts/config/botifyConfig.js b/packages/react-scripts/config/botifyConfig.js index ce65c1d7a83..92aad719b62 100644 --- a/packages/react-scripts/config/botifyConfig.js +++ b/packages/react-scripts/config/botifyConfig.js @@ -4,6 +4,10 @@ const path = require('path'); const fs = require('fs'); const autoprefixer = require('autoprefixer'); const ExtractTextPlugin = require('extract-text-webpack-plugin'); +const commonJs = path.resolve( + fs.realpathSync(process.cwd()), + '../common-js/src' +); const getSCSSLoaderConfig = isDev => { const loaders = [ @@ -56,7 +60,8 @@ const getSCSSLoaderConfig = isDev => { module.exports = { babelPlugins: [require.resolve('babel-plugin-transform-decorators-legacy')], webpackLoaders: [getSCSSLoaderConfig(process.env.NODE_ENV !== 'production')], - allowedExternalImports: [ - path.resolve(fs.realpathSync(process.cwd()), '../../config/config.js'), - ], + allowedSrc: [commonJs], // These are folders that needs to be processed with Babel + alias: { + 'common-js': commonJs, + }, }; diff --git a/packages/react-scripts/config/webpack.config.dev.js b/packages/react-scripts/config/webpack.config.dev.js index 0c005e89bd9..855b2d9c826 100644 --- a/packages/react-scripts/config/webpack.config.dev.js +++ b/packages/react-scripts/config/webpack.config.dev.js @@ -96,31 +96,24 @@ module.exports = { // `web` extension prefixes have been added for better support // for React Native Web. extensions: ['.web.js', '.js', '.json', '.web.jsx', '.jsx'], - alias: { - // @remove-on-eject-begin - // Resolve Babel runtime relative to react-scripts. - // It usually still works on npm 3 without this but it would be - // unfortunate to rely on, as react-scripts could be symlinked, - // and thus babel-runtime might not be resolvable from the source. - 'babel-runtime': path.dirname( - require.resolve('babel-runtime/package.json') - ), - // @remove-on-eject-end - // Support React Native Web - // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/ - 'react-native': 'react-native-web', - }, - plugins: [ - // Prevents users from importing files from outside of src/ (or node_modules/). - // This often causes confusion because we only process files within src/ with babel. - // To fix this, we prevent you from importing files out of src/ -- if you'd like to, - // please link the files into your node_modules/ and let module-resolution kick in. - // Make sure your source files are compiled, as they will not be processed in any way. - new ModuleScopePlugin(paths.appSrc, [ - paths.appPackageJson, - ...botifyConfig.allowedExternalImports, - ]), - ], + alias: Object.assign( + {}, + { + // @remove-on-eject-begin + // Resolve Babel runtime relative to react-scripts. + // It usually still works on npm 3 without this but it would be + // unfortunate to rely on, as react-scripts could be symlinked, + // and thus babel-runtime might not be resolvable from the source. + 'babel-runtime': path.dirname( + require.resolve('babel-runtime/package.json') + ), + // @remove-on-eject-end + // Support React Native Web + // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/ + 'react-native': 'react-native-web', + }, + botifyConfig.alias + ), }, module: { strictExportPresence: true, @@ -171,7 +164,7 @@ module.exports = { // Process JS with Babel. { test: /\.(js|jsx)$/, - include: paths.appSrc, + include: [paths.appSrc, ...botifyConfig.allowedSrc], loader: require.resolve('babel-loader'), options: { // @remove-on-eject-begin diff --git a/packages/react-scripts/config/webpack.config.prod.js b/packages/react-scripts/config/webpack.config.prod.js index b5bcf9433a0..9cde155a99b 100644 --- a/packages/react-scripts/config/webpack.config.prod.js +++ b/packages/react-scripts/config/webpack.config.prod.js @@ -100,28 +100,24 @@ module.exports = { // `web` extension prefixes have been added for better support // for React Native Web. extensions: ['.web.js', '.js', '.json', '.web.jsx', '.jsx'], - alias: { - // @remove-on-eject-begin - // Resolve Babel runtime relative to react-scripts. - // It usually still works on npm 3 without this but it would be - // unfortunate to rely on, as react-scripts could be symlinked, - // and thus babel-runtime might not be resolvable from the source. - 'babel-runtime': path.dirname( - require.resolve('babel-runtime/package.json') - ), - // @remove-on-eject-end - // Support React Native Web - // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/ - 'react-native': 'react-native-web', - }, - plugins: [ - // Prevents users from importing files from outside of src/ (or node_modules/). - // This often causes confusion because we only process files within src/ with babel. - // To fix this, we prevent you from importing files out of src/ -- if you'd like to, - // please link the files into your node_modules/ and let module-resolution kick in. - // Make sure your source files are compiled, as they will not be processed in any way. - new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]), - ], + alias: Object.assing( + {}, + { + // @remove-on-eject-begin + // Resolve Babel runtime relative to react-scripts. + // It usually still works on npm 3 without this but it would be + // unfortunate to rely on, as react-scripts could be symlinked, + // and thus babel-runtime might not be resolvable from the source. + 'babel-runtime': path.dirname( + require.resolve('babel-runtime/package.json') + ), + // @remove-on-eject-end + // Support React Native Web + // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/ + 'react-native': 'react-native-web', + }, + botifyConfig.alias + ), }, module: { strictExportPresence: true, @@ -173,7 +169,7 @@ module.exports = { // Process JS with Babel. { test: /\.(js|jsx)$/, - include: paths.appSrc, + include: [paths.appSrc, ...botifyConfig.allowedSrc], loader: require.resolve('babel-loader'), options: { // @remove-on-eject-begin diff --git a/packages/react-scripts/package-lock.json b/packages/react-scripts/package-lock.json index 25a3d7e3857..b5c8887cfa2 100644 --- a/packages/react-scripts/package-lock.json +++ b/packages/react-scripts/package-lock.json @@ -8292,14 +8292,6 @@ "resolved": "https://registry.npmjs.org/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz", "integrity": "sha1-J5siXfHVgrH1TmWt3UNS4Y+qBxM=" }, - "string_decoder": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", - "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", - "requires": { - "safe-buffer": "5.1.1" - } - }, "string-length": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/string-length/-/string-length-1.0.1.tgz", @@ -8332,6 +8324,14 @@ } } }, + "string_decoder": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", + "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", + "requires": { + "safe-buffer": "5.1.1" + } + }, "stringstream": { "version": "0.0.5", "resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz",