From b32be27cf7d6f63176f75972dfded495a40ea35f Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sat, 21 Sep 2019 13:44:32 -0700 Subject: [PATCH] feat: add debug build (#1506) --- CONTRIBUTING.md | 6 ++++++ bin/build-inline-script.js | 3 ++- webpack/client.config.js | 4 ++-- webpack/service-worker.config.js | 2 +- webpack/terser.config.js | 2 +- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 35a748ab..fd35242f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -143,6 +143,12 @@ Pinafore also offers a "legacy" build designed for older browsers. To build this LEGACY=1 yarn build +## Debug build + +To disable minification in a production build (for debugging purposes), you can run: + + DEBUG=1 yarn build + ## Debugging Webpack The Webpack Bundle Analyzer `report.html` and `stats.json` are available publicly via e.g.: diff --git a/bin/build-inline-script.js b/bin/build-inline-script.js index 2e30051a..ebadd1f4 100644 --- a/bin/build-inline-script.js +++ b/bin/build-inline-script.js @@ -21,13 +21,14 @@ export async function buildInlineScript () { plugins: [ replace({ 'process.browser': true, + 'process.env.LEGACY': JSON.stringify(process.env.LEGACY), 'process.env.THEME_COLORS': JSON.stringify(themeColors) }), process.env.LEGACY && babel({ runtimeHelpers: true, presets: ['@babel/preset-env'] }), - terser({ + !process.env.DEBUG && terser({ mangle: true, compress: true, ecma: 8 diff --git a/webpack/client.config.js b/webpack/client.config.js index c1347e2d..6eb53a36 100644 --- a/webpack/client.config.js +++ b/webpack/client.config.js @@ -88,7 +88,7 @@ module.exports = { optimization: dev ? {} : { minimizer: [ terser() - ], + ].filter(Boolean), splitChunks: { chunks: 'async', minSize: 5000, @@ -130,7 +130,7 @@ module.exports = { ]), devtool: dev ? 'inline-source-map' : 'source-map', performance: { - hints: dev ? false : 'error', + hints: dev ? false : (process.env.DEBUG ? 'warning' : 'error'), assetFilter: assetFilename => { return !(/\.map$/.test(assetFilename)) && !/tesseract-asset/.test(assetFilename) } diff --git a/webpack/service-worker.config.js b/webpack/service-worker.config.js index b8038123..ba18484f 100644 --- a/webpack/service-worker.config.js +++ b/webpack/service-worker.config.js @@ -23,5 +23,5 @@ module.exports = { 'process.env.SAPPER_TIMESTAMP': process.env.SAPPER_TIMESTAMP || Date.now() }), terser() - ] + ].filter(Boolean) } diff --git a/webpack/terser.config.js b/webpack/terser.config.js index 58c47440..3d8eb5db 100644 --- a/webpack/terser.config.js +++ b/webpack/terser.config.js @@ -1,6 +1,6 @@ const TerserWebpackPlugin = require('terser-webpack-plugin') -module.exports = () => new TerserWebpackPlugin({ +module.exports = () => !process.env.DEBUG && new TerserWebpackPlugin({ exclude: /tesseract-asset/, cache: true, parallel: true,