Skip to content

Commit fef718c

Browse files
caubljharb
authored andcommitted
[resolvers/webpack] [Breaking] Allow to resolve config path relative to working directory
Co-Authored-By: caub <[email protected]>
1 parent bbe529a commit fef718c

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

resolvers/webpack/README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ settings:
4242
config: 'webpack.dev.config.js'
4343
```
4444
45-
or with explicit config file name:
45+
or with explicit config file index:
4646
4747
```yaml
4848
---
@@ -53,6 +53,16 @@ settings:
5353
config-index: 1 # take the config at index 1
5454
```
5555
56+
or with explicit config file path relative to your projects's working directory:
57+
58+
```yaml
59+
---
60+
settings:
61+
import/resolver:
62+
webpack:
63+
config: './configs/webpack.dev.config.js'
64+
```
65+
5666
or with explicit config object:
5767
5868
```yaml

resolvers/webpack/index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ exports.resolve = function (source, file, settings) {
4848

4949
var webpackConfig
5050

51-
var configPath = get(settings, 'config')
51+
var _configPath = get(settings, 'config')
5252
/**
5353
* Attempt to set the current working directory.
5454
* If none is passed, default to the `cwd` where the config is located.
@@ -59,6 +59,10 @@ exports.resolve = function (source, file, settings) {
5959
, argv = get(settings, 'argv', {})
6060
, packageDir
6161

62+
var configPath = typeof _configPath === 'string' && _configPath.startsWith('.')
63+
? path.resolve(_configPath)
64+
: _configPath
65+
6266
log('Config path from settings:', configPath)
6367

6468
// see if we've got a config path, a config object, an array of config objects or a config function

resolvers/webpack/test/config.js

+8
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ describe("config", function () {
7272
.and.equal(path.join(__dirname, 'files', 'some', 'absolutely', 'goofy', 'path', 'foo.js'))
7373
})
7474

75+
it("finds config object when config uses a path relative to working dir", function () {
76+
var settings = {
77+
config: './test/files/some/absolute.path.webpack.config.js',
78+
}
79+
expect(resolve('foo', file, settings)).to.have.property('path')
80+
.and.equal(path.join(__dirname, 'files', 'some', 'absolutely', 'goofy', 'path', 'foo.js'))
81+
})
82+
7583
it("finds the first config with a resolve section when config is an array of config objects", function () {
7684
var settings = {
7785
config: require(path.join(__dirname, './files/webpack.config.multiple.js')),

0 commit comments

Comments
 (0)