-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
107 lines (102 loc) · 2.38 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
/* eslint-disable import/no-commonjs, import/no-nodejs-modules */
const path = require('path')
const CompressionPlugin = require('compression-webpack-plugin')
const BrotliPlugin = require('brotli-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const StatsPlugin = require('stats-webpack-plugin')
const shouldCompress = /\.(js|css|html|svg)(\.map)?$/
// eslint-disable-next-line import/no-commonjs
module.exports = function(env, argv) {
const babelLoaderOptions = {}
if (argv.mode !== 'production') {
// minimal transpiling for easier debugging in development
babelLoaderOptions.options = {
presets: [
[
'@babel/preset-env',
{
useBuiltIns: 'usage',
corejs: 3,
targets: { browsers: 'last 1 Chrome versions' },
},
],
],
plugins: [
['@babel/plugin-proposal-object-rest-spread', { useBuiltIns: true }],
['@babel/plugin-syntax-decorators', { legacy: true }],
['@babel/plugin-proposal-decorators', { legacy: true }],
['@babel/plugin-proposal-class-properties', { loose: true }],
// 'babel-plugin-espower',
],
}
}
const config = {
entry: {
[require('./package.json').name]: '.',
},
mode: argv.mode,
output: {
filename: '[name].js',
chunkFilename: '[name].js',
},
node: {
fs: 'empty',
net: 'empty',
tls: 'empty',
},
resolve: {
symlinks: false,
},
plugins: [
new CleanWebpackPlugin(),
new StatsPlugin('stats.json', {
chunkModules: true,
}),
],
module: {
rules: [
{
test: /\.js$/,
include: [
path.resolve(__dirname, 'src'),
path.resolve(__dirname, 'node_modules', 'olm'),
],
loader: 'babel-loader',
...babelLoaderOptions,
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
],
},
// // kiwi's plugin loader doesn't work with split chunks
// optimization: {
// splitChunks: {
// chunks: 'all',
// },
// },
devtool: 'source-map',
devServer: {
filename: 'plugin-olm.js',
host: process.env.HOST || 'localhost',
port: process.env.PORT || 53080,
},
}
if (argv.mode === 'production') {
config.plugins = [
...config.plugins,
new CompressionPlugin({
test: shouldCompress,
}),
new BrotliPlugin({
asset: '[path].br[query]',
test: shouldCompress,
threshold: 10240,
minRatio: 0.8,
deleteOriginalAssets: false,
}),
]
}
return config
}