Skip to content

Commit

Permalink
feat: entries syntax (#2369)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Jan 27, 2021
1 parent 153d449 commit 6b31614
Show file tree
Hide file tree
Showing 33 changed files with 991 additions and 692 deletions.
40 changes: 17 additions & 23 deletions OPTIONS.md
@@ -1,12 +1,6 @@
```
Usage: webpack [options]
Alternative usage: webpack --config <config> [options]
Alternative usage: webpack build [options]
Alternative usage: webpack bundle [options]
Alternative usage: webpack b [options]
Alternative usage: webpack build --config <config> [options]
Alternative usage: webpack bundle --config <config> [options]
Alternative usage: webpack b --config <config> [options]
Usage: webpack [entries...] [options]
Alternative usage to run commands: webpack [command] [options]
The build tool for modern web applications.
Expand Down Expand Up @@ -793,23 +787,23 @@ Options:
--no-watch-options-stdin Do not stop watching when stdin stream has ended.
Global options:
--color Enable colors on console.
--no-color Disable colors on console.
-v, --version Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and commands.
-h, --help [verbose] Display help for commands and options.
--color Enable colors on console.
--no-color Disable colors on console.
-v, --version Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and commands.
-h, --help [verbose] Display help for commands and options.
Commands:
build|bundle|b [options] Run webpack (default command, can be omitted).
watch|w [options] Run webpack and watch for files changes.
version|v [commands...] Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and commands.
help|h [command] [option] Display help for commands and options.
serve|s [options] Run the webpack dev server.
info|i [options] Outputs information about your system.
init|c [options] [scaffold...] Initialize a new webpack configuration.
loader|l [output-path] Scaffold a loader.
migrate|m <config-path> [new-config-path] Migrate a configuration to a new version.
configtest|t [config-path] Tests webpack configuration against validation errors.
plugin|p [output-path] Scaffold a plugin.
build|bundle|b [entries...] [options] Run webpack (default command, can be omitted).
configtest|t [config-path] Tests webpack configuration against validation errors.
help|h [command] [option] Display help for commands and options.
info|i [options] Outputs information about your system.
init|c [scaffold...] [options] Initialize a new webpack configuration.
loader|l [output-path] Scaffold a loader.
migrate|m <config-path> [new-config-path] Migrate a configuration to a new version.
plugin|p [output-path] Scaffold a plugin.
serve|s [entries...] [options] Run the webpack dev server.
version|v [commands...] Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and commands.
watch|w [entries...] [options] Run webpack and watch for files changes.
To see list of all supported commands and options run 'webpack --help=verbose'.
Expand Down
10 changes: 7 additions & 3 deletions packages/serve/src/index.ts
Expand Up @@ -6,10 +6,10 @@ class ServeCommand {

await cli.makeCommand(
{
name: 'serve',
name: 'serve [entries...]',
alias: 's',
description: 'Run the webpack dev server.',
usage: '[options]',
usage: '[entries...] [options]',
pkg: '@webpack-cli/serve',
dependencies: ['webpack-dev-server'],
},
Expand All @@ -28,7 +28,7 @@ class ServeCommand {

return [...builtInOptions, ...devServerFlags];
},
async (options) => {
async (entries, options) => {
const builtInOptions = cli.getBuiltInOptions();
let devServerFlags = [];

Expand Down Expand Up @@ -72,6 +72,10 @@ class ServeCommand {
processor(devServerOptions);
}

if (entries.length > 0) {
webpackOptions.entry = [...entries, ...(webpackOptions.entry || [])];
}

webpackOptions.argv = { ...options, env: { WEBPACK_SERVE: true, ...options.env } };

const compiler = await cli.createCompiler(webpackOptions);
Expand Down
20 changes: 10 additions & 10 deletions packages/webpack-cli/__tests__/resolveArgs.test.js
Expand Up @@ -2,24 +2,24 @@ const { resolve } = require('path');
const webpackCLI = require('../lib/webpack-cli');

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

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

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

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

expect(result.options).toMatchObject({ mode: 'production' });
expect(result.options.mode).toEqual('production');
});

it('should handle the mode option [development]', async () => {
const result = await applyOptions(
const result = await cli.applyOptions(
{ options: {} },
{
mode: 'development',
Expand All @@ -31,7 +31,7 @@ describe('BasicResolver', () => {
});

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

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

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

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

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

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

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

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

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

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

expect(result.options.target).toEqual(option);
});
Expand Down
202 changes: 0 additions & 202 deletions packages/webpack-cli/lib/utils/cli-flags.js

This file was deleted.

0 comments on commit 6b31614

Please sign in to comment.