Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made webpack respect NODE_PATH environment variable #476

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions config/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// and use those instead. This way we don't need to branch here.

var path = require('path');
var os = require('os');

// True after ejecting, false when used as a dependency
var isEjected = (
Expand All @@ -31,6 +32,16 @@ function resolveApp(relativePath) {
return path.resolve(relativePath);
}

function resolveNodePath(paths) {
if (paths === '') {
return []
}
var separator = os.platform() === 'win32' ? ';' : ':';
return paths.split(separator).map(p => path.resolve(p));
}

var nodePath = resolveNodePath(process.env.NODE_PATH || '');

if (isInCreateReactAppSource) {
// create-react-app development: we're in ./config/
module.exports = {
Expand All @@ -39,7 +50,8 @@ if (isInCreateReactAppSource) {
appPackageJson: resolveOwn('../package.json'),
appSrc: resolveOwn('../template/src'),
appNodeModules: resolveOwn('../node_modules'),
ownNodeModules: resolveOwn('../node_modules')
ownNodeModules: resolveOwn('../node_modules'),
nodePath: nodePath
};
} else if (!isEjected) {
// before eject: we're in ./node_modules/react-scripts/config/
Expand All @@ -50,7 +62,8 @@ if (isInCreateReactAppSource) {
appSrc: resolveApp('src'),
appNodeModules: resolveApp('node_modules'),
// this is empty with npm3 but node resolution searches higher anyway:
ownNodeModules: resolveOwn('../node_modules')
ownNodeModules: resolveOwn('../node_modules'),
nodePath: nodePath
};
} else {
// after eject: we're in ./config/
Expand All @@ -60,6 +73,7 @@ if (isInCreateReactAppSource) {
appPackageJson: resolveApp('package.json'),
appSrc: resolveApp('src'),
appNodeModules: resolveApp('node_modules'),
ownNodeModules: resolveApp('node_modules')
ownNodeModules: resolveApp('node_modules'),
nodePath: nodePath
};
}
3 changes: 3 additions & 0 deletions config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ module.exports = {
publicPath: '/'
},
resolve: {
// This allows you to set a root for where webpack should look for modules.
// This enables you to use absolute imports from the root.
root: paths.nodePath,
// These are the reasonable defaults supported by the Node ecosystem.
extensions: ['.js', '.json', ''],
alias: {
Expand Down
3 changes: 3 additions & 0 deletions config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ module.exports = {
publicPath: publicPath
},
resolve: {
// This allows you to set a root for where webpack should look for modules.
// This enables you to use absolute imports from the root.
root: paths.nodePath,
// These are the reasonable defaults supported by the Node ecosystem.
extensions: ['.js', '.json', ''],
alias: {
Expand Down