forked from overleaf/web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.prod.js
More file actions
104 lines (95 loc) · 2.93 KB
/
webpack.config.prod.js
File metadata and controls
104 lines (95 loc) · 2.93 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
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
const fs = require('fs')
const merge = require('webpack-merge')
const TerserPlugin = require('terser-webpack-plugin')
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const SentryPlugin = require('@sentry/webpack-plugin')
const RemoveFilesPlugin = require('remove-files-webpack-plugin')
const base = require('./webpack.config')
// Use "smart" merge: attempts to combine loaders targeting the same file type,
// overriding the base config
module.exports = merge.smart(
base,
{
mode: 'production',
// Enable a full source map. Generates a comment linking to the source map
devtool: 'hidden-source-map',
output: {
// Override filename to include hash for immutable caching
filename: 'js/[name]-[chunkhash].js'
},
module: {
rules: [
{
// Override base font loading to add hash to filename so that we can
// use "immutable" caching
test: /\.(woff|woff2)$/,
use: [
{
loader: 'file-loader',
options: {
outputPath: 'fonts',
publicPath: '/fonts/',
name: '[name]-[hash].[ext]'
}
}
]
}
]
},
optimization: {
// Minify JS (with Terser) and CSS (with cssnano)
minimizer: [new TerserPlugin(), new OptimizeCssAssetsPlugin()]
},
plugins: [
// Extract CSS to a separate file (rather than inlining to a <style> tag)
new MiniCssExtractPlugin({
// Output to public/stylesheets directory and append hash for immutable
// caching
filename: 'stylesheets/[name]-[chunkhash].css'
})
]
},
// Conditionally merge in Sentry plugins
generateSentryConfig()
)
/*
* If Sentry secrets file exists, then configure SentryPlugin to upload source
* maps to Sentry
*/
function generateSentryConfig() {
// Only upload if the Sentry secrets file is available and on master branch
if (
fs.existsSync('./.sentryclirc') &&
process.env['BRANCH_NAME'] === 'master'
) {
console.log('Sentry secrets file found. Uploading source maps to Sentry')
return {
plugins: [
new SentryPlugin({
release: process.env['SENTRY_RELEASE'],
include: './public/js',
ignore: ['ace-1.4.5', 'cmaps', 'libs']
}),
// After uploading source maps to Sentry, delete them. Some of the
// source maps are of proprietary code and so we don't want to make them
// publicly available
new RemoveFilesPlugin({
after: {
test: [
{
folder: './public/js',
method: filePath => /\.map$/.test(filePath)
}
]
}
})
]
}
} else {
console.log(
'Sentry secrets file not found. NOT uploading source maps to Sentry'
)
return {}
}
}