Skip to content

Commit

Permalink
Tweak how NODE_PATH is handled
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Sep 2, 2016
1 parent 82066ac commit c71337f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
10 changes: 7 additions & 3 deletions config/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@

var path = require('path');

// We support resolving modules according to NODE_PATH.
// We support resolving modules according to `NODE_PATH`.
// This lets you use absolute paths in imports inside large monorepos:
// https://github.com/facebookincubator/create-react-app/issues/253.
// It works just like NODE_PATH in Node:

// It works similar to `NODE_PATH` in Node itself:
// https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders

// We will export `nodePaths` as an array of absolute paths.
// It will then be used by Webpack (and potentially other tools).
// It will then be used by Webpack configs.
// Jest doesn’t need this because it already handles `NODE_PATH` out of the box.

var nodePaths = (process.env.NODE_PATH || '')
.split(process.platform === 'win32' ? ';' : ':')
.filter(Boolean)
Expand Down
11 changes: 6 additions & 5 deletions config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ module.exports = {
publicPath: '/'
},
resolve: {
// This allows you to set a root for where Webpack should look for modules.
// It must be an absolute path or an array of absolute paths.
// This lets you use absolute paths in imports inside large monorepos:
// https://github.com/facebookincubator/create-react-app/issues/253.
root: paths.nodePaths,
// This allows you to set a fallback for where Webpack should look for modules.
// We read `NODE_PATH` environment variable in `paths.js` and pass paths here.
// We use `fallback` instead of `root` because we want `node_modules` to "win"
// if there any conflicts. This matches Node resolution mechanism.
// https://github.com/facebookincubator/create-react-app/issues/253
fallback: paths.nodePaths,
// These are the reasonable defaults supported by the Node ecosystem.
extensions: ['.js', '.json', ''],
alias: {
Expand Down
11 changes: 6 additions & 5 deletions config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ module.exports = {
publicPath: publicPath
},
resolve: {
// This allows you to set a root for where Webpack should look for modules.
// It must be an absolute path or an array of absolute paths.
// This lets you use absolute paths in imports inside large monorepos:
// https://github.com/facebookincubator/create-react-app/issues/253.
root: paths.nodePaths,
// This allows you to set a fallback for where Webpack should look for modules.
// We read `NODE_PATH` environment variable in `paths.js` and pass paths here.
// We use `fallback` instead of `root` because we want `node_modules` to "win"
// if there any conflicts. This matches Node resolution mechanism.
// https://github.com/facebookincubator/create-react-app/issues/253
fallback: paths.nodePaths,
// These are the reasonable defaults supported by the Node ecosystem.
extensions: ['.js', '.json', ''],
alias: {
Expand Down

0 comments on commit c71337f

Please sign in to comment.