-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
95 lines (85 loc) · 2.89 KB
/
webpack.config.js
File metadata and controls
95 lines (85 loc) · 2.89 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
var path = require('path')
var webpack = require('webpack')
var HtmlWebpackPlugin = require('html-webpack-plugin')
var ExtractTextPlugin = require('extract-text-webpack-plugin')
var Dashboard = require('webpack-dashboard')
var DashboardPlugin = require('webpack-dashboard/plugin')
var dashboard = new Dashboard()
module.exports = {
entry: [
// 开启 React 代码的模块热替换(HMR)
"react-hot-loader/patch",
// 为 webpack-dev-server 的环境打包代码
// 然后连接到指定服务器域名与端口
"webpack-dev-server/client?http://localhost:8888",
// 为热替换(HMR)打包好代码
// only- 意味着只有成功更新运行代码才会执行热替换(HMR)
"webpack/hot/only-dev-server",
// 入口文件
"./index.js"
],
output: {
filename: "bundle.js",
path: path.resolve(__dirname, 'dist'),
// 对于热替换(HMR)是必须的,让 webpack 知道在哪里载入热更新的模块(chunk)
publicPath: '/',
chunkFilename: "[name].[chunkhash:6].js"
},
context: path.resolve(__dirname, 'src'),
// devtool: 'inline-source-map',
devServer: {
port: 8888,
hot: true,
quiet: true,
historyApiFallback: true,
contentBase: path.resolve(__dirname, 'dist'),
// 和上文 output 的“publicPath”值保持一致
publicPath: '/'
},
module: {
rules: [{
test: /\.js$/,
use: [
'babel-loader',
],
exclude: /node_modules/
}, {
test: /\.css$/,
use: ExtractTextPlugin.extract({
// 懒加载组件用到
fallback: "style-loader",
use: [{
loader: "css-loader",
options: {
modules: true,
minimize:true,
importLoaders: true,
localIdentName: "[name]-[local]-[hash:base64:6]"
}
}, {
loader: "postcss-loader",
options: {
plugins: function() {
return [
require("autoprefixer")
]
}
}
}]
})
}]
},
plugins: [
new HtmlWebpackPlugin({
template: "./index.html"
}),
// 开启全局的模块热替换(HMR)
new webpack.HotModuleReplacementPlugin(),
// 当模块热替换(HMR)时在浏览器控制台输出对用户更友好的模块名字信息
new webpack.NamedModulesPlugin(),
// 单独打包css
new ExtractTextPlugin("bundle.css"),
// webpack可视化
new DashboardPlugin(dashboard.setData)
],
}