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 1 commit
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
4 changes: 3 additions & 1 deletion config/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

var REACT_APP = /^REACT_APP_/i;
var NODE_ENV = JSON.stringify(process.env.NODE_ENV || 'development');
var NODE_PATH = process.env.NODE_PATH || '';

module.exports = Object
.keys(process.env)
Expand All @@ -20,5 +21,6 @@ module.exports = Object
env['process.env.' + key] = JSON.stringify(process.env[key]);
return env;
}, {
'process.env.NODE_ENV': NODE_ENV
'process.env.NODE_ENV': NODE_ENV,
'process.env.NODE_PATH': NODE_PATH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

env.js is only used for variables injected into the app.
Doesn't seem like it's useful to expose it to the path.

});
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: path.resolve(env['process.env.NODE_PATH']),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably use just process.env.NODE_PATH itself here without env, what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work for multiple paths?
From Node docs:

If the NODE_PATH environment variable is set to a colon-delimited list of absolute paths, then Node.js will search those paths for modules if they are not found elsewhere. (Note: On Windows, NODE_PATH is delimited by semicolons instead of colons.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure the exact reason for env.js, but that makes sense and I've removed it from there and just accessed it directly.

It does not currently support multiple paths. Would that be something you want me to add in this PR?

// 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: path.resolve(env['process.env.NODE_PATH']),
// These are the reasonable defaults supported by the Node ecosystem.
extensions: ['.js', '.json', ''],
alias: {
Expand Down