Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Meta
create-react-app
Commits
82066ac4
Commit
82066ac4
authored
8 years ago
by
Jimmy Miller
Committed by
Dan Abramov
8 years ago
Browse files
Options
Download
Email Patches
Plain Diff
Added ability to specify multiple directories in node_path.
parent
6e94bd84
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
config/paths.js
+19
-3
config/paths.js
config/webpack.config.dev.js
+5
-3
config/webpack.config.dev.js
config/webpack.config.prod.js
+5
-3
config/webpack.config.prod.js
with
29 additions
and
9 deletions
+29
-9
config/paths.js
+
19
-
3
View file @
82066ac4
...
@@ -11,6 +11,18 @@
...
@@ -11,6 +11,18 @@
var
path
=
require
(
'
path
'
);
var
path
=
require
(
'
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:
// 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).
var
nodePaths
=
(
process
.
env
.
NODE_PATH
||
''
)
.
split
(
process
.
platform
===
'
win32
'
?
'
;
'
:
'
:
'
)
.
filter
(
Boolean
)
.
map
(
p
=>
path
.
resolve
(
p
));
function
resolveApp
(
relativePath
)
{
function
resolveApp
(
relativePath
)
{
return
path
.
resolve
(
relativePath
);
return
path
.
resolve
(
relativePath
);
}
}
...
@@ -22,13 +34,15 @@ module.exports = {
...
@@ -22,13 +34,15 @@ module.exports = {
appPackageJson
:
resolveApp
(
'
package.json
'
),
appPackageJson
:
resolveApp
(
'
package.json
'
),
appSrc
:
resolveApp
(
'
src
'
),
appSrc
:
resolveApp
(
'
src
'
),
appNodeModules
:
resolveApp
(
'
node_modules
'
),
appNodeModules
:
resolveApp
(
'
node_modules
'
),
ownNodeModules
:
resolveApp
(
'
node_modules
'
)
ownNodeModules
:
resolveApp
(
'
node_modules
'
),
nodePaths
:
nodePaths
};
};
// @remove-on-eject-begin
// @remove-on-eject-begin
function
resolveOwn
(
relativePath
)
{
function
resolveOwn
(
relativePath
)
{
return
path
.
resolve
(
__dirname
,
relativePath
);
return
path
.
resolve
(
__dirname
,
relativePath
);
}
}
// config before eject: we're in ./node_modules/react-scripts/config/
// config before eject: we're in ./node_modules/react-scripts/config/
module
.
exports
=
{
module
.
exports
=
{
appBuild
:
resolveApp
(
'
build
'
),
appBuild
:
resolveApp
(
'
build
'
),
...
@@ -37,7 +51,8 @@ module.exports = {
...
@@ -37,7 +51,8 @@ module.exports = {
appSrc
:
resolveApp
(
'
src
'
),
appSrc
:
resolveApp
(
'
src
'
),
appNodeModules
:
resolveApp
(
'
node_modules
'
),
appNodeModules
:
resolveApp
(
'
node_modules
'
),
// this is empty with npm3 but node resolution searches higher anyway:
// this is empty with npm3 but node resolution searches higher anyway:
ownNodeModules
:
resolveOwn
(
'
../node_modules
'
)
ownNodeModules
:
resolveOwn
(
'
../node_modules
'
),
nodePaths
:
nodePaths
};
};
// @remove-on-eject-end
// @remove-on-eject-end
...
@@ -48,6 +63,7 @@ module.exports = {
...
@@ -48,6 +63,7 @@ module.exports = {
appPackageJson
:
resolveOwn
(
'
../package.json
'
),
appPackageJson
:
resolveOwn
(
'
../package.json
'
),
appSrc
:
resolveOwn
(
'
../template/src
'
),
appSrc
:
resolveOwn
(
'
../template/src
'
),
appNodeModules
:
resolveOwn
(
'
../node_modules
'
),
appNodeModules
:
resolveOwn
(
'
../node_modules
'
),
ownNodeModules
:
resolveOwn
(
'
../node_modules
'
)
ownNodeModules
:
resolveOwn
(
'
../node_modules
'
),
nodePaths
:
nodePaths
};
};
// @remove-on-publish-end
// @remove-on-publish-end
This diff is collapsed.
Click to expand it.
config/webpack.config.dev.js
+
5
-
3
View file @
82066ac4
...
@@ -67,9 +67,11 @@ module.exports = {
...
@@ -67,9 +67,11 @@ module.exports = {
publicPath
:
'
/
'
publicPath
:
'
/
'
},
},
resolve
:
{
resolve
:
{
// This allows you to set a root for where webpack should look for modules.
// This allows you to set a root for where Webpack should look for modules.
// This enables you to use absolute imports from the root.
// It must be an absolute path or an array of absolute paths.
root
:
path
.
resolve
(
process
.
env
.
NODE_PATH
||
''
),
// This lets you use absolute paths in imports inside large monorepos:
// https://github.com/facebookincubator/create-react-app/issues/253.
root
:
paths
.
nodePaths
,
// These are the reasonable defaults supported by the Node ecosystem.
// These are the reasonable defaults supported by the Node ecosystem.
extensions
:
[
'
.js
'
,
'
.json
'
,
''
],
extensions
:
[
'
.js
'
,
'
.json
'
,
''
],
alias
:
{
alias
:
{
...
...
This diff is collapsed.
Click to expand it.
config/webpack.config.prod.js
+
5
-
3
View file @
82066ac4
...
@@ -62,9 +62,11 @@ module.exports = {
...
@@ -62,9 +62,11 @@ module.exports = {
publicPath
:
publicPath
publicPath
:
publicPath
},
},
resolve
:
{
resolve
:
{
// This allows you to set a root for where webpack should look for modules.
// This allows you to set a root for where Webpack should look for modules.
// This enables you to use absolute imports from the root.
// It must be an absolute path or an array of absolute paths.
root
:
path
.
resolve
(
process
.
env
.
NODE_PATH
||
''
),
// This lets you use absolute paths in imports inside large monorepos:
// https://github.com/facebookincubator/create-react-app/issues/253.
root
:
paths
.
nodePaths
,
// These are the reasonable defaults supported by the Node ecosystem.
// These are the reasonable defaults supported by the Node ecosystem.
extensions
:
[
'
.js
'
,
'
.json
'
,
''
],
extensions
:
[
'
.js
'
,
'
.json
'
,
''
],
alias
:
{
alias
:
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets