Skip to content

Commit

Permalink
Remove ModuleScopePlugin and add common-js alias
Browse files Browse the repository at this point in the history
  • Loading branch information
kamalbennani committed Oct 23, 2017
1 parent 9c1a6f4 commit 5bcecf0
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 60 deletions.
11 changes: 8 additions & 3 deletions packages/react-scripts/config/botifyConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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,
},
};
45 changes: 19 additions & 26 deletions packages/react-scripts/config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
42 changes: 19 additions & 23 deletions packages/react-scripts/config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions packages/react-scripts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5bcecf0

Please sign in to comment.