-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.ts
46 lines (43 loc) · 1.45 KB
/
webpack.config.ts
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
import { Configuration } from 'webpack'
import { resolve } from 'path'
import TerserPlugin from 'terser-webpack-plugin'
const isProdBuild: boolean = process.env.NODE_ENV === 'production'
const buildSuffix: string = isProdBuild ? 'prod' : 'dev'
const config: Configuration = {
entry: './src/server.ts',
mode: isProdBuild ? 'production' : 'development',
// We want to make sure we're not adding anything we don't need like browser libraries
target: 'async-node',
output: {
path: resolve(__dirname, 'build'),
filename: `[name].${buildSuffix}.js`,
publicPath: '/',
// we need to target CommonJS, otherwise node cannot execute file
libraryTarget: 'commonjs2',
},
resolve: {
roots: [__dirname],
extensions: ['.ts', '.js', '.json'],
alias: {
'~': resolve('src/'),
},
},
module: {
rules: [{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/,
}],
},
// Do not generate LICENCE file
// https://github.com/webpack-contrib/terser-webpack-plugin/issues/229#issuecomment-761294644
optimization: {
minimizer: [new TerserPlugin({ extractComments: false })],
},
// we better bundle everything into 1 script file to ease docker image creation, thus commented out below
// cannot use optimize.LimitChunkCountPlugin because of https://stackoverflow.com/a/73318866/2848264
externals: [
isProdBuild ? {} : /^[a-z\-0-9]+$/, // Ignore node_modules folder
],
}
export default config