Skip to content

Commit a8e152a

Browse files
authored
Fix hierarchy of directories to look for loaders and modules (#435)
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.
1 parent 98df2fe commit a8e152a

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

lib/utils/webpack.config.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,18 @@ module.exports = (program, directory, suppliedStage, webpackPort = 1500, routes
162162
'.toml',
163163
'.yaml',
164164
],
165+
// Hierarchy of directories for Webpack to look for module.
166+
// First is the site directory.
167+
// Then in the special directory of isomorphic modules Gatsby ships with.
168+
// Then the site's node_modules directory
169+
// and last the Gatsby node_modules directory.
165170
root: [
166171
directory,
167172
path.resolve(__dirname, '..', 'isomorphic'),
168173
],
169174
modulesDirectories: [
170175
`${directory}/node_modules`,
176+
`${directory}/node_modules/gatsby/node_modules`,
171177
'node_modules',
172178
],
173179
}
@@ -430,12 +436,16 @@ module.exports = (program, directory, suppliedStage, webpackPort = 1500, routes
430436
devtool: devtool(),
431437
output: output(),
432438
resolveLoader: {
439+
// Hierarchy of directories for Webpack to look for loaders.
440+
// First is the /loaders/ directory in the site.
441+
// Then in the special directory of loaders Gatsby ships with.
442+
// Then the site's node_modules directory
443+
// and last the Gatsby node_modules directory.
433444
root: [
434445
path.resolve(directory, 'loaders'),
435446
path.resolve(__dirname, '..', 'loaders'),
436-
],
437-
modulesDirectories: [
438-
'node_modules',
447+
path.resolve(directory, 'node_modules'),
448+
path.resolve(directory, 'node_modules/gatsby/node_modules'),
439449
],
440450
},
441451
plugins: plugins(),

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"highlight.js": "^9.6.0",
4444
"history": "^2.1.2",
4545
"html-frontmatter": "^1.6.0",
46+
"image-webpack-loader": "^2.0.0",
4647
"invariant": "^2.2.1",
4748
"json-loader": "^0.5.2",
4849
"json5": "^0.5.0",
@@ -79,7 +80,6 @@
7980
"toml": "^2.2.2",
8081
"toml-loader": "^1.0.0",
8182
"tracer": "^0.8.3",
82-
"typography": "^0.13.0",
8383
"url-loader": "^0.5.7",
8484
"webpack": "^1.13.2",
8585
"webpack-configurator": "^0.3.0",

0 commit comments

Comments
 (0)