Skip to content

Commit 56a22a2

Browse files
committed
chore(deps-dev): migrate webpack-dev-server from v3 to v4
webpack-cli@4 requires webpack-dev-server@4: https://github.com/webpack/webpack-dev-server/releases/tag/v4.0.0-beta.0 * Migrate config from v3 to v4: https://github.com/webpack/webpack-dev-server/blob/master/migration-v4.md * Invoke webpack-dev-server using `webpack serve` instead: "Error: Cannot find module 'webpack-cli/bin/config-yargs' when use v5" webpack/webpack-dev-server#2424 * Pass production/development env with `--node-env` or nothing instead: https://github.com/webpack/webpack-cli/blob/master/CHANGELOG.md#450-2021-02-02 * `cross-env` is no longer needed * Webpack sets production/development env to 'production' by default https://v4.webpack.js.org/configuration/mode/
1 parent 0e0e659 commit 56a22a2

File tree

3 files changed

+360
-476
lines changed

3 files changed

+360
-476
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
2121
"@babel/preset-env": "^7.8.7",
2222
"@babel/preset-react": "^7.8.3",
23+
"@webpack-cli/serve": "^1.5.2",
2324
"babel-loader": "^8.0.6",
2425
"cross-env": "^7.0.2",
2526
"css-loader": "^3.4.2",
@@ -38,7 +39,7 @@
3839
"webpack": "^4.42.0",
3940
"webpack-cdn-plugin": "^3.2.2",
4041
"webpack-cli": "^4.8.0",
41-
"webpack-dev-server": "^3.10.3"
42+
"webpack-dev-server": "^4.0.0"
4243
},
4344
"lint-staged": {
4445
"*.json": [
@@ -98,8 +99,8 @@
9899
"scripts": {
99100
"clean": "rimraf dist/assets dist/index.html",
100101
"prebuild": "npm run clean",
101-
"build": "cross-env webpack",
102+
"build": "webpack",
102103
"prestart": "npm run clean",
103-
"start": "cross-env NODE_ENV=development webpack-dev-server"
104+
"start": "webpack serve --node-env=development"
104105
}
105106
}

webpack.config.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,12 @@ module.exports = {
121121
new HtmlWebpackHarddiskPlugin()
122122
]),
123123
devServer: {
124-
contentBase: path.join(__dirname, './dist'),
124+
static: {
125+
directory: path.resolve(__dirname, 'dist'),
126+
},
127+
devMiddleware: {
128+
publicPath: '/assets',
129+
},
125130
proxy: {
126131
'/bbs': {
127132
target: 'https://ws.ptt.cc',

0 commit comments

Comments
 (0)