This repository has been archived by the owner on Oct 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
148 lines (137 loc) · 3.08 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
const webpack = require('webpack')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CopyPlugin = require('copy-webpack-plugin')
const { pages, entries } = require('./webpack.pages.js')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const TerserPlugin = require('terser-webpack-plugin')
module.exports = {
mode: 'development',
entry: entries,
plugins: [
new webpack.ProgressPlugin(),
new webpack.EnvironmentPlugin({
ytAPIToken: ''
}),
new CopyPlugin([
{ from: './src/assets', to: 'assets' }
]),
new HtmlWebpackPlugin({
template: 'src/views/index.pug',
filename: 'index.html'
})
],
module: {
rules: [
{
test: /\.pug$/,
use: 'pug-loader'
},
{
test: /\.(png|jpg|gif)$/,
loader: 'file-loader',
options: {
outputPath: 'assets/others',
publicPath: '/assets/others'
}
},
{
test: /\.css$/,
use: [
{
loader: MiniCssExtractPlugin.loader
},
{
loader: 'css-loader',
options: {
sourceMap: true
}
}
]
},
{
test: /\.s(?:a|c)ss$/,
use: [
{
loader: MiniCssExtractPlugin.loader
},
{
loader: 'css-loader',
options: {
sourceMap: true
}
},
{
loader: 'sass-loader',
options: {
sourceMap: true
}
}
]
},
{
test: /\.woff(2|)$/,
loader: 'file-loader',
options: {
outputPath: 'assets/others',
publicPath: '/assets/others'
}
}
]
},
optimization: {
minimizer: [
new TerserPlugin({
terserOptions: {
ecma: '2017'
}
})
],
splitChunks: {
cacheGroups: {
vendors: {
priority: -10,
test: /[\\/]node_modules[\\/]/
}
},
chunks: 'async',
minChunks: 1,
minSize: 30000,
name: true
}
},
output: {
filename: 'assets/js/[name].[chunkhash].js'
},
devServer: {
port: 50000,
compress: true,
publicPath: '/'
}
}
pages.forEach(e => {
module.exports.plugins.push(
new HtmlWebpackPlugin({
template: `src/views/${e.page}.pug`,
filename: `${e.page}.html`,
chunks: [
// CSS 檔案。預設引入。
'css',
// 在新分頁開啟。預設引入。
'blank',
// 清除追蹤 query。預設引入。
'cleanupQueries',
// 開頭列 JS。預設引入。
'header',
// 延後載入 JS。預設引入。
'lazyload',
// 回到 TOP 的 JS。預設引入。
'top'
].concat(e.chunks)
})
)
})
module.exports.plugins = module.exports.plugins.concat([
new MiniCssExtractPlugin({ filename: 'assets/css/[name].[chunkhash].css' }),
new CleanWebpackPlugin()
])