-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwebpack.prod.ts
142 lines (132 loc) · 3.51 KB
/
webpack.prod.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
/* eslint-disable no-magic-numbers, no-console */
/*
* Webpack distribution configuration
*
* This file is set up for serving the distribution version. It will be compiled to dist/ by default
*/
import SentryCliPlugin from '@sentry/webpack-plugin';
import CopyPlugin from 'copy-webpack-plugin';
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
import dotenv from 'dotenv';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import TerserPlugin from 'terser-webpack-plugin';
import webpack from 'webpack';
import WebpackBundleAnalyzer from 'webpack-bundle-analyzer';
import merge from 'webpack-merge';
import common from './webpack.common';
const envFileVars = dotenv.config().parsed;
const {
SENTRY_UPLOAD_SOURCEMAPS,
SENTRY_API_KEY,
SENTRY_RELEASE_VERSION,
HAPPA_ANALYZE_BUNDLE,
} = Object.assign(
{
SENTRY_UPLOAD_SOURCEMAPS: 'false',
SENTRY_API_KEY: '',
SENTRY_RELEASE_VERSION: 'happa@development',
HAPPA_ANALYZE_BUNDLE: 'false',
},
envFileVars,
process.env
);
const plugins: webpack.WebpackPluginInstance[] = [
new webpack.SourceMapDevToolPlugin({
filename: '[file].map[query]',
append: '//# sourceMappingURL=[url]',
}),
new MiniCssExtractPlugin({
filename: 'assets/[name].[chunkhash:12].css',
chunkFilename: 'assets/[id].[chunkhash:12].css',
}) as unknown as webpack.WebpackPluginInstance,
new CopyPlugin({
patterns: [
{ from: 'src/metadata.json', to: 'metadata.json' },
{
from: 'src/images',
globOptions: {
ignore: ['**/*.sketch'],
},
to: 'images',
},
],
}) as unknown as webpack.WebpackPluginInstance,
];
if (SENTRY_UPLOAD_SOURCEMAPS.toLowerCase() === 'true') {
plugins.push(
new SentryCliPlugin({
include: './dist/assets',
authToken: SENTRY_API_KEY,
ignore: ['./dist/assets/images/index.js', '**/*.css.map'],
org: 'giantswarm',
project: 'happa',
release: SENTRY_RELEASE_VERSION,
validate: true,
urlPrefix: '~/assets/',
})
);
}
if (HAPPA_ANALYZE_BUNDLE.toLowerCase() === 'true') {
plugins.push(
new WebpackBundleAnalyzer.BundleAnalyzerPlugin() as unknown as webpack.WebpackPluginInstance
);
}
const config: webpack.Configuration = merge(common, {
mode: 'production',
devtool: false,
stats: {
colors: true,
reasons: true,
},
optimization: {
nodeEnv: 'production',
removeEmptyChunks: true,
providedExports: true,
mangleExports: 'deterministic',
mergeDuplicateChunks: true,
innerGraph: true,
concatenateModules: true,
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: 'all',
terserOptions: {
sourceMap: true,
mangle: true,
compress: true,
},
}) as unknown as webpack.WebpackPluginInstance,
new CssMinimizerPlugin() as unknown as webpack.WebpackPluginInstance,
],
moduleIds: 'deterministic',
runtimeChunk: 'single',
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
},
},
},
},
plugins,
module: {
rules: [
{
test: /\.(js|ts)(x?)$/,
exclude: /node_modules/,
use: ['babel-loader'],
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
{
test: /\.(scss|sass)$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
},
],
},
});
export default config;