-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathwebpack.common.js
130 lines (126 loc) · 4.21 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
'use strict';
const path = require('path');
const readline = require('readline');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackTagsPlugin = require('html-webpack-tags-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const {ProgressPlugin} = require('webpack');
const staticPath = path.resolve(__dirname, 'build', 'lib', 'static');
module.exports = {
entry: {
report: ['./index.jsx', './variables.css', './styles.css'],
gui: ['./gui.jsx', './variables.css', './styles.css', './gui.css']
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
fallback: {
buffer: require.resolve('buffer'),
crypto: require.resolve('crypto-browserify'),
events: require.resolve('events'),
path: require.resolve('path-browserify'),
stream: require.resolve('stream-browserify')
}
},
context: path.resolve(__dirname, 'lib', 'static'),
output: {
path: staticPath,
filename: '[name].min.js',
hotUpdateChunkFilename: '../../hot/hot-update.js',
hotUpdateMainFilename: '../../hot/hot-update.json'
},
module: {
rules: [
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader']
},
{
test: /\.less$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'less-loader']
},
{
test: /\.styl$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'stylus-loader']
},
{
test: /\.[jt]sx?$/,
use: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.(png|woff|woff2|eot|ttf|svg)$/,
type: 'asset',
parser: {
dataUrlCondition: {
maxSize: 4 * 1024 // 4kb
}
},
generator: {
filename: path.resolve(__dirname, 'lib', 'static', 'assets', '[contenthash][ext][query]')
}
}
]
},
plugins: [
new ProgressPlugin((percentage, msg, args) => {
if (percentage < 1) {
readline.clearLine(process.stdout, 0);
readline.cursorTo(process.stdout, 0);
process.stdout.write(`${Math.round(percentage * 100)}% ${msg} ${args}`);
} else {
process.stdout.write('\n');
process.stdout.write(msg);
}
}),
new MiniCssExtractPlugin({filename: '[name].min.css'}),
new ForkTsCheckerWebpackPlugin({
typescript: {
// Points to lib/static/tsconfig.json
configFile: './tsconfig.json'
}
}),
new HtmlWebpackPlugin({
title: 'HTML report',
filename: 'index.html',
template: 'template.html',
chunks: ['report']
}),
new HtmlWebpackTagsPlugin({
files: ['index.html'],
scripts: ['data.js', 'sql-wasm.js'],
append: false
}),
new HtmlWebpackPlugin({
title: 'Gui report',
filename: 'gui.html',
template: 'template.html',
chunks: ['gui']
}),
new HtmlWebpackTagsPlugin({
files: ['gui.html'],
scripts: ['sql-wasm.js'],
append: false
})
],
optimization: {
minimizer: [
new CssMinimizerPlugin(),
new TerserPlugin({
parallel: true,
terserOptions: {
output: {
comments: false
}
},
extractComments: false
})
]
},
performance: {
maxEntrypointSize: 2100000,
assetFilter: assetFilename => !['gui.min.js', 'report.min.js'].includes(assetFilename)
}
};