From 16183159b86a5a72e87427dd6207cd49c583a86f Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Sat, 1 May 2021 15:51:11 +0530 Subject: [PATCH 1/6] feat: add more static option related cli flags --- bin/cli-flags.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/bin/cli-flags.js b/bin/cli-flags.js index 16fd661d25..02776fe336 100644 --- a/bin/cli-flags.js +++ b/bin/cli-flags.js @@ -37,6 +37,56 @@ module.exports = { multiple: true, negative: true, }, + { + name: 'static-directory', + type: String, + configs: [ + { + type: 'string', + }, + ], + description: '', + multiple: true, + 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 when enabled.', + negative: true, + processor(opts) { + opts.static = opts.static || {}; + opts.static.serveIndex = opts.staticServeIndex; + delete opts.staticServeIndex; + }, + }, { name: 'live-reload', type: Boolean, From 7dd44610e021b1a05bb061b19cc3801c420e98db Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Sat, 1 May 2021 15:59:56 +0530 Subject: [PATCH 2/6] feat: --static-watch --- bin/cli-flags.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/bin/cli-flags.js b/bin/cli-flags.js index 02776fe336..e6f7301ac5 100644 --- a/bin/cli-flags.js +++ b/bin/cli-flags.js @@ -87,6 +87,22 @@ module.exports = { delete opts.staticServeIndex; }, }, + { + name: 'static-watch', + type: Boolean, + configs: [ + { + type: 'boolean', + }, + ], + description: 'Watch for static content directory.', + negative: true, + processor(opts) { + opts.static = opts.static || {}; + opts.static.watch = opts.staticWatch; + delete opts.staticWatch; + }, + }, { name: 'live-reload', type: Boolean, From 91fda7cfe4f2d9fd1023105f00d06f530dfffb33 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Sat, 1 May 2021 16:01:55 +0530 Subject: [PATCH 3/6] test: update snapshot --- .../__snapshots__/cli.test.js.snap.webpack5 | 161 ++++++++++-------- 1 file changed, 88 insertions(+), 73 deletions(-) diff --git a/test/cli/__snapshots__/cli.test.js.snap.webpack5 b/test/cli/__snapshots__/cli.test.js.snap.webpack5 index 2d03c2738d..493738f961 100644 --- a/test/cli/__snapshots__/cli.test.js.snap.webpack5 +++ b/test/cli/__snapshots__/cli.test.js.snap.webpack5 @@ -10,7 +10,9 @@ exports[`CLI --bonjour 1`] = ` `; exports[`CLI --bonjour and --https 1`] = ` -" [webpack-dev-server] Project is running at: +" [webpack-dev-server] SSL Certificate is more than 30 days old. Removing. + [webpack-dev-server] Generating SSL Certificate + [webpack-dev-server] Project is running at: [webpack-dev-server] Loopback: https://localhost:/ [webpack-dev-server] On Your Network (IPv4): https://:/ [webpack-dev-server] On Your Network (IPv6): https://[]:/ @@ -154,80 +156,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. - -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 + --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 when enabled. + --no-static-serve-index Negative 'static-serve-index' option. + --static-watch Watch for static content directory. + --no-static-watch Negative 'static-watch' 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. 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'. From 763fcd816dee19f6f11bede12b37f30bc7ba4d5a Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Sat, 1 May 2021 16:08:52 +0530 Subject: [PATCH 4/6] test: updates --- bin/cli-flags.js | 11 ++++++----- test/cli/__snapshots__/cli.test.js.snap.webpack5 | 16 ++++++++-------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/bin/cli-flags.js b/bin/cli-flags.js index e6f7301ac5..5270554783 100644 --- a/bin/cli-flags.js +++ b/bin/cli-flags.js @@ -45,8 +45,7 @@ module.exports = { type: 'string', }, ], - description: '', - multiple: true, + description: 'Directory for static contents.', processor(opts) { opts.static = opts.static || {}; opts.static.directory = opts.staticDirectory; @@ -78,8 +77,9 @@ module.exports = { type: 'boolean', }, ], - description: - 'Tells dev-server to use serveIndex middleware when enabled.', + 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 || {}; @@ -95,7 +95,8 @@ module.exports = { type: 'boolean', }, ], - description: 'Watch for static content directory.', + 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 || {}; diff --git a/test/cli/__snapshots__/cli.test.js.snap.webpack5 b/test/cli/__snapshots__/cli.test.js.snap.webpack5 index 493738f961..9ff758ac94 100644 --- a/test/cli/__snapshots__/cli.test.js.snap.webpack5 +++ b/test/cli/__snapshots__/cli.test.js.snap.webpack5 @@ -10,9 +10,7 @@ exports[`CLI --bonjour 1`] = ` `; exports[`CLI --bonjour and --https 1`] = ` -" [webpack-dev-server] SSL Certificate is more than 30 days old. Removing. - [webpack-dev-server] Generating SSL Certificate - [webpack-dev-server] Project is running at: +" [webpack-dev-server] Project is running at: [webpack-dev-server] Loopback: https://localhost:/ [webpack-dev-server] On Your Network (IPv4): https://:/ [webpack-dev-server] On Your Network (IPv6): https://[]:/ @@ -189,14 +187,16 @@ Options: --port The port server will listen to. --static [value...] A directory to serve static content from. --no-static Negative 'static' option. - --static-directory + --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 when enabled. - --no-static-serve-index Negative 'static-serve-index' option. - --static-watch Watch for static content directory. - --no-static-watch Negative 'static-watch' option. + 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. From 95d687eb8c3cdcd0cb2808d5c97b1ac75469afe9 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Sat, 1 May 2021 16:16:44 +0530 Subject: [PATCH 5/6] test: more --- test/cli/cli.test.js | 73 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) 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', From 38e8b035b9a19a5a1777572e2ba26d47487d4669 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Sat, 1 May 2021 16:21:14 +0530 Subject: [PATCH 6/6] test: webpack-4 --- .../__snapshots__/cli.test.js.snap.webpack4 | 155 ++++++++++-------- 1 file changed, 85 insertions(+), 70 deletions(-) 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'.