-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpackfile.js
111 lines (108 loc) · 2.58 KB
/
webpackfile.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
const { resolve } = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackRootPlugin = require('html-webpack-root-plugin');
const TSConfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const {
APP_NAME,
SERVER_URL,
PUBLIC_CLIENT_URL,
APP_VERSION
} = process.env;
/**
* This Webpack configuration only handles bundling the client code in
* production.
*
* Changes to the dev configuration should be made in:
* webpackfile.client-dev.js
* webpackfile.server-dev.js
*/
module.exports = {
name: 'client',
mode: 'production',
entry: ['./src/client/index.tsx'],
output: {
path: resolve(__dirname, 'build/client'),
filename: 'app.js',
publicPath: '/',
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.svg'],
plugins: [
new TSConfigPathsPlugin(),
],
},
target: 'web',
module: {
rules: [
{
include: resolve(__dirname, 'src'),
test: /\.(t|j)sx?$/,
use: [
{
loader: 'ts-loader',
options: {
configFile: 'tsconfig.client.json',
happyPackMode: true,
},
},
],
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'assets/',
},
},
],
},
],
},
optimization: {
minimize: true,
minimizer: [new TerserPlugin({
sourceMap: true,
})],
noEmitOnErrors: true,
nodeEnv: 'production',
occurrenceOrder: true,
providedExports: true,
usedExports: true,
sideEffects: true,
splitChunks: {
chunks: 'all',
name: true,
minSize: 1,
minChunks: 1,
cacheGroups: {
assets: {
test: /[\\/]node_modules[\\/]/,
enforce: true,
reuseExistingChunk: true,
filename: '[name][hash].js',
},
},
},
},
plugins: [
new HtmlWebpackPlugin({
title: APP_NAME,
}),
new webpack.DefinePlugin({
'process.env.SERVER_URL': JSON.stringify(SERVER_URL),
'process.env.PUBLIC_CLIENT_URL': JSON.stringify(PUBLIC_CLIENT_URL),
'process.env.APP_VERSION': JSON.stringify(APP_VERSION),
}),
new HtmlWebpackRootPlugin(),
new webpack.optimize.ModuleConcatenationPlugin(),
],
};