From 1646f90544aa4a9340c3900c2ba0070f22bbdfe7 Mon Sep 17 00:00:00 2001 From: Cyril Auburtin Date: Tue, 29 Jan 2019 18:07:48 +0100 Subject: [PATCH] Allow to pass $dirname placeholder for absolute paths --- resolvers/webpack/README.md | 12 +++++++++++- resolvers/webpack/index.js | 6 ++++-- resolvers/webpack/test/config.js | 8 ++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/resolvers/webpack/README.md b/resolvers/webpack/README.md index 711b663f28..46bd9a7066 100644 --- a/resolvers/webpack/README.md +++ b/resolvers/webpack/README.md @@ -42,7 +42,7 @@ settings: config: 'webpack.dev.config.js' ``` -or with explicit config file name: +or with explicit config file index: ```yaml --- @@ -53,6 +53,16 @@ settings: config-index: 1 # take the config at index 1 ``` +or with explicit config file path relative to your projects's working directory: + +```yaml +--- +settings: + import/resolver: + webpack: + config: './configs/webpack.dev.config.js' +``` + or with explicit config object: ```yaml diff --git a/resolvers/webpack/index.js b/resolvers/webpack/index.js index 146213a0ca..a66c3a8eb1 100644 --- a/resolvers/webpack/index.js +++ b/resolvers/webpack/index.js @@ -44,13 +44,15 @@ exports.resolve = function (source, file, settings) { var webpackConfig - var configPath = get(settings, 'config') + var _configPath = get(settings, 'config') , configIndex = get(settings, 'config-index') , env = get(settings, 'env') , argv = get(settings, 'argv', {}) , packageDir - log('Config path from settings:', configPath) + var configPath = typeof _configPath === 'string' + ? _configPath.replace(/^\.(?=[/\\])/, path.resolve(path.join(__dirname, '..', '..'))) + : _configPath; // see if we've got a config path, a config object, an array of config objects or a config function if (!configPath || typeof configPath === 'string') { diff --git a/resolvers/webpack/test/config.js b/resolvers/webpack/test/config.js index 07c6350c56..2edaf908d0 100644 --- a/resolvers/webpack/test/config.js +++ b/resolvers/webpack/test/config.js @@ -72,6 +72,14 @@ describe("config", function () { .and.equal(path.join(__dirname, 'files', 'some', 'absolutely', 'goofy', 'path', 'foo.js')) }) + it("finds config object when config uses $PWD path placeholder", function () { + var settings = { + config: './resolvers/webpack/test/files/some/absolute.path.webpack.config.js', + } + expect(resolve('foo', file, settings)).to.have.property('path') + .and.equal(path.join(__dirname, 'files', 'some', 'absolutely', 'goofy', 'path', 'foo.js')) + }) + it("finds the first config with a resolve section when config is an array of config objects", function () { var settings = { config: require(path.join(__dirname, './files/webpack.config.multiple.js')),