-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.base.js
71 lines (69 loc) · 1.9 KB
/
webpack.base.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
const path = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin') // css指纹.
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin') // 优化打包日志.
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin') // 缓存.
// Notice me! please use image-webpack-plugin to minify images' size.
module.exports = {
resolve: {
alias: {
react: path.resolve(__dirname, './node_modules/react/umd/react.production.min.js'),
'react-dom': path.resolve(__dirname, './node_modules/react-dom/umd/react-dom.production.min.js')
},
extensions: ['.js', '.jsx'] // 引入此类型文件时, 省略文件后缀名.
},
devtool: 'source-map', // 开启以后可以根据源码调试.
mode: 'production',
module: {
rules: [
{
test: /(.js|.jsx)$/,
use: [
{
loader: 'thread-loader', // 多进程打包, 加快打包速度.
options: {
workers: 3
}
},
'babel-loader',
'eslint-loader'
],
exclude: path.join(__dirname, './node_modules')
},
{
test: /.css$/,
use: [
'style-loader',
MiniCssExtractPlugin.loader,
'css-loader'
]
},
{
test: /.less$/,
use: [
'style-loader',
MiniCssExtractPlugin.loader,
'css-loader',
'less-loader'
]
},
{
test: /\.(jpg|png|gif|jpeg)$/,
use: 'file-loader'
// options: {
// name: 'img/[name][hash:8].[ext]'
// }
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: 'file-loader'
}
]
},
plugins: [
new MiniCssExtractPlugin({
filename: './css/[name]_[contenthash:8].css' // css output file.
}),
new FriendlyErrorsWebpackPlugin(),
new HardSourceWebpackPlugin()
]
}