Skip to content

Commit

Permalink
Fix hierarchy of directories to look for loaders and modules (#435)
Browse files Browse the repository at this point in the history
This fixes two longstanding problems.

First that starters had to ship with modules/utilities that Gatsby
already included and second that installing a starter with NPM 2 often
has problems.

I did some more research into this and realized the problem is that we
don't tell Gatsby to look in `/node_modules/gatsby/node_modules` to look
for modules and loaders. This means the starter also has to install them
(especially with NPM 2 which doesn't put dependencies of dependencies at
top-level of node_modules like NPM 3 does).

By telling Webpack to look in Gatsby's node_modules directory as well we
should be able to elimintate extra dependencies from starters as well as
fix intermittent NPM 2 problems.
  • Loading branch information
KyleAMathews authored Sep 9, 2016
1 parent 98df2fe commit a8e152a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions lib/utils/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,18 @@ module.exports = (program, directory, suppliedStage, webpackPort = 1500, routes
'.toml',
'.yaml',
],
// Hierarchy of directories for Webpack to look for module.
// First is the site directory.
// Then in the special directory of isomorphic modules Gatsby ships with.
// Then the site's node_modules directory
// and last the Gatsby node_modules directory.
root: [
directory,
path.resolve(__dirname, '..', 'isomorphic'),
],
modulesDirectories: [
`${directory}/node_modules`,
`${directory}/node_modules/gatsby/node_modules`,
'node_modules',
],
}
Expand Down Expand Up @@ -430,12 +436,16 @@ module.exports = (program, directory, suppliedStage, webpackPort = 1500, routes
devtool: devtool(),
output: output(),
resolveLoader: {
// Hierarchy of directories for Webpack to look for loaders.
// First is the /loaders/ directory in the site.
// Then in the special directory of loaders Gatsby ships with.
// Then the site's node_modules directory
// and last the Gatsby node_modules directory.
root: [
path.resolve(directory, 'loaders'),
path.resolve(__dirname, '..', 'loaders'),
],
modulesDirectories: [
'node_modules',
path.resolve(directory, 'node_modules'),
path.resolve(directory, 'node_modules/gatsby/node_modules'),
],
},
plugins: plugins(),
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"highlight.js": "^9.6.0",
"history": "^2.1.2",
"html-frontmatter": "^1.6.0",
"image-webpack-loader": "^2.0.0",
"invariant": "^2.2.1",
"json-loader": "^0.5.2",
"json5": "^0.5.0",
Expand Down Expand Up @@ -79,7 +80,6 @@
"toml": "^2.2.2",
"toml-loader": "^1.0.0",
"tracer": "^0.8.3",
"typography": "^0.13.0",
"url-loader": "^0.5.7",
"webpack": "^1.13.2",
"webpack-configurator": "^0.3.0",
Expand Down

0 comments on commit a8e152a

Please sign in to comment.