-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.cjs
140 lines (135 loc) · 2.5 KB
/
webpack.config.cjs
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
/* eslint-disable @typescript-eslint/no-var-requires */
/* global require, module, __dirname */
const TerserPlugin = require('terser-webpack-plugin')
const {
optimize: { LimitChunkCountPlugin },
IgnorePlugin,
DefinePlugin,
} = require('webpack')
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
const CopyPlugin = require('copy-webpack-plugin')
const fs = require('fs')
const path = require('path')
const sourceRoot = path.normalize(__dirname + '/src')
const babelConfig = {
presets: [
[
'@babel/preset-env',
{
targets: {
esmodules: true,
},
},
],
'@babel/preset-typescript',
],
sourceType: 'module',
}
const main = {
mode: 'production',
devtool: 'source-map',
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
include: ['main.cjs', 'migrate.cjs'],
}),
],
},
resolve: {
extensions: ['.js', '.ts'],
extensionAlias: {
'.js': ['.ts', '.js'],
},
},
target: 'node',
experiments: {
topLevelAwait: true,
},
module: {
rules: [
{
test: /\.(j|t)s$/,
include: [sourceRoot],
exclude: __dirname + '/node_modules',
use: {
loader: 'babel-loader',
options: babelConfig,
},
},
],
},
externals: {
'bufferutil': false,
'utf-8-validate': false,
'argon2': 'argon2',
},
externalsType: 'node-commonjs',
externalsPresets: {
node: true,
},
}
const commonPlugins = [
new IgnorePlugin({
checkResource: res => res === 'utf-8-validate',
}),
new LimitChunkCountPlugin({
maxChunks: 1,
}),
new ForkTsCheckerWebpackPlugin({
typescript: {
diagnosticOptions: {
semantic: true,
syntactic: true,
},
mode: 'write-references',
},
}),
]
module.exports = [
{
...main,
entry: {
main: __dirname + '/src/index.ts',
},
output: {
filename: 'main.cjs',
path: __dirname + '/dist',
},
plugins: [
...commonPlugins,
new DefinePlugin({
'process.env.WS_NO_BUFFER_UTIL': true,
}),
new CopyPlugin({
patterns: [
{ from: __dirname + '/package.json' },
{ from: __dirname + '/package-lock.json' },
...(fs.existsSync(__dirname + '/.env.local')
? [{ from: __dirname + '/.env.local' }]
: []),
],
}),
],
},
{
...main,
entry: {
migrate: __dirname + '/src/migrate.ts',
},
output: {
filename: 'migrate.cjs',
path: __dirname + '/dist/db',
},
externals: {
...main.externals,
'node:module': false,
},
plugins: [
...commonPlugins,
new CopyPlugin({
patterns: [{ from: __dirname + '/db' }],
}),
],
},
]