diff --git a/packages/webpack-cli/README.md b/packages/webpack-cli/README.md index 299ab326652..00b446bd43c 100644 --- a/packages/webpack-cli/README.md +++ b/packages/webpack-cli/README.md @@ -35,7 +35,7 @@ Available Commands Options - --entry string The entry point of your application. + --entry string[] The entry point of your application. -c, --config string Provide path to a webpack configuration file -m, --merge string Merge a configuration file using webpack-merge --progress Print compilation progress during build diff --git a/packages/webpack-cli/lib/groups/BasicGroup.js b/packages/webpack-cli/lib/groups/BasicGroup.js index 723ad85c455..98dacccdc69 100644 --- a/packages/webpack-cli/lib/groups/BasicGroup.js +++ b/packages/webpack-cli/lib/groups/BasicGroup.js @@ -1,3 +1,4 @@ +const chalk = require('chalk'); const GroupHelper = require('../utils/GroupHelper'); const { core, groups } = require('../utils/cli-flags'); @@ -35,6 +36,9 @@ class BasicGroup extends GroupHelper { } if (arg === 'entry') { options[arg] = this.resolveFilePath(args[arg], 'index.js'); + if (options[arg].length === 0) { + process.stdout.write(chalk.red('\nError: you provided an invalid entry point.\n')); + } } }); if (outputOptions['dev']) { diff --git a/packages/webpack-cli/lib/utils/cli-flags.js b/packages/webpack-cli/lib/utils/cli-flags.js index 56de174097d..60d7b5bf8f1 100644 --- a/packages/webpack-cli/lib/utils/cli-flags.js +++ b/packages/webpack-cli/lib/utils/cli-flags.js @@ -77,6 +77,7 @@ module.exports = { name: 'entry', usage: '--entry e.g. ./src/main.js', type: String, + multiple: true, defaultOption: true, group: BASIC_GROUP, description: 'The entry point of your application.', diff --git a/test/entry/flag-entry/entry-with-flag.test.js b/test/entry/flag-entry/entry-with-flag.test.js index 362c5cb09a5..9bf21c32753 100644 --- a/test/entry/flag-entry/entry-with-flag.test.js +++ b/test/entry/flag-entry/entry-with-flag.test.js @@ -22,9 +22,45 @@ describe('entry flag', () => { }); }); + it('should allow multiple entries with --entry ', (done) => { + const { stderr, stdout } = run(__dirname, ['--entry', './src/a.js', './src/b.js']); + expect(stderr).toBeFalsy(); + expect(stdout).toBeTruthy(); + + stat(resolve(__dirname, './bin/main.js'), (err, stats) => { + expect(err).toBe(null); + expect(stats.isFile()).toBe(true); + done(); + }); + readFile(resolve(__dirname, './bin/main.js'), 'utf-8', (err, data) => { + expect(err).toBe(null); + expect(data).toContain('Hello from a.js'); + expect(data).toContain('Hello from b.js'); + done(); + }); + }); + + it('should allow multiple entries with --entry --entry ', (done) => { + const { stderr, stdout } = run(__dirname, ['--entry', './src/a.js', '--entry', './src/b.js']); + expect(stderr).toBeFalsy(); + expect(stdout).toBeTruthy(); + + stat(resolve(__dirname, './bin/main.js'), (err, stats) => { + expect(err).toBe(null); + expect(stats.isFile()).toBe(true); + done(); + }); + readFile(resolve(__dirname, './bin/main.js'), 'utf-8', (err, data) => { + expect(err).toBe(null); + expect(data).toContain('Hello from a.js'); + expect(data).toContain('Hello from b.js'); + done(); + }); + }); + it('should throw error for invalid entry file', () => { const { stderr, stdout } = run(__dirname, ['--entry', './src/test.js']); - expect(stderr).toBeFalsy(); - expect(stdout).toContain('not found'); + expect(stderr).toBeTruthy(); + expect(stdout).toContain('Error: you provided an invalid entry point.'); }); }); diff --git a/test/entry/flag-entry/src/b.js b/test/entry/flag-entry/src/b.js new file mode 100644 index 00000000000..4eb2d45c855 --- /dev/null +++ b/test/entry/flag-entry/src/b.js @@ -0,0 +1 @@ +console.log('Hello from b.js'); diff --git a/test/target/node/node-test.test.js b/test/target/node/node-test.test.js index 1ca60cfcc10..f6719d9629e 100644 --- a/test/target/node/node-test.test.js +++ b/test/target/node/node-test.test.js @@ -5,7 +5,7 @@ const { run } = require('../../utils/test-utils'); describe('Node target', () => { it('should emit the correct code', (done) => { - const { stderr } = run(__dirname, [__dirname, '-c', './webpack.config.js']); + const { stderr } = run(__dirname, ['-c', './webpack.config.js']); expect(stderr).toBeFalsy(); stat(resolve(__dirname, 'bin/main.js'), (err, stats) => { expect(err).toBe(null);