From 21490b724a3b2657ca05d8f6d458825c8fa55987 Mon Sep 17 00:00:00 2001 From: ta264 Date: Mon, 9 Dec 2019 21:42:49 +0000 Subject: [PATCH] New: Option for production build with profiling --- frontend/gulp/webpack.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/frontend/gulp/webpack.js b/frontend/gulp/webpack.js index bed7f1d58..7294f22f1 100644 --- a/frontend/gulp/webpack.js +++ b/frontend/gulp/webpack.js @@ -7,17 +7,20 @@ const errorHandler = require('./helpers/errorHandler'); const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin'); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin'); +const TerserPlugin = require('terser-webpack-plugin'); const uiFolder = 'UI'; const frontendFolder = path.join(__dirname, '..'); const srcFolder = path.join(frontendFolder, 'src'); const isProduction = process.argv.indexOf('--production') > -1; +const isProfiling = isProduction && process.argv.indexOf('--profile') > -1; const distFolder = path.resolve(frontendFolder, '..', '_output', uiFolder); console.log('Source Folder:', srcFolder); console.log('Output Folder:', distFolder); console.log('isProduction:', isProduction); +console.log('isProfiling:', isProduction); const cssVarsFiles = [ '../src/Styles/Variables/colors', @@ -216,6 +219,24 @@ const config = { } }; +if (isProfiling) { + config.resolve.alias['react-dom$'] = 'react-dom/profiling'; + config.resolve.alias['scheduler/tracing'] = 'scheduler/tracing-profiling'; + + config.optimization.minimizer = [ + new TerserPlugin({ + cache: true, + parallel: true, + sourceMap: true, // Must be set to true if using source-maps in production + terserOptions: { + mangle: false, + keep_classnames: true, + keep_fnames: true + } + }) + ]; +} + gulp.task('webpack', () => { return webpackStream(config) .pipe(gulp.dest('_output/UI'));