-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwebpack.prod.config.ts
186 lines (183 loc) · 5.14 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import * as CopyWebpackPlugin from 'copy-webpack-plugin';
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 CopyWebpackPlugin({
patterns: [{
from: 'env.js',
to: 'assets/env.js',
transform: (content: Buffer, path: string) => {
return `
window.env = {
DEPLOY_ENV: ${JSON.stringify(process.env.DEPLOY_ENV)},
APP_VERSION: ${JSON.stringify(process.env.APP_VERSION)},
APP_SECRET: ${JSON.stringify(process.env.APP_SECRET)},
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: 'BuildPipeline | 603.nz',
template: path.join(__dirname, 'src', 'index.ejs'),
favicon: path.join(__dirname, 'src', 'favicon.ico'),
meta: {
description: 'AWS-powered serverless build, test and deploy pipeline ft. multiple environments',
},
minify: {
collapseWhitespace: true,
},
}),
new InlineManifestWebpackPlugin(),
new ForkTsCheckerWebpackPlugin({
async: false,
}),
],
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?$/,
enforce: 'pre',
include: path.join(__dirname, 'src'),
exclude: path.join(__dirname, 'node_modules'),
use: {
loader: 'tslint-loader',
options: {
emitErrors: true,
failOnHint: false,
},
},
},
{
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;