-
Notifications
You must be signed in to change notification settings - Fork 51
/
webpack.common.js
108 lines (105 loc) · 2.76 KB
/
webpack.common.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
98
99
100
101
102
103
104
105
106
107
108
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const AntdDayjsWebpackPlugin = require('antd-dayjs-webpack-plugin');
const os = require('os');
const HappyPack = require('happypack');
const happyThreadPool = HappyPack.ThreadPool({ size: os.cpus().length });
const srcDir = path.join(__dirname, '../src');
const devMode = process.env.NODE_ENV !== 'production';
module.exports = {
entry: {
main: path.join(__dirname, '../src/main.js'),
},
output: {
path: path.join(__dirname, '../dist'),
filename: '[name].[chunkhash:8].js',
// publicPath: "/",
chunkFilename: 'chunk/[name].[chunkhash:8].js',
},
module: {
rules: [
// {
// test: /\.(js|jsx)$/,
// include: [srcDir],
// loader: 'eslint-loader',
// enforce: 'pre',
// options: {
// fix: true,
// },
// },
{
test: /\.(js|jsx)$/,
include: [srcDir],
exclude: /(node_modules|bower_components)/,
use: ['happypack/loader?id=happybabel'],
},
{
test: /\.less$/,
use: [
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
'less-loader',
],
},
{
test: /\.css$/,
use: [
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
],
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
use: ['url-loader'],
include: [srcDir],
},
{
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
use: ['url-loader'],
include: [srcDir],
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
use: ['url-loader'],
include: [srcDir],
},
],
},
plugins: [
// 开启 happypack 的线程池
new HappyPack({
id: 'happybabel',
loaders: ['babel-loader?cacheDirectory=true'],
threadPool: happyThreadPool,
// cache: true,
verbose: true,
}),
new HtmlWebpackPlugin({
template: `${srcDir}/index.html`,
}),
new CopyWebpackPlugin({
patterns: [
{
from: `${srcDir}/assets/images/nowthen.jpg`,
to: 'nowthen.jpg',
},
],
}),
new AntdDayjsWebpackPlugin()
],
resolve: {
alias: {
'@': srcDir,
'@pages': `${srcDir}/pages`,
},
},
// optimization: {
// removeAvailableModules: true, // 删除已解决的chunk (默认 true)
// removeEmptyChunks: true, // 删除空的chunks (默认 true)
// mergeDuplicateChunks: true // 合并重复的chunk (默认 true)
// }
};