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
Support webpack resolve.root and resolve.modulesDirectories #28
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ var resolveDependencyPath = require('resolve-dependency-path'); | |
var appModulePath = require('app-module-path'); | ||
var webpackResolve = require('enhanced-resolve'); | ||
var isRelative = require('is-relative-path'); | ||
var objectAssign = require('object-assign'); | ||
|
||
var defaultLookups = { | ||
'.js': jsLookup, | ||
|
@@ -184,7 +185,27 @@ function resolveWebpackPath(partial, filename, directory, webpackConfig) { | |
|
||
try { | ||
var loadedConfig = require(webpackConfig); | ||
var resolver = webpackResolve.create.sync(loadedConfig.resolve || {}); | ||
var resolveConfig = objectAssign({}, loadedConfig.resolve); | ||
|
||
resolveConfig.modules = []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't this blow away the existing value in |
||
|
||
if (resolveConfig.root) { | ||
resolveConfig.modules = resolveConfig.modules.concat(resolveConfig.root); | ||
} | ||
|
||
if (resolveConfig.modulesDirectories) { | ||
resolveConfig.modules = resolveConfig.modules.concat(resolveConfig.modulesDirectories); | ||
} | ||
|
||
var foundNodeModulesInPaths = resolveConfig.modules.some(function(dir) { | ||
return dir.match('node_modules'); | ||
}); | ||
|
||
if (!foundNodeModulesInPaths) { | ||
resolveConfig.modules.push('node_modules'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocker: Looking at the webpack's docs. It seems to assume that a user should know that they're responsible for supplying I'd only prefer to remove this config safety net for a few reasons:
Many of these are minor points though. I'm fine either way. |
||
} | ||
|
||
var resolver = webpackResolve.create.sync(resolveConfig); | ||
|
||
// We don't care about what the loader resolves the partial to | ||
// we only wnat the path of the resolved file | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = {}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = {}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
var path = require('path'); | ||
|
||
module.exports = { | ||
entry: "./index.js", | ||
resolve: { | ||
modulesDirectories: ['test/root1'], | ||
root: [ | ||
path.resolve(__dirname, './test/root2') | ||
] | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocker: Since filing-cabinet is in the hot code path for dependency-tree, a for-in loop might be preferable. Probably negligible, but something to keep in mind for code in precinct, cabinet, and its dependencies.