-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.dev-server.js
55 lines (55 loc) · 1.77 KB
/
webpack.dev-server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
// 改用 express & webpack-dev-middleware
module.exports = merge.strategy({
entry: 'replace', // or 'replace', defaults to 'append'
})(common, {
mode: 'development',
devtool: 'inline-source-map',
entry: {
// hot loader entry 文件都要添加 module.hot.accept
index: ['react-hot-loader/patch',
// 'webpack-dev-server/client?http://localhost:8080', // if iframe mode(inline:false)
'webpack/hot/only-dev-server',
path.resolve(__dirname, 'src/index.jsx')
],
// hot loader entry 文件都要添加 module.hot.accept
// math: ['react-hot-loader/patch',
// 'webpack/hot/only-dev-server',
// path.resolve(__dirname, 'src/math.js')
// ],
},
output: {
path: path.resolve(__dirname, 'dist'),//打包后的文件存放的地方 // path.resolve 生成绝对路径
filename: '[name].bundle.js',//打包后输出文件的文件名
publicPath: '/',
chunkFilename: '[name].bundle.js',
},
optimization: {
splitChunks: {
cacheGroups: {
vendors: {
test: /[\\/]node_modules[\\/]/,
priority: -10
}
}
}
},
plugins: [
new HtmlWebpackPlugin({
title: 'ReactApp'
}), // 生成 html 文件
new webpack.NamedModulesPlugin(),
new webpack.HotModuleReplacementPlugin() // 热替换 用于自定义的 server
], // 改用 express & webpack-dev-middleware
devServer: {
contentBase: './dist', // webpackServer 使用的路径
historyApiFallback: true, // 不跳转
inline: true,
open: true,// 是否自动打开浏览器
hot: true,
},
});