Skip to content

Commit 6b31614

Browse files
feat: entries syntax (#2369)
1 parent 153d449 commit 6b31614

33 files changed

+991
-692
lines changed

OPTIONS.md

+17-23
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
```
2-
Usage: webpack [options]
3-
Alternative usage: webpack --config <config> [options]
4-
Alternative usage: webpack build [options]
5-
Alternative usage: webpack bundle [options]
6-
Alternative usage: webpack b [options]
7-
Alternative usage: webpack build --config <config> [options]
8-
Alternative usage: webpack bundle --config <config> [options]
9-
Alternative usage: webpack b --config <config> [options]
2+
Usage: webpack [entries...] [options]
3+
Alternative usage to run commands: webpack [command] [options]
104
115
The build tool for modern web applications.
126
@@ -793,23 +787,23 @@ Options:
793787
--no-watch-options-stdin Do not stop watching when stdin stream has ended.
794788
795789
Global options:
796-
--color Enable colors on console.
797-
--no-color Disable colors on console.
798-
-v, --version Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and commands.
799-
-h, --help [verbose] Display help for commands and options.
790+
--color Enable colors on console.
791+
--no-color Disable colors on console.
792+
-v, --version Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and commands.
793+
-h, --help [verbose] Display help for commands and options.
800794
801795
Commands:
802-
build|bundle|b [options] Run webpack (default command, can be omitted).
803-
watch|w [options] Run webpack and watch for files changes.
804-
version|v [commands...] Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and commands.
805-
help|h [command] [option] Display help for commands and options.
806-
serve|s [options] Run the webpack dev server.
807-
info|i [options] Outputs information about your system.
808-
init|c [options] [scaffold...] Initialize a new webpack configuration.
809-
loader|l [output-path] Scaffold a loader.
810-
migrate|m <config-path> [new-config-path] Migrate a configuration to a new version.
811-
configtest|t [config-path] Tests webpack configuration against validation errors.
812-
plugin|p [output-path] Scaffold a plugin.
796+
build|bundle|b [entries...] [options] Run webpack (default command, can be omitted).
797+
configtest|t [config-path] Tests webpack configuration against validation errors.
798+
help|h [command] [option] Display help for commands and options.
799+
info|i [options] Outputs information about your system.
800+
init|c [scaffold...] [options] Initialize a new webpack configuration.
801+
loader|l [output-path] Scaffold a loader.
802+
migrate|m <config-path> [new-config-path] Migrate a configuration to a new version.
803+
plugin|p [output-path] Scaffold a plugin.
804+
serve|s [entries...] [options] Run the webpack dev server.
805+
version|v [commands...] Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and commands.
806+
watch|w [entries...] [options] Run webpack and watch for files changes.
813807
814808
To see list of all supported commands and options run 'webpack --help=verbose'.
815809

packages/serve/src/index.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ class ServeCommand {
66

77
await cli.makeCommand(
88
{
9-
name: 'serve',
9+
name: 'serve [entries...]',
1010
alias: 's',
1111
description: 'Run the webpack dev server.',
12-
usage: '[options]',
12+
usage: '[entries...] [options]',
1313
pkg: '@webpack-cli/serve',
1414
dependencies: ['webpack-dev-server'],
1515
},
@@ -28,7 +28,7 @@ class ServeCommand {
2828

2929
return [...builtInOptions, ...devServerFlags];
3030
},
31-
async (options) => {
31+
async (entries, options) => {
3232
const builtInOptions = cli.getBuiltInOptions();
3333
let devServerFlags = [];
3434

@@ -72,6 +72,10 @@ class ServeCommand {
7272
processor(devServerOptions);
7373
}
7474

75+
if (entries.length > 0) {
76+
webpackOptions.entry = [...entries, ...(webpackOptions.entry || [])];
77+
}
78+
7579
webpackOptions.argv = { ...options, env: { WEBPACK_SERVE: true, ...options.env } };
7680

7781
const compiler = await cli.createCompiler(webpackOptions);

packages/webpack-cli/__tests__/resolveArgs.test.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@ const { resolve } = require('path');
22
const webpackCLI = require('../lib/webpack-cli');
33

44
const targetValues = ['web', 'webworker', 'node', 'async-node', 'node-webkit', 'electron-main', 'electron-renderer', 'electron-preload'];
5-
const applyOptions = new webpackCLI().applyOptions;
5+
const cli = new webpackCLI();
66

77
describe('BasicResolver', () => {
88
it('should handle the output option', async () => {
9-
const result = await applyOptions({ options: {} }, { outputPath: './bundle' });
9+
const result = await cli.applyOptions({ options: {} }, { outputPath: './bundle' });
1010

1111
expect(result.options.output.path).toEqual(resolve('bundle'));
1212
});
1313

1414
it('should handle the mode option [production]', async () => {
15-
const result = await applyOptions({ options: {} }, { mode: 'production' });
15+
const result = await cli.applyOptions({ options: {} }, { mode: 'production' });
1616

1717
expect(result.options).toMatchObject({ mode: 'production' });
1818
expect(result.options.mode).toEqual('production');
1919
});
2020

2121
it('should handle the mode option [development]', async () => {
22-
const result = await applyOptions(
22+
const result = await cli.applyOptions(
2323
{ options: {} },
2424
{
2525
mode: 'development',
@@ -31,7 +31,7 @@ describe('BasicResolver', () => {
3131
});
3232

3333
it('should handle the mode option [none]', async () => {
34-
const result = await applyOptions(
34+
const result = await cli.applyOptions(
3535
{ options: {} },
3636
{
3737
mode: 'none',
@@ -44,34 +44,34 @@ describe('BasicResolver', () => {
4444

4545
it('should prefer supplied move flag over NODE_ENV', async () => {
4646
process.env.NODE_ENV = 'production';
47-
const result = await applyOptions({ options: {} }, { mode: 'development' });
47+
const result = await cli.applyOptions({ options: {} }, { mode: 'development' });
4848

4949
expect(result.options).toMatchObject({ mode: 'development' });
5050
});
5151

5252
it('should prefer supplied move flag over mode from config', async () => {
53-
const result = await applyOptions({ options: { mode: 'development' } }, { mode: 'production' });
53+
const result = await cli.applyOptions({ options: { mode: 'development' } }, { mode: 'production' });
5454

5555
expect(result.options).toMatchObject({ mode: 'production' });
5656
});
5757

5858
it('should prefer mode form config over NODE_ENV', async () => {
5959
process.env.NODE_ENV = 'development';
60-
const result = await applyOptions({ options: {} }, { mode: 'production' });
60+
const result = await cli.applyOptions({ options: {} }, { mode: 'production' });
6161

6262
expect(result.options).toMatchObject({ mode: 'production' });
6363
});
6464

6565
it('should prefer mode form flag over NODE_ENV and config', async () => {
6666
process.env.NODE_ENV = 'development';
67-
const result = await applyOptions({ options: {} }, {});
67+
const result = await cli.applyOptions({ options: {} }, {});
6868

6969
expect(result.options).toMatchObject({ mode: 'development' });
7070
});
7171

7272
targetValues.map((option) => {
7373
it(`should handle ${option} option`, async () => {
74-
const result = await applyOptions({ options: {} }, { target: option });
74+
const result = await cli.applyOptions({ options: {} }, { target: option });
7575

7676
expect(result.options.target).toEqual(option);
7777
});

packages/webpack-cli/lib/utils/cli-flags.js

-202
This file was deleted.

0 commit comments

Comments
 (0)