-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.prod.js
79 lines (77 loc) · 1.81 KB
/
webpack.prod.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
/* eslint-disable @typescript-eslint/no-var-requires */
const TerserWebpackPlugin = require('terser-webpack-plugin')
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
const { merge } = require('webpack-merge')
const path = require('path')
const nodeExternals = require('webpack-node-externals')
require('@babel/register')
const makeConfig = (envName, config) =>
merge(
{
resolve: {
modules: ['./node_modules'],
extensions: ['*', '.js', '.jsx', '.ts', '.tsx'],
},
mode: 'production',
devtool: 'source-map',
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
envName,
},
},
},
],
},
optimization: {
minimize: true,
minimizer: [
new TerserWebpackPlugin({
terserOptions: {
ecma: 2015,
},
}),
],
},
stats: 'minimal',
},
config
)
module.exports = [
makeConfig('browser', {
entry: {
bundle: ['./src/client/client.tsx'],
},
output: {
filename: '[name].[contenthash:8].js',
path: path.join(__dirname, 'dist/client'),
},
plugins: [
new BundleAnalyzerPlugin({
analyzerMode: 'disabled',
generateStatsFile: true,
statsFilename: '../stats.json',
statsOptions: {
all: false,
assets: true,
},
}),
],
}),
makeConfig('server', {
entry: {
server: ['./src/server/server.ts'],
},
output: {
filename: '[name].js',
path: path.join(__dirname, 'dist/server'),
},
externalsPresets: { node: true },
externals: [nodeExternals()],
}),
]