Skip to content

Commit 6f95b26

Browse files
fix: support any config name (#1926)
1 parent 4bfde10 commit 6f95b26

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

packages/webpack-cli/lib/groups/ConfigGroup.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { existsSync } = require('fs');
2-
const { resolve, sep, dirname, extname } = require('path');
2+
const { resolve, extname } = require('path');
33
const webpackMerge = require('webpack-merge');
44
const { extensions, jsVariants } = require('interpret');
55
const rechoir = require('rechoir');
@@ -149,8 +149,9 @@ const finalize = async (moduleObj, args) => {
149149
if (!moduleObj) {
150150
return newOptionsObject;
151151
}
152-
const configPath = moduleObj.path;
152+
153153
const configOptions = moduleObj.content;
154+
154155
if (typeof configOptions === 'function') {
155156
// when config is a function, pass the env from args to the config function
156157
let formattedEnv;
@@ -187,18 +188,6 @@ const finalize = async (moduleObj, args) => {
187188
newOptionsObject['options'] = configOptions;
188189
}
189190

190-
if (configOptions && configPath.includes('.webpack')) {
191-
const currentPath = configPath;
192-
const parentContext = dirname(currentPath).split(sep).slice(0, -1).join(sep);
193-
if (Array.isArray(configOptions)) {
194-
configOptions.forEach((config) => {
195-
config.context = config.context || parentContext;
196-
});
197-
} else {
198-
configOptions.context = configOptions.context || parentContext;
199-
}
200-
newOptionsObject['options'] = configOptions;
201-
}
202191
return newOptionsObject;
203192
};
204193

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 'foo';
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const { resolve } = require('path');
2+
3+
module.exports = {
4+
entry: resolve('./a.js'),
5+
output: {
6+
path: resolve(__dirname, 'binary'),
7+
filename: 'a.bundle.js',
8+
},
9+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
const { existsSync } = require('fs');
3+
const { resolve } = require('path');
4+
const { run } = require('../../utils/test-utils');
5+
6+
describe('custom config file', () => {
7+
it('should work', () => {
8+
const { stdout, stderr, exitCode } = run(__dirname, ['--config', resolve(__dirname, 'config.webpack.js')], false);
9+
expect(stderr).toBeFalsy();
10+
expect(stdout).toBeTruthy();
11+
expect(exitCode).toBe(0);
12+
expect(existsSync(resolve(__dirname, './binary/a.bundle.js'))).toBeTruthy();
13+
});
14+
});

0 commit comments

Comments
 (0)