chore: teserReservations build reserved names

This commit is contained in:
Zack Spear
2023-08-08 16:37:12 -07:00
parent f75ff38607
commit d395056a12
+24 -1
View File
@@ -5,6 +5,29 @@ for (const k in envConfig) {
process.env[k] = envConfig[k];
}
/**
* @see alt solution https://github.com/terser/terser/issues/1001, https://github.com/terser/terser/pull/1038
*/
function terserReservations(inputStr) {
const combinations = [];
// Add 1-character combinations
for(let i = 0; i < inputStr.length; i++) {
combinations.push(inputStr[i]);
}
// Add 2-character combinations
for(let i = 0; i < inputStr.length; i++) {
for(let j = 0; j < inputStr.length; j++) {
combinations.push(inputStr[i] + inputStr[j]);
}
}
return combinations;
}
const charsToReserve = "_$abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
ssr: false,
@@ -30,7 +53,7 @@ export default defineNuxtConfig({
minify: 'terser',
terserOptions: {
mangle: {
reserved: ['_', '$', 'i', 'my', 't', 'v', 'w', 'x', 'y', 'z'],
reserved: terserReservations(charsToReserve),
toplevel: true,
},
},