Skip to content

Commit

Permalink
feat(webpack-cli): allow multiple entry points
Browse files Browse the repository at this point in the history
Signed-off-by: Nitin Kumar <snitin315@gmail.com>

docs: a
  • Loading branch information
snitin315 committed Apr 13, 2020
1 parent e4cf0dc commit 1bfab12
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/webpack-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Available Commands
Options
--entry string The entry point of your application.
--entry string[] The entry point(s) 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
Expand Down
4 changes: 4 additions & 0 deletions packages/webpack-cli/lib/groups/BasicGroup.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const chalk = require('chalk');
const GroupHelper = require('../utils/GroupHelper');
const { core, groups } = require('../utils/cli-flags');

Expand Down Expand Up @@ -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']) {
Expand Down
3 changes: 2 additions & 1 deletion packages/webpack-cli/lib/utils/cli-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ module.exports = {
name: 'entry',
usage: '--entry <path to entry file> e.g. ./src/main.js',
type: String,
multiple: true,
defaultOption: true,
group: BASIC_GROUP,
description: 'The entry point of your application.',
description: 'The entry point(s) of your application.',
link: 'https://webpack.js.org/concepts/#entry',
},
{
Expand Down
40 changes: 38 additions & 2 deletions test/entry/flag-entry/entry-with-flag.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,45 @@ describe('entry flag', () => {
});
});

it('should allow multiple entries with --entry <file1> <file2>', (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 <file1> --entry <file2>', (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.');
});
});
1 change: 1 addition & 0 deletions test/entry/flag-entry/src/b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Hello from b.js');
2 changes: 1 addition & 1 deletion test/target/node/node-test.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1bfab12

Please sign in to comment.