-
Notifications
You must be signed in to change notification settings - Fork 20
/
webpack.prod.config.ts
162 lines (159 loc) · 4.4 KB
/
webpack.prod.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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import * as HtmlWebpackPlugin from 'html-webpack-plugin';
import * as InlineManifestWebpackPlugin from 'inline-manifest-webpack-plugin';
import * as MiniCssExtractPlugin from 'mini-css-extract-plugin';
import * as OptimizeCssAssetsPlugin from 'optimize-css-assets-webpack-plugin';
import * as path from 'path';
import * as TerserPlugin from 'terser-webpack-plugin';
import * as webpack from 'webpack';
import * as WebpackChunkHash from 'webpack-chunk-hash';
import ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const config: webpack.Configuration = {
mode: 'production',
entry: [
path.join(__dirname, 'src', 'index.tsx'),
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'assets/[name].[contenthash].js',
chunkFilename: 'assets/[name].[contenthash].js',
publicPath: '/',
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
AUTH0_CLIENT_ID: JSON.stringify(process.env.AUTH0_CLIENT_ID),
AUTH0_DOMAIN: JSON.stringify(process.env.AUTH0_DOMAIN),
GA_ID: JSON.stringify(process.env.GA_ID),
},
}),
new webpack.ContextReplacementPlugin(/moment[/\\]locale$/, /en/),
new WebpackChunkHash(),
new MiniCssExtractPlugin({
filename: 'assets/[name].[contenthash].css',
ignoreOrder: true,
}),
new HtmlWebpackPlugin({
title: 'Starter Pack | 603.nz',
template: path.join(__dirname, 'src', 'index.ejs'),
favicon: path.join(__dirname, 'src', 'favicon.ico'),
meta: [
{
name: 'description',
content: 'React + Redux + Auth0',
},
],
minify: {
collapseWhitespace: true,
},
}),
new InlineManifestWebpackPlugin(),
new ForkTsCheckerWebpackPlugin({
async: false,
eslint: {
files: './src/**/*.{ts,tsx,js,jsx}', // required - same as command `eslint ./src/**/*.{ts,tsx,js,jsx} --ext .ts,.tsx,.js,.jsx`
},
}),
],
optimization: {
runtimeChunk: 'single',
moduleIds: 'hashed',
chunkIds: 'named',
minimizer: [
new OptimizeCssAssetsPlugin({
cssProcessorOptions: { safe: true, discardComments: { removeAll: true } },
canPrint: false,
}),
new TerserPlugin({
parallel: true,
terserOptions: {
mangle: {
safari10: true,
},
},
}),
],
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
cacheGroups: {
default: false,
vendor: {
name: 'vendor',
chunks: 'all',
test: /[\\/]node_modules[\\/]/,
priority: 20,
},
utilities: {
test: /[\\/]node_modules[\\/](immutable|moment|react|react-dom|react-loading)[\\/]/,
name: 'utilities',
priority: 30,
},
common: {
name: 'async-common',
minChunks: 2,
chunks: 'async',
priority: 10,
reuseExistingChunk: true,
enforce: true,
},
// See: https://github.com/webpack-contrib/mini-css-extract-plugin/issues/85
styles: {
name: 'styles',
test: module => module.nameForCondition && /\.css$/.test(module.nameForCondition()) && !/^javascript/.test(module.type),
chunks: 'all',
enforce: true,
},
},
},
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.css', '.json'],
modules: [
path.join(__dirname, 'src'),
path.join(__dirname, 'node_modules'),
],
},
module: {
rules: [
{
test: /\.tsx?$/,
include: path.join(__dirname, 'src'),
use: [{
loader: 'ts-loader',
options: {
transpileOnly: true,
experimentalWatchApi: true,
},
}],
},
{
test: /\.css?$/,
include: path.join(__dirname, 'src'),
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
modules: {
mode: 'local',
localIdentName: '[hash:base64:5]',
},
},
},
],
},
{
test: /\.(jpe?g|png|gif|svg|ico)$/,
include: path.join(__dirname, 'src'),
use: [{
loader: 'url-loader',
options: {
limit: 10240,
esModule: false,
},
}],
},
],
},
};
export default config;