-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
115 lines (114 loc) · 2.9 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
const path = require('path');
const webpack = require('webpack');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const HTMLWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserWebpackPlugin = require('terser-webpack-plugin');
const ScriptExtHTMLWebpackPlugin = require('script-ext-html-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
module.exports = {
mode: 'production',
devtool: 'source-map',
// mode: 'development',
// devtool: 'inline-source-map',
entry: {
demo1: './src/js/index.js',
},
output: {
filename: '[name].[contenthash].js',
chunkFilename: '[name].[contenthash].js',
path: path.resolve(__dirname, 'docs'),
},
module: {
rules: [
{
test: /\.js$/,
include: [
path.resolve(__dirname, 'src/js'),
],
use: {
loader: 'babel-loader',
options: {
plugins: ['@babel/plugin-syntax-dynamic-import'],
presets: [
[
'@babel/preset-env',
{
'useBuiltIns': 'usage',
'corejs': '3.1.3',
},
],
],
cacheDirectory: true,
},
},
},
{
test: /\.(sa|sc|c)ss$/,
loaders: [
MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader',
],
},
],
},
optimization: {
minimizer: [
new TerserWebpackPlugin({
parallel: true,
sourceMap: true,
}),
new OptimizeCSSAssetsPlugin({}),
],
runtimeChunk: 'single',
splitChunks: {
chunks: 'all',
},
},
plugins: [
new CleanWebpackPlugin({ cleanOnceBeforeBuildPatterns: [
'**/*',
'!demo1.min.js',
'!demo2.min.js',
'!demo3a.min.js',
'!demo3b.min.js',
'!demo3c.min.js',
'!demo3d.min.js',
'!demo4.min.js',
] }),
new MiniCssExtractPlugin({
filename: '[name].[contenthash].css',
chunkFilename: '[name].[contenthash].css',
}),
new HTMLWebpackPlugin({
template: './src/html/index1.html',
title: 'CSS Paint Demo 1',
filename: 'demo1.html',
}),
new HTMLWebpackPlugin({
template: './src/html/index2.html',
title: 'CSS Paint Demo 2',
filename: 'demo2.html',
}),
new HTMLWebpackPlugin({
template: './src/html/index3.html',
title: 'CSS Paint Demo 3',
filename: 'demo3.html',
}),
new HTMLWebpackPlugin({
template: './src/html/index4.html',
title: 'CSS Paint Demo 4',
filename: 'demo4.html',
}),
new ScriptExtHTMLWebpackPlugin({
defaultAttribute: 'async',
}),
new webpack.HashedModuleIdsPlugin(),
],
devServer: {
port: 3001,
contentBase: path.join(__dirname, 'docs'),
index: 'index.html',
},
};