Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support any config name #1926

Merged
merged 3 commits into from Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
});
});