diff --git a/README.md b/README.md index 34c308a73c..ad57f1edfa 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,6 @@ [![npm][npm]][npm-url] [![node][node]][node-url] -[![deps][deps]][deps-url] [![tests][tests]][tests-url] [![coverage][cover]][cover-url] [![chat][chat]][chat-url] @@ -52,14 +51,14 @@ There are two main, recommended methods of using the module: ### With the CLI -The easiest way to use it is with the CLI. In the directory where your +The easiest way to use it is with the [webpack CLI](https://webpack.js.org/api/cli/). In the directory where your `webpack.config.js` is, run: ```console -node_modules/.bin/webpack-dev-server +node_modules/.bin/webpack serve ``` -_**Note**: Many CLI options are available with `webpack-dev-server`. Explore this [link](https://webpack.js.org/configuration/dev-server/)._ +_**Note**: Many CLI options are available with `webpack serve`. Explore this [link](https://webpack.js.org/configuration/dev-server/)._ ### With NPM Scripts @@ -69,7 +68,7 @@ script as such: ```json "scripts": { - "start:dev": "webpack-dev-server" + "start:dev": "webpack serve" } ``` @@ -144,8 +143,6 @@ This project is heavily inspired by [peerigon/nof5](https://github.com/peerigon/ [npm-url]: https://npmjs.com/package/webpack-dev-server [node]: https://img.shields.io/node/v/webpack-dev-server.svg [node-url]: https://nodejs.org -[deps]: https://david-dm.org/webpack/webpack-dev-server.svg -[deps-url]: https://david-dm.org/webpack/webpack-dev-server [tests]: https://github.com/webpack/webpack-dev-server/workflows/webpack-dev-server/badge.svg [tests-url]: https://github.com/webpack/webpack-dev-server/actions?query=workflow%3Awebpack-dev-server [cover]: https://codecov.io/gh/webpack/webpack-dev-server/branch/master/graph/badge.svg diff --git a/examples/api/middleware/server.js b/examples/api/middleware/server.js index eed5090f45..1df8fc70db 100644 --- a/examples/api/middleware/server.js +++ b/examples/api/middleware/server.js @@ -5,11 +5,7 @@ const WebpackDevServer = require('../../../lib/Server'); const webpackConfig = require('./webpack.config'); const compiler = Webpack(webpackConfig); -const devServerOptions = Object.assign({}, webpackConfig.devServer, { - stats: { - colors: true, - }, -}); +const devServerOptions = webpackConfig.devServer; const server = new WebpackDevServer(compiler, devServerOptions); server.listen(8080, '127.0.0.1', () => { diff --git a/examples/api/middleware/webpack.config.js b/examples/api/middleware/webpack.config.js index 28ae0eb186..547faee867 100644 --- a/examples/api/middleware/webpack.config.js +++ b/examples/api/middleware/webpack.config.js @@ -10,4 +10,7 @@ module.exports = setup({ output: { filename: 'bundle.js', }, + stats: { + colors: true, + }, }); diff --git a/examples/api/simple/server.js b/examples/api/simple/server.js index 0f0bc323b0..92db7677db 100644 --- a/examples/api/simple/server.js +++ b/examples/api/simple/server.js @@ -7,9 +7,6 @@ const webpackConfig = require('./webpack.config'); const compiler = Webpack(webpackConfig); const devServerOptions = Object.assign({}, webpackConfig.devServer, { open: true, - stats: { - colors: true, - }, }); const server = new WebpackDevServer(compiler, devServerOptions); diff --git a/examples/api/simple/webpack.config.js b/examples/api/simple/webpack.config.js index 28ae0eb186..547faee867 100644 --- a/examples/api/simple/webpack.config.js +++ b/examples/api/simple/webpack.config.js @@ -10,4 +10,7 @@ module.exports = setup({ output: { filename: 'bundle.js', }, + stats: { + colors: true, + }, }); diff --git a/examples/cli/listen-socket/README.md b/examples/cli/listen-socket/README.md deleted file mode 100644 index ab11649347..0000000000 --- a/examples/cli/listen-socket/README.md +++ /dev/null @@ -1,50 +0,0 @@ -# CLI: Socket Option - -To run the entire example, start the server with the following command: - -```console -npm run webpack-dev-server -- --socket ./webpack.sock -``` - -And then start node server that will use that socket: - -```console -node check-socket.js -``` - -## What Should Happen - -You should see this responses to this command: - -```console -Successfully connected to socket, exiting -``` - -## Use Cases - -A common use-case for this feature is configuring upstream in nginx that points -to webpack socket. Listening to socket instead of port is much more convenient -because if you have many applications you don't have to resolve port conflicts -since each of them has own unique socket. - -Example of configuring upstream with Websockets support in nginx: - -``` -location /webpack/ { - proxy_pass http://unix:/home/happywebpackuser/apps/todo/webpack.sock; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_pass http://unix:/home/resure/code/statface-raw/app/run/statbox.sock; - proxy_redirect off; -} -location /sockjs-node/ { - proxy_pass http://unix:/home/happywebpackuser/apps/todo/webpack.sock; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; -} -``` - -Replace `/webpack/` with your `publicPath` param value and path in `proxy_pass` -to your actual proxy location. diff --git a/examples/cli/listen-socket/check-socket.js b/examples/cli/listen-socket/check-socket.js deleted file mode 100644 index cc14321e3c..0000000000 --- a/examples/cli/listen-socket/check-socket.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict'; - -const net = require('net'); - -const client = net.createConnection('./webpack.sock'); -client.on('connect', () => { - console.log('Successfully connected to socket, exiting'); - process.exit(1); // eslint-disable-line -}); diff --git a/examples/cli/listen-socket/webpack.config.js b/examples/cli/listen-socket/webpack.config.js deleted file mode 100644 index e0e5363925..0000000000 --- a/examples/cli/listen-socket/webpack.config.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict'; - -// our setup function adds behind-the-scenes bits to the config that all of our -// examples need -const { setup } = require('../../util'); - -module.exports = setup({ - context: __dirname, - entry: './app.js', -}); diff --git a/examples/cli/open-page-multiple/README.md b/examples/cli/open-page-multiple/README.md index e5d07ec496..cc1a297b13 100644 --- a/examples/cli/open-page-multiple/README.md +++ b/examples/cli/open-page-multiple/README.md @@ -1,7 +1,7 @@ # CLI: Open Page Option (Multiple) ```console -npm run webpack-dev-server -- --open-page example1.html,example2.html +npm run webpack-dev-server -- --open --open-page example1.html --open-page example2.html ``` Some applications may consist of multiple pages. During development it may diff --git a/examples/cli/open-page-multiple/webpack.config.js b/examples/cli/open-page-multiple/webpack.config.js index d933139c04..c052dc4bd9 100644 --- a/examples/cli/open-page-multiple/webpack.config.js +++ b/examples/cli/open-page-multiple/webpack.config.js @@ -20,7 +20,7 @@ module.exports = [ }), ], }), - setup({ + { context: __dirname, entry: './app2.js', output: { @@ -33,5 +33,5 @@ module.exports = [ title: 'Open Page (Multiple) / Example / Page 2', }), ], - }), + }, ]; diff --git a/examples/cli/open-page/README.md b/examples/cli/open-page/README.md index df88bfae78..12b48f0292 100644 --- a/examples/cli/open-page/README.md +++ b/examples/cli/open-page/README.md @@ -1,7 +1,7 @@ # CLI: Open Page Option ```console -npm run webpack-dev-server -- --open-page example.html#page1 +npm run webpack-dev-server -- --open --open-page example.html#page1 ``` Some applications may consist of multiple pages. During development it may diff --git a/examples/cli/overlay/README.md b/examples/cli/overlay/README.md deleted file mode 100644 index 9de6bbc9f6..0000000000 --- a/examples/cli/overlay/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# CLI: Overlay Option - -`webpack-dev-server` can display an overlay for warnings and errors. - -```shell -npm run webpack-dev-server -- --open --overlay -``` - -_Note: To view additional options for the overlay visit -[https://webpack.js.org/configuration/dev-server/#devserver-overlay](https://webpack.js.org/configuration/dev-server/#devserver-overlay)._ - -## What Should Happen - -1. The script should open `http://localhost:8080/` in your default browser. -2. You should see the text on the page itself change to read `Success!`. -3. In `app.js` write code containing a syntax error and save the file. -4. The page should now refresh and show a full screen error overlay, displaying - the syntax error. diff --git a/examples/cli/overlay/app.js b/examples/cli/overlay/app.js deleted file mode 100644 index c78c71d97e..0000000000 --- a/examples/cli/overlay/app.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict'; - -const target = document.querySelector('#target'); - -target.classList.add('pass'); -target.innerHTML = 'Success!'; - -// This results in an error: -// if (!window) require('test'); diff --git a/examples/cli/overlay/webpack.config.js b/examples/cli/overlay/webpack.config.js deleted file mode 100644 index e0e5363925..0000000000 --- a/examples/cli/overlay/webpack.config.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict'; - -// our setup function adds behind-the-scenes bits to the config that all of our -// examples need -const { setup } = require('../../util'); - -module.exports = setup({ - context: __dirname, - entry: './app.js', -}); diff --git a/examples/cli/stdin/README.md b/examples/cli/stdin/README.md deleted file mode 100644 index e9364fa6a7..0000000000 --- a/examples/cli/stdin/README.md +++ /dev/null @@ -1,16 +0,0 @@ -# CLI: Stdin Option - -Specifying this option instructs the server to close when `stdin` ends. - -```console -npm run webpack-dev-server -- --stdin -``` - -## What Should Happen - -1. The server should begin running. -2. Press `CTL+D` on your keyboard. -3. The server should close. - -_Note: the keyboard shortcut for terminating `stdin` can vary depending on the -operating systems._ diff --git a/examples/cli/stdin/app.js b/examples/cli/stdin/app.js deleted file mode 100644 index da9a93b668..0000000000 --- a/examples/cli/stdin/app.js +++ /dev/null @@ -1,6 +0,0 @@ -'use strict'; - -const target = document.querySelector('#target'); - -target.innerHTML = - 'Press CTL+D on your keyboard to close the server.'; diff --git a/examples/cli/stdin/webpack.config.js b/examples/cli/stdin/webpack.config.js deleted file mode 100644 index c02f31ab8e..0000000000 --- a/examples/cli/stdin/webpack.config.js +++ /dev/null @@ -1,6 +0,0 @@ -'use strict'; - -module.exports = { - context: __dirname, - entry: './app.js', -}; diff --git a/examples/cli/watch-content-base/app.js b/examples/cli/watch-content-base/app.js deleted file mode 100644 index ae384858b9..0000000000 --- a/examples/cli/watch-content-base/app.js +++ /dev/null @@ -1,6 +0,0 @@ -'use strict'; - -const target = document.querySelector('#target'); - -target.classList.add('pass'); -target.innerHTML = 'Success!'; diff --git a/examples/cli/watch-content-base/README.md b/examples/cli/watch-static/README.md similarity index 83% rename from examples/cli/watch-content-base/README.md rename to examples/cli/watch-static/README.md index 9b6689d20d..74bfd9b073 100644 --- a/examples/cli/watch-content-base/README.md +++ b/examples/cli/watch-static/README.md @@ -3,7 +3,7 @@ ## Watching a single directory ```console -npm run webpack-dev-server -- --content-base assets --watch-content-base --open +npm run webpack-dev-server -- --static assets --open ``` ### What Should Happen @@ -20,13 +20,13 @@ npm run webpack-dev-server -- --content-base assets --watch-content-base --open module.exports = { /* ... */ devServer: { - contentBase: ['assets', 'css'], + static: ['assets', 'css'], }, }; ``` ```console -npm run webpack-dev-server -- --watch-content-base --open +npm run webpack-dev-server -- --open ``` ### What Should Happen diff --git a/examples/cli/listen-socket/app.js b/examples/cli/watch-static/app.js similarity index 100% rename from examples/cli/listen-socket/app.js rename to examples/cli/watch-static/app.js diff --git a/examples/cli/watch-content-base/assets/index.html b/examples/cli/watch-static/assets/index.html similarity index 100% rename from examples/cli/watch-content-base/assets/index.html rename to examples/cli/watch-static/assets/index.html diff --git a/examples/cli/watch-content-base/css/styles.css b/examples/cli/watch-static/css/styles.css similarity index 100% rename from examples/cli/watch-content-base/css/styles.css rename to examples/cli/watch-static/css/styles.css diff --git a/examples/cli/watch-content-base/webpack.config.js b/examples/cli/watch-static/webpack.config.js similarity index 87% rename from examples/cli/watch-content-base/webpack.config.js rename to examples/cli/watch-static/webpack.config.js index c2e972908c..1441be63f2 100644 --- a/examples/cli/watch-content-base/webpack.config.js +++ b/examples/cli/watch-static/webpack.config.js @@ -8,6 +8,6 @@ module.exports = setup({ context: __dirname, entry: './app.js', devServer: { - contentBase: ['assets', 'css'], + static: ['assets', 'css'], }, }); diff --git a/examples/general/config-array/webpack.config.js b/examples/general/config-array/webpack.config.js index d2be381d99..e5c9fcf268 100644 --- a/examples/general/config-array/webpack.config.js +++ b/examples/general/config-array/webpack.config.js @@ -22,7 +22,7 @@ module.exports = [ ], }, }), - setup({ + { context: __dirname, entry: './app.js', output: { @@ -44,5 +44,5 @@ module.exports = [ optimization: { minimize: true, }, - }), + }, ];