2020-03-31 05:12:46 -04:00
|
|
|
const fs = require('fs')
|
2018-03-13 07:19:30 -04:00
|
|
|
const merge = require('webpack-merge')
|
2019-11-28 05:20:22 -05:00
|
|
|
const TerserPlugin = require('terser-webpack-plugin')
|
|
|
|
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
|
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
2020-03-31 05:12:46 -04:00
|
|
|
const SentryPlugin = require('@sentry/webpack-plugin')
|
|
|
|
const RemoveFilesPlugin = require('remove-files-webpack-plugin')
|
2018-03-13 07:19:30 -04:00
|
|
|
|
|
|
|
const base = require('./webpack.config')
|
|
|
|
|
2020-01-29 05:25:33 -05:00
|
|
|
// Use "smart" merge: attempts to combine loaders targeting the same file type,
|
|
|
|
// overriding the base config
|
2020-03-31 05:12:46 -04:00
|
|
|
module.exports = merge.smart(
|
|
|
|
base,
|
|
|
|
{
|
|
|
|
mode: 'production',
|
2019-08-06 08:20:02 -04:00
|
|
|
|
2020-03-31 05:12:46 -04:00
|
|
|
// Enable a full source map. Generates a comment linking to the source map
|
2020-04-08 04:35:01 -04:00
|
|
|
devtool: 'hidden-source-map',
|
2018-03-13 07:19:30 -04:00
|
|
|
|
2020-03-31 05:12:46 -04:00
|
|
|
output: {
|
|
|
|
// Override filename to include hash for immutable caching
|
|
|
|
filename: 'js/[name]-[chunkhash].js'
|
|
|
|
},
|
2019-11-28 05:20:22 -05:00
|
|
|
|
2020-03-31 05:12:46 -04:00
|
|
|
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]'
|
|
|
|
}
|
2020-01-29 05:25:33 -05:00
|
|
|
}
|
2020-03-31 05:12:46 -04:00
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
|
|
|
|
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'
|
|
|
|
})
|
2020-01-29 05:25:33 -05:00
|
|
|
]
|
|
|
|
},
|
2020-03-31 05:12:46 -04:00
|
|
|
// Conditionally merge in Sentry plugins
|
|
|
|
generateSentryConfig()
|
|
|
|
)
|
2020-01-29 05:25:33 -05:00
|
|
|
|
2020-03-31 05:12:46 -04:00
|
|
|
/*
|
|
|
|
* 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']
|
|
|
|
}),
|
2019-11-28 05:20:22 -05:00
|
|
|
|
2020-03-31 05:12:46 -04:00
|
|
|
// 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 {}
|
|
|
|
}
|
|
|
|
}
|