diff --git a/bin/cli-flags.js b/bin/cli-flags.js index 16fd661d25..5270554783 100644 --- a/bin/cli-flags.js +++ b/bin/cli-flags.js @@ -37,6 +37,73 @@ module.exports = { multiple: true, negative: true, }, + { + name: 'static-directory', + type: String, + configs: [ + { + type: 'string', + }, + ], + description: 'Directory for static contents.', + processor(opts) { + opts.static = opts.static || {}; + opts.static.directory = opts.staticDirectory; + delete opts.staticDirectory; + }, + }, + { + name: 'static-public-path', + type: String, + configs: [ + { + type: 'string', + }, + ], + description: + 'The bundled files will be available in the browser under this path.', + multiple: true, + processor(opts) { + opts.static = opts.static || {}; + opts.static.publicPath = opts.staticPublicPath; + delete opts.staticPublicPath; + }, + }, + { + name: 'static-serve-index', + type: Boolean, + configs: [ + { + type: 'boolean', + }, + ], + description: 'Tells dev-server to use serveIndex middleware.', + negatedDescription: + 'Do not tell dev-server to use serveIndex middleware.', + negative: true, + processor(opts) { + opts.static = opts.static || {}; + opts.static.serveIndex = opts.staticServeIndex; + delete opts.staticServeIndex; + }, + }, + { + name: 'static-watch', + type: Boolean, + configs: [ + { + type: 'boolean', + }, + ], + description: 'Watch for files in static content directory.', + negatedDescription: 'Do not watch for files in static content directory.', + negative: true, + processor(opts) { + opts.static = opts.static || {}; + opts.static.watch = opts.staticWatch; + delete opts.staticWatch; + }, + }, { name: 'live-reload', type: Boolean, diff --git a/test/cli/__snapshots__/cli.test.js.snap.webpack4 b/test/cli/__snapshots__/cli.test.js.snap.webpack4 index 20e5f2ce1d..c2184b033a 100644 --- a/test/cli/__snapshots__/cli.test.js.snap.webpack4 +++ b/test/cli/__snapshots__/cli.test.js.snap.webpack4 @@ -154,78 +154,93 @@ exports[`CLI should generate correct cli flags 1`] = ` Run the webpack dev server. Options: - -c, --config Provide path to a webpack configuration file e.g. - ./webpack.config.js. - --config-name Name of the configuration to use. - -m, --merge Merge two or more configurations using - 'webpack-merge'. - --env Environment passed to the configuration when it is - a function. - --node-env Sets process.env.NODE_ENV to the specified value. - --progress [value] Print compilation progress during build. - -j, --json [value] Prints result as JSON or store it in a file. - --entry The entry point(s) of your application e.g. - ./src/main.js. - -o, --output-path Output location of the file generated by webpack - e.g. ./dist/. - -t, --target Sets the build target e.g. node. - -d, --devtool Determine source maps to use. - --mode Defines the mode to pass to webpack. - --name Name of the configuration. Used when loading - multiple configurations. - --stats [value] It instructs webpack on how to treat the stats - e.g. verbose. - --no-stats Disable stats output. - --watch-options-stdin Stop watching when stdin stream has ended. - --no-watch-options-stdin Do not stop watching when stdin stream has ended. - --host The hostname/ip address the server will bind to. - --port The port server will listen to. - --static [value...] A directory to serve static content from. - --no-static Negative 'static' option. - --live-reload Enables live reloading on changing files. - --no-live-reload Disables live reloading on changing files. - --https Use HTTPS protocol. - --no-https Do not use HTTPS protocol. - --http2 Use HTTP/2, must be used with HTTPS. - --no-http2 Do not use HTTP/2. - --bonjour Broadcasts the server via ZeroConf networking on - start. - --no-bonjour Do not broadcast the server via ZeroConf - networking on start. - --client-progress Print compilation progress in percentage in the - browser. - --no-client-progress Do not print compilation progress in percentage in - the browser. - --client-overlay Show a full-screen overlay in the browser when - there are compiler errors or warnings. - --no-client-overlay Do not show a full-screen overlay in the browser - when there are compiler errors or warnings. - --open [value...] Open the default browser. - --no-open Do not open the default browser. - --open-app Open specified browser. - --open-target [value...] Open specified route in browser. - --no-open-target Do not open specified route in browser. - --client-logging Log level in the browser (none, error, warn, info, - log, verbose). - --history-api-fallback Fallback to /index.html for Single Page - Applications. - --no-history-api-fallback Do not fallback to /index.html for Single Page - Applications. - --compress Enable gzip compression. - --no-compress Disable gzip compression. - --public The public hostname/ip address of the server. - --firewall [value...] Enable firewall or set hosts that are allowed to - access the dev server. - --no-firewall Disable firewall. - --watch-files Watch static files for file changes. + -c, --config Provide path to a webpack configuration file + e.g. ./webpack.config.js. + --config-name Name of the configuration to use. + -m, --merge Merge two or more configurations using + 'webpack-merge'. + --env Environment passed to the configuration when + it is a function. + --node-env Sets process.env.NODE_ENV to the specified + value. + --progress [value] Print compilation progress during build. + -j, --json [value] Prints result as JSON or store it in a file. + --entry The entry point(s) of your application e.g. + ./src/main.js. + -o, --output-path Output location of the file generated by + webpack e.g. ./dist/. + -t, --target Sets the build target e.g. node. + -d, --devtool Determine source maps to use. + --mode Defines the mode to pass to webpack. + --name Name of the configuration. Used when loading + multiple configurations. + --stats [value] It instructs webpack on how to treat the + stats e.g. verbose. + --no-stats Disable stats output. + --watch-options-stdin Stop watching when stdin stream has ended. + --no-watch-options-stdin Do not stop watching when stdin stream has + ended. + --host The hostname/ip address the server will bind + to. + --port The port server will listen to. + --static [value...] A directory to serve static content from. + --no-static Negative 'static' option. + --static-directory Directory for static contents. + --static-public-path The bundled files will be available in the + browser under this path. + --static-serve-index Tells dev-server to use serveIndex + middleware. + --no-static-serve-index Do not tell dev-server to use serveIndex + middleware. + --static-watch Watch for files in static content directory. + --no-static-watch Do not watch for files in static content + directory. + --live-reload Enables live reloading on changing files. + --no-live-reload Disables live reloading on changing files. + --https Use HTTPS protocol. + --no-https Do not use HTTPS protocol. + --http2 Use HTTP/2, must be used with HTTPS. + --no-http2 Do not use HTTP/2. + --bonjour Broadcasts the server via ZeroConf + networking on start. + --no-bonjour Do not broadcast the server via ZeroConf + networking on start. + --client-progress Print compilation progress in percentage in + the browser. + --no-client-progress Do not print compilation progress in + percentage in the browser. + --client-overlay Show a full-screen overlay in the browser + when there are compiler errors or warnings. + --no-client-overlay Do not show a full-screen overlay in the + browser when there are compiler errors or + warnings. + --open [value...] Open the default browser. + --no-open Do not open the default browser. + --open-app Open specified browser. + --open-target [value...] Open specified route in browser. + --no-open-target Do not open specified route in browser. + --client-logging Log level in the browser (none, error, warn, + info, log, verbose). + --history-api-fallback Fallback to /index.html for Single Page + Applications. + --no-history-api-fallback Do not fallback to /index.html for Single + Page Applications. + --compress Enable gzip compression. + --no-compress Disable gzip compression. + --public The public hostname/ip address of the + server. + --firewall [value...] Enable firewall or set hosts that are + allowed to access the dev server. + --no-firewall Disable firewall. + --watch-files Watch static files for file changes. 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. To see list of all supported commands and options run 'webpack --help=verbose'. diff --git a/test/cli/__snapshots__/cli.test.js.snap.webpack5 b/test/cli/__snapshots__/cli.test.js.snap.webpack5 index 2d03c2738d..9ff758ac94 100644 --- a/test/cli/__snapshots__/cli.test.js.snap.webpack5 +++ b/test/cli/__snapshots__/cli.test.js.snap.webpack5 @@ -154,80 +154,95 @@ exports[`CLI should generate correct cli flags 1`] = ` Run the webpack dev server. Options: - -c, --config Provide path to a webpack configuration file e.g. - ./webpack.config.js. - --config-name Name of the configuration to use. - -m, --merge Merge two or more configurations using - 'webpack-merge'. - --env Environment passed to the configuration when it is - a function. - --node-env Sets process.env.NODE_ENV to the specified value. - --progress [value] Print compilation progress during build. - -j, --json [value] Prints result as JSON or store it in a file. - -d, --devtool Determine source maps to use. - --no-devtool Do not generate source maps. - --entry The entry point(s) of your application e.g. - ./src/main.js. - --mode Defines the mode to pass to webpack. - --name Name of the configuration. Used when loading - multiple configurations. - -o, --output-path Output location of the file generated by webpack - e.g. ./dist/. - --stats [value] It instructs webpack on how to treat the stats - e.g. verbose. - --no-stats Disable stats output. - -t, --target Sets the build target e.g. node. - --no-target Negative 'target' option. - --watch-options-stdin Stop watching when stdin stream has ended. - --no-watch-options-stdin Do not stop watching when stdin stream has ended. - --host The hostname/ip address the server will bind to. - --port The port server will listen to. - --static [value...] A directory to serve static content from. - --no-static Negative 'static' option. - --live-reload Enables live reloading on changing files. - --no-live-reload Disables live reloading on changing files. - --https Use HTTPS protocol. - --no-https Do not use HTTPS protocol. - --http2 Use HTTP/2, must be used with HTTPS. - --no-http2 Do not use HTTP/2. - --bonjour Broadcasts the server via ZeroConf networking on - start. - --no-bonjour Do not broadcast the server via ZeroConf - networking on start. - --client-progress Print compilation progress in percentage in the - browser. - --no-client-progress Do not print compilation progress in percentage in - the browser. - --client-overlay Show a full-screen overlay in the browser when - there are compiler errors or warnings. - --no-client-overlay Do not show a full-screen overlay in the browser - when there are compiler errors or warnings. - --open [value...] Open the default browser. - --no-open Do not open the default browser. - --open-app Open specified browser. - --open-target [value...] Open specified route in browser. - --no-open-target Do not open specified route in browser. - --client-logging Log level in the browser (none, error, warn, info, - log, verbose). - --history-api-fallback Fallback to /index.html for Single Page - Applications. - --no-history-api-fallback Do not fallback to /index.html for Single Page - Applications. - --compress Enable gzip compression. - --no-compress Disable gzip compression. - --public The public hostname/ip address of the server. - --firewall [value...] Enable firewall or set hosts that are allowed to - access the dev server. - --no-firewall Disable firewall. - --watch-files Watch static files for file changes. + -c, --config Provide path to a webpack configuration file + e.g. ./webpack.config.js. + --config-name Name of the configuration to use. + -m, --merge Merge two or more configurations using + 'webpack-merge'. + --env Environment passed to the configuration when + it is a function. + --node-env Sets process.env.NODE_ENV to the specified + value. + --progress [value] Print compilation progress during build. + -j, --json [value] Prints result as JSON or store it in a file. + -d, --devtool Determine source maps to use. + --no-devtool Do not generate source maps. + --entry The entry point(s) of your application e.g. + ./src/main.js. + --mode Defines the mode to pass to webpack. + --name Name of the configuration. Used when loading + multiple configurations. + -o, --output-path Output location of the file generated by + webpack e.g. ./dist/. + --stats [value] It instructs webpack on how to treat the + stats e.g. verbose. + --no-stats Disable stats output. + -t, --target Sets the build target e.g. node. + --no-target Negative 'target' option. + --watch-options-stdin Stop watching when stdin stream has ended. + --no-watch-options-stdin Do not stop watching when stdin stream has + ended. + --host The hostname/ip address the server will bind + to. + --port The port server will listen to. + --static [value...] A directory to serve static content from. + --no-static Negative 'static' option. + --static-directory Directory for static contents. + --static-public-path The bundled files will be available in the + browser under this path. + --static-serve-index Tells dev-server to use serveIndex + middleware. + --no-static-serve-index Do not tell dev-server to use serveIndex + middleware. + --static-watch Watch for files in static content directory. + --no-static-watch Do not watch for files in static content + directory. + --live-reload Enables live reloading on changing files. + --no-live-reload Disables live reloading on changing files. + --https Use HTTPS protocol. + --no-https Do not use HTTPS protocol. + --http2 Use HTTP/2, must be used with HTTPS. + --no-http2 Do not use HTTP/2. + --bonjour Broadcasts the server via ZeroConf + networking on start. + --no-bonjour Do not broadcast the server via ZeroConf + networking on start. + --client-progress Print compilation progress in percentage in + the browser. + --no-client-progress Do not print compilation progress in + percentage in the browser. + --client-overlay Show a full-screen overlay in the browser + when there are compiler errors or warnings. + --no-client-overlay Do not show a full-screen overlay in the + browser when there are compiler errors or + warnings. + --open [value...] Open the default browser. + --no-open Do not open the default browser. + --open-app Open specified browser. + --open-target [value...] Open specified route in browser. + --no-open-target Do not open specified route in browser. + --client-logging Log level in the browser (none, error, warn, + info, log, verbose). + --history-api-fallback Fallback to /index.html for Single Page + Applications. + --no-history-api-fallback Do not fallback to /index.html for Single + Page Applications. + --compress Enable gzip compression. + --no-compress Disable gzip compression. + --public The public hostname/ip address of the + server. + --firewall [value...] Enable firewall or set hosts that are + allowed to access the dev server. + --no-firewall Disable firewall. + --watch-files Watch static files for file changes. 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. To see list of all supported commands and options run 'webpack --help=verbose'. diff --git a/test/cli/cli.test.js b/test/cli/cli.test.js index 8b6f2343de..27244990a1 100644 --- a/test/cli/cli.test.js +++ b/test/cli/cli.test.js @@ -460,6 +460,79 @@ describe('CLI', () => { .catch(done); }); + it('--static', (done) => { + testBin('--static') + .then((output) => { + expect(output.exitCode).toEqual(0); + done(); + }) + .catch(done); + }); + + it('--static ', (done) => { + testBin( + `--static ${path.resolve( + __dirname, + '../fixtures/static/webpack.config.js' + )}` + ) + .then((output) => { + expect(output.exitCode).toEqual(0); + done(); + }) + .catch(done); + }); + + it('--static-directory', (done) => { + testBin( + `--static-directory ${path.resolve( + __dirname, + '../fixtures/static/webpack.config.js' + )}` + ) + .then((output) => { + expect(output.exitCode).toEqual(0); + done(); + }) + .catch(done); + }); + + it('--static-serve-index', (done) => { + testBin('--static-serve-index') + .then((output) => { + expect(output.exitCode).toEqual(0); + done(); + }) + .catch(done); + }); + + it('--no-static-serve-index', (done) => { + testBin('--no-static-serve-index') + .then((output) => { + expect(output.exitCode).toEqual(0); + done(); + }) + .catch(done); + }); + + it('--static-watch', (done) => { + testBin('--static-watch') + .then((output) => { + expect(output.exitCode).toEqual(0); + done(); + }) + .catch(done); + }); + + it('--no-static-watch', (done) => { + testBin('--static-watch') + .then((output) => { + expect(output.exitCode).toEqual(0); + done(); + }) + .catch(done); + }); + it('should log static', (done) => { testBin( '--no-color',