Ensure Terser only outputs ascii characters
The google-protobuf dependency defines some Regex patterns, which
include escape sequences corresponding to invalid Unicode characters.
Terser at the minification phase would convert those escape sequences to
the raw bytes, which would render the UTF-8 file invalid, and Chrome
wouldn't let the user install the extension.
Thus, this CL adds a workaround to only output valid ASCII characters,
so this issue doesn't occur again. This isn't expected to have much
impact, since we don't use a lot of non-ASCII characters in our code.
Fixed: twpowertools:145
Change-Id: I56863eaa8a90e7382758474f8c0ba08c17cf51f0
diff --git a/webpack.config.js b/webpack.config.js
index 40fbcc2..619237e 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -2,6 +2,7 @@
const path = require('path');
const json5 = require('json5');
const CopyWebpackPlugin = require('copy-webpack-plugin');
+const TerserPlugin = require('terser-webpack-plugin');
const WebpackShellPluginNext = require('webpack-shell-plugin-next');
// Pontoon uses their own locale set. This array lets us convert those locales
@@ -159,5 +160,16 @@
},
]
},
+ optimization: {
+ minimizer: [
+ new TerserPlugin({
+ terserOptions: {
+ format: {
+ ascii_only: true, // Due to https://iavm.xyz/b/twpowertools/145#c1
+ },
+ },
+ }),
+ ],
+ },
};
};