Skip to content

Commit c142db9

Browse files
committed
调整webpack-dev-server相关配置,实现LiveReload
1 parent 52fc54f commit c142db9

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
"scripts": {
66
"build": "node npm-scripts/before-build.script.js && webpack --progress --colors --bail",
77
"dev": "node npm-scripts/before-build.script.js && webpack --progress --colors --config ./webpack.dev.config.js",
8-
"watch": "node npm-scripts/before-build.script.js && webpack --progress --colors --watch --config ./webpack.dev.config.js",
9-
"start": "webpack-dev-server --inline --progress --compress --devtool eval --content-base build/ --open",
8+
"start": "webpack-dev-server --config ./webpack.dev.config.js --open",
109
"profile": "node npm-scripts/before-build.script.js && webpack --colors --profile --display-modules",
1110
"dll": "node npm-scripts/before-build-dll.script.js && webpack --progress --colors --config ./webpack-dll.config.js",
1211
"analyse": "webpack --json > ./build/stats.json && webpack-bundle-analyzer --port 8989 ./build/stats.json",

webpack-config/output.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var dirVars = require('./base/dir-vars.config.js');
22
module.exports = {
33
path: dirVars.buildDir,
4-
publicPath: '../../',
4+
publicPath: '/',
55
filename: '[name]/entry.js', // [name]表示entry每一项中的key,用以批量指定生成后文件的名称
66
chunkFilename: '[id].bundle.js',
77
};

webpack.dev.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,14 @@ module.exports = {
1212
eslint: require('./webpack-config/vendor/eslint.config.js'),
1313

1414
postcss: require('./webpack-config/vendor/postcss.config.js'),
15+
16+
devServer: {
17+
contentBase: './build/',
18+
host: 'localhost',
19+
port: 9090, // 默认8080
20+
inline: true, // 可以监控js变化
21+
// hot: true, // 热启动
22+
compress: true,
23+
watchContentBase: true,
24+
},
1525
};

0 commit comments

Comments
 (0)