Skip to content

Commit

Permalink
fix: support any config name (#1926)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Oct 12, 2020
1 parent 4bfde10 commit 6f95b26
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
17 changes: 3 additions & 14 deletions packages/webpack-cli/lib/groups/ConfigGroup.js
@@ -1,5 +1,5 @@
const { existsSync } = require('fs');
const { resolve, sep, dirname, extname } = require('path');
const { resolve, extname } = require('path');
const webpackMerge = require('webpack-merge');
const { extensions, jsVariants } = require('interpret');
const rechoir = require('rechoir');
Expand Down Expand Up @@ -149,8 +149,9 @@ const finalize = async (moduleObj, args) => {
if (!moduleObj) {
return newOptionsObject;
}
const configPath = moduleObj.path;

const configOptions = moduleObj.content;

if (typeof configOptions === 'function') {
// when config is a function, pass the env from args to the config function
let formattedEnv;
Expand Down Expand Up @@ -187,18 +188,6 @@ const finalize = async (moduleObj, args) => {
newOptionsObject['options'] = configOptions;
}

if (configOptions && configPath.includes('.webpack')) {
const currentPath = configPath;
const parentContext = dirname(currentPath).split(sep).slice(0, -1).join(sep);
if (Array.isArray(configOptions)) {
configOptions.forEach((config) => {
config.context = config.context || parentContext;
});
} else {
configOptions.context = configOptions.context || parentContext;
}
newOptionsObject['options'] = configOptions;
}
return newOptionsObject;
};

Expand Down
1 change: 1 addition & 0 deletions test/config-lookup/custom-name/a.js
@@ -0,0 +1 @@
module.exports = 'foo';
9 changes: 9 additions & 0 deletions test/config-lookup/custom-name/config.webpack.js
@@ -0,0 +1,9 @@
const { resolve } = require('path');

module.exports = {
entry: resolve('./a.js'),
output: {
path: resolve(__dirname, 'binary'),
filename: 'a.bundle.js',
},
};
14 changes: 14 additions & 0 deletions test/config-lookup/custom-name/custom-name.test.js
@@ -0,0 +1,14 @@
'use strict';
const { existsSync } = require('fs');
const { resolve } = require('path');
const { run } = require('../../utils/test-utils');

describe('custom config file', () => {
it('should work', () => {
const { stdout, stderr, exitCode } = run(__dirname, ['--config', resolve(__dirname, 'config.webpack.js')], false);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
expect(exitCode).toBe(0);
expect(existsSync(resolve(__dirname, './binary/a.bundle.js'))).toBeTruthy();
});
});

0 comments on commit 6f95b26

Please sign in to comment.