Skip to content

Commit

Permalink
support array resolve.root
Browse files Browse the repository at this point in the history
  • Loading branch information
benmosher committed Dec 2, 2015
1 parent 5f8ff3e commit d3d41d0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion resolvers/webpack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ exports.resolveImport = function resolveImport(source, file, settings) {

// root as first alternate path
var rootPath = get(webpackConfig, ['resolve', 'root'])
if (rootPath) paths.push(rootPath)
if (rootPath) {
if (typeof rootPath === 'string') paths.push(rootPath)
else paths.push.apply(paths, rootPath)
}

// otherwise, resolve "normally"
return resolve.sync(source, {
Expand Down
7 changes: 7 additions & 0 deletions resolvers/webpack/test/files/webpack.array-root.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var path = require('path')
exports.resolve = {
root: [
path.join(__dirname, 'src'),
path.join(__dirname, 'bower_components'),
],
}
8 changes: 8 additions & 0 deletions resolvers/webpack/test/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ describe("root", function () {
expect(resolve('jsx/some-file', file)).to.exist
.and.equal(path.join(__dirname, 'files', 'src', 'jsx', 'some-file.js'))
})
it("supports definition as an array", function () {
expect(resolve('main-module', file, { config: "webpack.array-root.config.js" }))
.to.exist
.and.equal(path.join(__dirname, 'files', 'src', 'main-module.js'))
expect(resolve('typeahead', file, { config: "webpack.array-root.config.js" }))
.to.exist
.and.equal(path.join(__dirname, 'files', 'bower_components', 'typeahead.js'))
})
})

0 comments on commit d3d41d0

Please sign in to comment.