Skip to content

Commit

Permalink
Support webpack config that exports a function
Browse files Browse the repository at this point in the history
  • Loading branch information
pahen committed Apr 18, 2017
1 parent 21e44d4 commit 7ae4407
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ function resolveWebpackPath(partial, filename, directory, webpackConfig) {

try {
var loadedConfig = require(webpackConfig);

if (typeof loadedConfig === 'function') {
loadedConfig = loadedConfig();
}
} catch (e) {
debug('error loading the webpack config at ' + webpackConfig);
debug(e.message);
Expand Down
11 changes: 11 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,17 @@ describe('filing-cabinet', function() {
assert.equal(resolved, `${directory}/test/root2/mod2.js`);
});

it('resolves a path using webpack config that exports a function', function() {
const resolved = cabinet({
partial: 'R',
filename: `${directory}/index.js`,
directory,
webpackConfig: `${directory}/webpack-env.config.js`
});

assert.equal(resolved, `${directory}/node_modules/resolve/index.js`);
});

it('resolves files with a .jsx extension', function() {
testResolution('./test/foo.jsx', `${directory}/test/foo.jsx`);
});
Expand Down
10 changes: 10 additions & 0 deletions webpack-env.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = function() {
return {
entry: "./index.js",
resolve: {
alias: {
R: './node_modules/resolve'
}
}
};
};

0 comments on commit 7ae4407

Please sign in to comment.