-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
129 lines (126 loc) · 3.19 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-env node */
const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const ManifestPlugin = require('webpack-manifest-plugin');
const nodeExternals = require('webpack-node-externals');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const env = require('env-var');
const { getAssetUrl } = require('@uc/deploy-assets');
const USE_CDN = env.get('DEPLOY_TAG', '').asString();
const vendorChunks = [];
module.exports = (_, argv) => {
const { mode } = argv;
const output = {
path: path.resolve(__dirname, 'dist'),
libraryTarget: 'umd',
};
const babelLoader = {
test: /\.(js|tsx|ts)$/,
loader: 'babel-loader',
include: [path.resolve(__dirname, 'src')],
exclude: /node_modules/,
};
const rawLoader = {
test: /\.svg$/,
loader: 'raw-loader',
};
const resolve = {
extensions: ['.ts', '.tsx', '.js', '.mjs', '.json'],
alias: {
'@': path.resolve(__dirname, 'src'),
},
};
return [
{
mode,
devtool: 'source-map',
entry: {
client: [path.resolve(__dirname, 'src/client/index.tsx')],
},
output: {
...output,
filename: mode === 'production' ? '[name].[chunkhash:8].js' : '[name].[hash:8].js',
publicPath: USE_CDN ? getAssetUrl() + '/' : '/video-generator/static/',
},
plugins: [
new CleanWebpackPlugin(['dist']),
new ManifestPlugin({
path: '',
writeToFileEmit: true,
filename: 'manifest.json',
}),
],
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: (module) =>
module.resource &&
module.resource.includes('node_modules') &&
vendorChunks.every((chunk) => !module.resource.includes(chunk)),
name: 'vendor',
chunks: 'all',
},
},
},
},
resolve,
module: {
rules: [
babelLoader,
rawLoader,
...(mode === 'development'
? [
{
test: /\.js$/,
use: ['source-map-loader'],
enforce: 'pre',
},
]
: []),
],
},
},
{
mode,
entry: {
server: path.join(__dirname, 'src/server/index.ts'),
},
output: {
...output,
filename: 'server.js',
},
plugins: [new ForkTsCheckerWebpackPlugin()],
target: 'node',
externals: [
nodeExternals({
whitelist: [/\.mjs$/i],
}),
],
resolve,
module: {
rules: [
{
...babelLoader,
options: {
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
'@babel/preset-react',
'@babel/preset-typescript',
],
},
},
rawLoader,
],
},
},
];
};