-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.prod.js
85 lines (81 loc) · 2.32 KB
/
webpack.config.prod.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
/**
* @author [email protected]
* @date 2017/8/22
*/
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
module.exports = {
entry: [
'./src/index.js'
],
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
},
module: {
rules: [
//JS和JSX加载
{
test: /\.jsx?$/,
use: {
loader: 'babel-loader'
},
exclude: /(node_modules|bower_components)/
},
//css加载
{
test: /\.css$/,
use: [ 'style-loader', 'css-loader' ],
include: path.resolve('./src')
},
//图片文件加载
{
test: /\.png|jpe?g|gif|svg(\?.*)?/,
use: {
loader: "url-loader",//引用图片的格式,通过query来指定
query: {
name: 'img/[name].[hash:4].[ext]',
limit: 1000 //小于这个则会通过dataURI引用
}
},
include: path.resolve('./src')
},
//音频视频文件加载
{
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
use: {
loader: 'url-loader',
options: {
name: 'media/[name].[hash:4].[ext]'
}
}
},
//字体加载
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
use: {
loader: 'url-loader',
options: {
name: 'fonts/[name].[hash:4].[ext]'
}
}
}
]
},
plugins: [
new HtmlWebpackPlugin({template: './src/index.template.html'}),
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("development")
}
}),
],
devServer: {
hot: true, //打开 HMR
contentBase: path.join(__dirname, "dist"),
compress: true,
port: 9000
}
};