-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.dev.js
More file actions
executable file
·122 lines (103 loc) · 2.82 KB
/
Copy pathwebpack.config.dev.js
File metadata and controls
executable file
·122 lines (103 loc) · 2.82 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
const { resolve } = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: [
'react-hot-loader/patch',
// 开启 React 代码的模块热替换(HMR)
'webpack-dev-server/client?http://localhost:8080',
// 为 webpack-dev-server 的环境打包代码
// 然后连接到指定服务器域名与端口
'webpack/hot/only-dev-server',
// 为热替换(HMR)打包好代码
// only- 意味着只有成功更新运行代码才会执行热替换(HMR)
'./index.js'
// 我们 app 的入口文件
],
output: {
filename: 'bundle.js',
// 输出的打包文件
path: resolve(__dirname, 'dist'),
publicPath: '/'
// 对于热替换(HMR)是必须的,让 webpack 知道在哪里载入热更新的模块(chunk)
},
context: resolve(__dirname, 'src'),
devtool: 'inline-source-map',
devServer: {
hot: true,
// 开启服务器的模块热替换(HMR)
contentBase: resolve(__dirname, 'dist'),
// 输出文件的路径
publicPath: '/',
// 和上文 output 的“publicPath”值保持一致
historyApiFallback: true,
// proxy: {
// "/": "http://192.168.0.101:3000"
// }
},
module: {
rules: [
{
test: /\.js$/,
use: [
'babel-loader',
],
exclude: /node_modules/
},
{
test: /\.css$/,
use: [
'style-loader',
'css-loader?modules',
{
loader: 'postcss-loader',
options: {
plugins: function () {
return [
require('precss'),
require('autoprefixer')
];
}
}
},
],
},
{
test: /\.less$/,
use: [
'style-loader',
'css-loader',
{
loader: 'less-loader',
},
],
},
{
test: /\.(png|jpg|gif|jpeg)$/,
use: ['url-loader?limit=8192'],
exclude: /node_modules/
},
{
test: /\.svg(\?.*)?$/,
use: ['url-loader?prefix=fonts/&name=[hash:base64:20].[ext]&limit=10000&mimetype=image/svg+xml'],
exclude: /node_modules/
},
{
test: /\.(woff(2)?|eot|ttf|svg)(\?[a-z0-9=\.]+)?$/,
use: 'url-loader?limit=100000'
}
],
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
// 开启全局的模块热替换(HMR)
new webpack.NamedModulesPlugin(),
// 当模块热替换(HMR)时在浏览器控制台输出对用户更友好的模块名字信息
new HtmlWebpackPlugin({
template: './index.html',
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
})
],
};