-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathwebpack.config.js
67 lines (67 loc) · 2.32 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
const path = require('path');
let webpack = require('webpack');
let HtmlWebpackPlugin = require('html-webpack-plugin');
let { CleanWebpackPlugin } = require('clean-webpack-plugin');
module.exports = {
entry: './src/index.js',
output: {
filename: 'bundle.[hash:4].js', //添加hash可以防止文件缓存,每次都会生成4位hash串
path: path.resolve('dist'),
publicPath: '/'
},
devServer: {
contentBase: "./dist", // 本地服务器所加载的页面所在的目录
historyApiFallback: true, // 不跳转
inline: true, // 实时刷新
port: 3000, // 项目端口
open: false, // 不自动打开浏览器
},
resolve: {
// 引入文件不写后缀名的时候,通过以下顺序尝试引入文件
extensions: [".js", ".jsx"],
alias: {
components: path.resolve(__dirname, "src/components"),
views: path.resolve(__dirname, "src/views"),
images: path.resolve(__dirname, "src/asset/images"),
css: path.resolve(__dirname, "src/asset/css"),
myRedux: path.resolve(__dirname, "src/redux")
}
},
plugins: [
new HtmlWebpackPlugin({
template: './src/index.html',
hash: true, //会在打包好的bundle.js后面加上hash串
}),
new CleanWebpackPlugin(), //打包编译前先清空dist之前生成的文件
],
module:{
rules:[
{
test:/\.(jsx|js)$/,
exclude:/(node_modules)/, //排除掉nod_modules,优化打包速度
use:{
loader:'babel-loader'
}
},
{
test:/\.(png|jpg|gif|webp)$/,
use:[
"url-loader"
]
},
{
test:/\.(scss|css)$/,
use:[
"style-loader",
"css-loader",
"sass-loader"
]
},
{
test: /\.(ttf|eot|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/,
include: [path.join(__dirname, "src/asset")],
loader: "file-loader?name=assets/[name].[ext]"
}
]
}
};