checkout/config/webpack.prod.js
2022-01-24 14:38:04 +03:00

54 lines
2.0 KiB
JavaScript

const webpack = require('webpack');
const merge = require('webpack-merge');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const CompressionPlugin = require('compression-webpack-plugin');
const checkoutConfig = require('./checkout-config');
const initializerConfig = require('./initializer-config');
const samsungPayConfig = require('./samsung-pay-config');
const prepareOutputConfig = require('./prepare-output-config');
const commonConfig = require('./common-config');
const SentryWebpackPlugin = require('@sentry/webpack-plugin');
const commonProdConfig = {
plugins: [
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
}),
new BundleAnalyzerPlugin({
analyzerMode: 'disabled'
}),
new CompressionPlugin({
filename: '[path].gz[query]',
algorithm: 'gzip',
test: /\.js$|\.css$|\.html$|\.json$/,
threshold: 10240,
minRatio: 0.8
}),
...(process.env.SENTRY_AUTH_TOKEN
? [
new SentryWebpackPlugin({
authToken: process.env.SENTRY_AUTH_TOKEN,
org: 'vality',
project: 'checkout',
include: './dist',
ignore: ['node_modules', 'webpack.config.js']
})
]
: [])
]
};
const baseOutput = 'dist';
const prepareModule = (env, baseConfig, outputPath, jsPattern, cssPattern) =>
merge(baseConfig, commonConfig(env), prepareOutputConfig(outputPath, jsPattern, cssPattern), commonProdConfig);
module.exports = (env, { mode }) => [
prepareModule(mode, checkoutConfig, `${baseOutput}/v1`, '[name].[hash:20]', '[hash:20]'),
prepareModule(mode, samsungPayConfig, `${baseOutput}/v1`, '[name].[hash:20]', '[hash:20]'),
prepareModule(mode, initializerConfig, baseOutput)
];