Commit 52da1f28 authored by Robert Knight's avatar Robert Knight

Remove all comments from minified JavaScript

By default Terser keeps certain comments [1] in minified output. Safari has a
bug [2] that causes column numbers to be incorrectly reported in stack
traces when a line contains inline comments. In minified code where the
output is packed into a small number of lines, this can result in stack
traces that map to the wrong source line. Stripping all comments from
the output works around the issue.

The effect on the size of the bundles is minimal. sidebar.bundle.js is
about 2KB smaller with this change.

Part of https://github.com/hypothesis/client/issues/4045

[1] https://github.com/terser/terser#format-options
[2] https://bugs.webkit.org/show_bug.cgi?id=221548
parent 97ee3727
......@@ -11,7 +11,17 @@ import virtual from '@rollup/plugin-virtual';
const isProd = process.env.NODE_ENV === 'production';
const prodPlugins = [];
if (isProd) {
prodPlugins.push(terser());
// Minify output.
prodPlugins.push(
terser({
format: {
// Strip *all* comments from minified output. This works around an
// issue with column numbers in stack traces in Safari.
// See https://bugs.webkit.org/show_bug.cgi?id=221548.
comments: false,
},
})
);
// Eliminate debug-only imports.
prodPlugins.push(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment