-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
97 lines (96 loc) · 2.76 KB
/
webpack.config.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
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
//基于node 遵循commonjs规范
let path = require('path');
let HtmlWebpackPlugin = require('html-webpack-plugin');
let webpack = require('webpack');
let config = require('./config')
module.exports = {
devtool: "cheap-source-map",
performance: {
hints: false, // 性能提示[warning,error,false],
},
entry: {
index: [
"webpack-dev-server/client?http://localhost:3000/",
'webpack/hot/only-dev-server',
"react-hot-loader/patch",
"./src/index.js"
]
},
output: {
filename: "[name].[hash:8].js", //打包文件加8位哈希值清缓存
//导出路径必须是绝对路径
path: path.resolve('./build'),
publicPath: ''
}, //出口
devServer: {
contentBase: "./build",
publicPath: '',
port: 3000,
inline: true,
compress: true, //服务器压缩
open: true, //自动打开浏览器
hot: true, //开启热更新 要配置webpack自带的热更新插件 webpack.HotModuleReplacementPlugin
proxy: {
'/api': 'http://localhost:4000'
}
},
module: { //loader处理//模块配置
rules: [{
test: /\.jsx?$/,
exclude: /node_modules/,
include: path.resolve(__dirname, './src'),
loader: ["react-hot-loader/webpack","babel-loader"]
},
{
test: /\.css$/,
use: [{
loader: "style-loader"
},
{
loader: "css-loader"
}
]
},
{
test: /\.less$/,
use: [{
loader: "style-loader"
},
{
loader: "css-loader"
},
{
loader: "less-loader"
}
]
},
{
test: /\.(jpe?g|png|gif|svg|ico)$/,
use: [{
loader: 'file-loader?name=images/img_[hash:8].[ext]'
}]
}
]
},
plugins: [ //插件配置
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
new HtmlWebpackPlugin({
filename: "index.html",
template: "./src/index.html",
favicon: "./src/favicon.ico",
title: "react+webpack4",
hash: true
})
],
mode: "development",
resolve: {
extensions: ['.js', '.jsx', '.json', '.less', '.css'],
alias: {
'src': path.resolve(__dirname, './src'),
'components': path.resolve(__dirname, './src/app/components'),
'page': path.resolve(__dirname, './src/app/page'),
'util': path.resolve(__dirname, './src/util')
}
}//配置解析规则
}