Skip to content

Commit 4649189

Browse files
Timergaearon
authored andcommitted
Add module scope plugin (facebook#2189)
* Add module scope plugin * Oops * Add comments * Check windows seps too * More descriptive error * Document it
1 parent a47a655 commit 4649189

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

config/webpack.config.dev.js

+9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
1818
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
1919
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
2020
const eslintFormatter = require('react-dev-utils/eslintFormatter');
21+
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
2122
const getClientEnvironment = require('./env');
2223
const paths = require('./paths');
2324

@@ -106,6 +107,14 @@ module.exports = {
106107
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
107108
'react-native': 'react-native-web',
108109
},
110+
plugins: [
111+
// Prevents users from importing files from outside of src/ (or node_modules/).
112+
// This often causes confusion because we only process files within src/ with babel.
113+
// To fix this, we prevent you from importing files out of src/ -- if you'd like to,
114+
// please link the files into your node_modules/ and let module-resolution kick in.
115+
// Make sure your source files are compiled, as they will not be processed in any way.
116+
new ModuleScopePlugin(paths.appSrc),
117+
],
109118
},
110119
module: {
111120
strictExportPresence: true,

config/webpack.config.prod.js

+9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const ExtractTextPlugin = require('extract-text-webpack-plugin');
1818
const ManifestPlugin = require('webpack-manifest-plugin');
1919
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
2020
const eslintFormatter = require('react-dev-utils/eslintFormatter');
21+
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
2122
const paths = require('./paths');
2223
const getClientEnvironment = require('./env');
2324

@@ -103,6 +104,14 @@ module.exports = {
103104
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
104105
'react-native': 'react-native-web',
105106
},
107+
plugins: [
108+
// Prevents users from importing files from outside of src/ (or node_modules/).
109+
// This often causes confusion because we only process files within src/ with babel.
110+
// To fix this, we prevent you from importing files out of src/ -- if you'd like to,
111+
// please link the files into your node_modules/ and let module-resolution kick in.
112+
// Make sure your source files are compiled, as they will not be processed in any way.
113+
new ModuleScopePlugin(paths.appSrc),
114+
],
106115
},
107116
module: {
108117
strictExportPresence: true,

0 commit comments

Comments
 (0)