-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwebpack.worker.config.js
More file actions
116 lines (113 loc) · 2.84 KB
/
webpack.worker.config.js
File metadata and controls
116 lines (113 loc) · 2.84 KB
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
const ESLintWebpackPlugin = require('eslint-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const { DefinePlugin } = require('webpack');
const path = require('path');
const babelConfig = require('./babel-config.worker.js');
const packageJson = require('./package.json');
const jsConfig = require('./jsconfig.json');
const rootPath = path.resolve(__dirname, 'module', 'worker');
const sourcePath = path.resolve(rootPath, 'src');
const buildPath = path.resolve(rootPath, '..', '..', 'build');
const buildMode = process.env.NODE_ENV || 'production';
const isDev = buildMode === 'development';
const getResolveAliasFromJsConfig = () => {
return Object.entries(jsConfig.compilerOptions.paths).reduce((acc, [key, value]) => {
const transformedKey = key.replace('/*', '');
const paths = path.resolve(__dirname, value[0].replace('/*', ''));
return { ...acc, [transformedKey]: paths };
}, {});
};
module.exports = {
entry: path.resolve(sourcePath, 'worker.js'),
output: {
path: path.resolve(buildPath),
filename: `js/[name].worker.bundle.js`,
chunkFilename: `js/[name].worker.bundle.chunk.js`,
assetModuleFilename: `media/[name].worker.[hash][ext]`,
},
mode: buildMode,
devtool: isDev ? 'source-map' : undefined,
target: 'webworker',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: require.resolve('babel-loader'),
options: { ...babelConfig },
},
},
],
},
plugins: [
new ESLintWebpackPlugin({
extensions: ['.js'],
emitWarning: false,
cache: false,
}),
new DefinePlugin({
grammar: {
VERSION: `'v${packageJson.grammarVersion}'`,
},
}),
],
optimization: {
minimize: !isDev,
minimizer: [
new TerserPlugin({
terserOptions: {
parse: {
ecma: 2020,
},
compress: {
ecma: 5,
comparisons: false,
inline: 2,
},
mangle: {
safari10: true,
},
output: {
ecma: 5,
comments: false,
ascii_only: true,
},
},
}),
],
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
minSize: 0,
maxSize: 2000000,
cacheGroups: {
common: {
test: /[\\/]node_modules[\\/]/,
name: 'commons',
priority: -10,
enforce: true,
reuseExistingChunk: true,
},
},
},
},
resolve: {
alias: getResolveAliasFromJsConfig(),
extensions: ['.js'],
fallback: {
'reflect-metadata': false,
},
},
stats: {
warnings: true,
},
devServer: {
static: {
directory: path.resolve(buildPath),
},
compress: false,
port: 4001,
liveReload: true,
},
};