-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.config.js
More file actions
76 lines (72 loc) · 1.92 KB
/
webpack.config.js
File metadata and controls
76 lines (72 loc) · 1.92 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
/* eslint-disable no-console, node/no-unpublished-require */
const path = require('path');
const webpack = require('webpack');
const WebpackManifestPlugin = require('webpack-manifest-plugin');
const WebpackBundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
module.exports = (env, argv) => {
const isProd = argv.mode === 'production';
const config = {
entry: {
index: path.resolve('src', 'client', 'index.tsx'),
},
output: {
filename: '[name].[contenthash].bundle.js',
chunkFilename: '[name].[contenthash].chunk.js',
path: path.resolve('dist', 'public'),
publicPath: '/public/',
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
plugins: [
new TsconfigPathsPlugin({
configFile: './tsconfig.client.json',
}),
],
},
plugins: [
new webpack.DefinePlugin({
'process.env': JSON.stringify({
NODE_ENV: process.env.NODE_ENV,
}),
}),
new WebpackManifestPlugin(),
],
optimization: {
minimize: isProd,
splitChunks: {
minSize: 100000,
maxSize: 1500000,
name: 'dist/public/commons',
chunks: 'all',
cacheGroups: {
vendors: {
test: /node_modules/,
name: 'vendors',
chunks: 'all',
enforce: true,
},
},
},
},
module: {
rules: [
{
test: /\.tsx?$/,
use: {
loader: 'ts-loader',
options: {
configFile: 'tsconfig.client.json',
},
},
},
],
},
devtool: isProd ? null : 'inline-source-map',
};
if (process.env.ANALYSIS === 'true') {
console.log(`Building for analyze...`);
config.plugins.push(new WebpackBundleAnalyzerPlugin());
}
return config;
};