From 19b673e46777d8ed10abf6c6961138310c8dedec Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Thu, 5 Aug 2021 12:07:43 -0700 Subject: [PATCH] fix(webpack): use production mode in production builds (#8007) --- src/web/recorder/webpack.config.js | 6 ++++-- src/web/traceViewer/webpack.config.js | 5 +++-- utils/build/build.js | 28 +++++++++++++++++++++++---- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/web/recorder/webpack.config.js b/src/web/recorder/webpack.config.js index 41afa22f44..96c61fb25e 100644 --- a/src/web/recorder/webpack.config.js +++ b/src/web/recorder/webpack.config.js @@ -1,15 +1,17 @@ const path = require('path'); const HtmlWebPackPlugin = require('html-webpack-plugin'); +const mode = process.env.NODE_ENV === 'production' ? 'production' : 'development'; + module.exports = { - mode: process.env.NODE_ENV === 'production' ? 'production' : 'development', + mode, entry: { app: path.join(__dirname, 'index.tsx'), }, resolve: { extensions: ['.ts', '.js', '.tsx', '.jsx'] }, - devtool: 'source-map', + devtool: mode === 'production' ? false : 'source-map', output: { globalObject: 'self', filename: '[name].bundle.js', diff --git a/src/web/traceViewer/webpack.config.js b/src/web/traceViewer/webpack.config.js index c1e9a96323..2dba326c91 100644 --- a/src/web/traceViewer/webpack.config.js +++ b/src/web/traceViewer/webpack.config.js @@ -1,15 +1,16 @@ const path = require('path'); const HtmlWebPackPlugin = require('html-webpack-plugin'); +const mode = process.env.NODE_ENV === 'production' ? 'production' : 'development'; module.exports = { - mode: process.env.NODE_ENV === 'production' ? 'production' : 'development', + mode, entry: { app: path.join(__dirname, 'index.tsx'), }, resolve: { extensions: ['.ts', '.js', '.tsx', '.jsx'] }, - devtool: 'source-map', + devtool: mode === 'production' ? false : 'source-map', output: { globalObject: 'self', filename: '[name].bundle.js', diff --git a/utils/build/build.js b/utils/build/build.js index 523014d7a3..382f241f49 100644 --- a/utils/build/build.js +++ b/utils/build/build.js @@ -14,11 +14,25 @@ * limitations under the License. */ +// @ts-check + const child_process = require('child_process'); const path = require('path'); const chokidar = require('chokidar'); const fs = require('fs'); +/** + * @typedef {{ + * command: string, + * args: string[], + * shell: boolean, + * env?: NodeJS.ProcessEnv, + * }} Step + */ + +/** + * @type {Step[]} + */ const steps = []; const onChanges = []; const copyFiles = []; @@ -59,17 +73,23 @@ function runWatch() { } async function runBuild() { - function runStep(command, args, shell) { - const out = child_process.spawnSync(command, args, { stdio: 'inherit', shell }); + /** + * @param {Step} step + */ + function runStep(step) { + const out = child_process.spawnSync(step.command, step.args, { stdio: 'inherit', shell: step.shell, env: { + ...process.env, + ...step.env + } }); if (out.status) process.exit(out.status); } for (const step of steps) - runStep(step.command, step.args, step.shell); + runStep(step); for (const onChange of onChanges) { if (!onChange.committed) - runStep('node', [filePath(onChange.script)], false); + runStep({ command: 'node', args: [filePath(onChange.script)], shell: false }); } for (const {files, from, to, ignored} of copyFiles) { const watcher = chokidar.watch([filePath(files)], {