Skip to content

Commit

Permalink
feat: allow multiple targets (#1799)
Browse files Browse the repository at this point in the history
* feat: allow multiple targets

Co-authored-by: Anshuman Verma <anshu.av97@gmail.com>
Co-authored-by: Rishabh Chawla <rishabh31121999@gmail.com>
  • Loading branch information
3 people committed Sep 17, 2020
1 parent 2473978 commit 1724ddb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
Expand Up @@ -42,8 +42,7 @@ Object {
"webpackArgs": Object {
"color": true,
"config": Array [],
"mode": "production",
"target": "node",
"mode": "development",
},
}
`;
2 changes: 1 addition & 1 deletion packages/serve/__tests__/parseArgs.test.ts
Expand Up @@ -27,7 +27,7 @@ describe('parseArgs', () => {
});

it('parses webpack and dev server args', () => {
const args = parseArgs(cli, ['--bonjour', '--target=node', '--port', '8080']);
const args = parseArgs(cli, ['--bonjour', '--mode=development', '--port', '8080']);
expect(args).toMatchSnapshot();
expect(errorMock.mock.calls.length).toEqual(0);
expect(processExitSpy.mock.calls.length).toEqual(0);
Expand Down
3 changes: 2 additions & 1 deletion packages/webpack-cli/lib/utils/cli-flags.js
Expand Up @@ -144,6 +144,7 @@ const core = [
alias: 't',
type: String,
group: ADVANCED_GROUP,
multiple: cli !== undefined,
description: 'Sets the build target e.g. node',
link: 'https://webpack.js.org/configuration/target/#target',
},
Expand Down Expand Up @@ -259,7 +260,7 @@ const core = [
// Extract all the flags being exported from core. A list of cli flags generated by core
// can be found here https://github.com/webpack/webpack/blob/master/test/__snapshots__/Cli.test.js.snap
let flagsFromCore =
typeof cli !== 'undefined'
cli !== undefined
? Object.entries(cli.getArguments()).map(([flag, meta]) => {
if (meta.simpleType === 'string') {
meta.type = String;
Expand Down
20 changes: 18 additions & 2 deletions test/target/flag-test/target-flag.test.js
Expand Up @@ -10,7 +10,11 @@ describe('--target flag', () => {
it(`should accept ${val} with --target flag`, (done) => {
const { stdout, stderr } = run(__dirname, ['--target', `${val}`]);
expect(stderr).toBeFalsy();
expect(stdout).toContain(`target: '${val}'`);
if (isWebpack5) {
expect(stdout).toContain(`target: [ '${val}' ]`);
} else {
expect(stdout).toContain(`target: '${val}'`);
}

stat(resolve(__dirname, 'bin/main.js'), (err, stats) => {
expect(err).toBe(null);
Expand All @@ -22,7 +26,11 @@ describe('--target flag', () => {
it(`should accept ${val} with -t alias`, (done) => {
const { stdout, stderr } = run(__dirname, ['-t', `${val}`]);
expect(stderr).toBeFalsy();
expect(stdout).toContain(`target: '${val}'`);
if (isWebpack5) {
expect(stdout).toContain(`target: [ '${val}' ]`);
} else {
expect(stdout).toContain(`target: '${val}'`);
}

stat(resolve(__dirname, 'bin/main.js'), (err, stats) => {
expect(err).toBe(null);
Expand All @@ -40,4 +48,12 @@ describe('--target flag', () => {
expect(stderr).toContain('Invalid configuration object');
}
});

if (isWebpack5) {
it('should allow multiple targets', () => {
const { stderr, stdout } = run(__dirname, ['--target', 'node', '--target', 'async-node']);
expect(stderr).toBeFalsy();
expect(stdout).toContain(`target: [ 'node', 'async-node' ]`);
});
}
});

0 comments on commit 1724ddb

Please sign in to comment.