Skip to content

Commit

Permalink
support webpack multiple configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
re-fort committed Jul 29, 2021
1 parent 754d388 commit 90fb286
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ function resolveWebpackPath({dependency, filename, directory, webpackConfig}) {
if (typeof loadedConfig === 'function') {
loadedConfig = loadedConfig();
}
if (Array.isArray(loadedConfig)) {
loadedConfig = loadedConfig[0];
}
} catch (e) {
debug('error loading the webpack config at ' + webpackConfig);
debug(e.message);
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ console.log(result); // /absolute/path/to/somePartialPath
* `ast`: (optional) the parsed AST for `filename`.
* Useful optimization for avoiding a parse of filename
* `config`: (optional) requirejs config for resolving aliased JavaScript modules
* `webpackConfig`: (optional) webpack config for resolving aliased JavaScript modules
* `webpackConfig`: (optional) webpack config for resolving aliased JavaScript modules. If exporting multiple configurations, the first configuration is used.
* `nodeModulesConfig`: (optional) config for resolving entry file for node_modules. This value overrides the `main` attribute in the package.json file; used in conjunction with the [packageFilter](https://github.com/browserify/resolve#resolveid-opts-cb) of the `resolve` package.
* `tsConfig`: (optional) path to a typescript configuration. Could also be an object representing a pre-parsed typescript config.
* `noTypeDefinitions`: (optional) For typescript files, whether to prefer `*.js` over `*.d.ts`.
Expand Down
11 changes: 11 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,17 @@ describe('filing-cabinet', function() {
assert.equal(resolved, expected);
});

it('resolves a path using a first configuration', function() {
const resolved = cabinet({
partial: 'mod1',
filename: `${directory}/index.js`,
directory,
webpackConfig: `${directory}/webpack-multiple.config.js`
});
var expected = path.normalize(`${directory}/test/root1/mod1.js`);
assert.equal(resolved, expected);
});

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

0 comments on commit 90fb286

Please sign in to comment.