When enabling JavaScript mangling in terser (e.g. --minify-js {"compress":{"drop_console":"true"},"mangle":{"toplevel":"true"}} my page breaks (TypeError: e is not a function).
Test case:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>title</title>
<script>
function functiona(param1) {
return functionb(param1);
}
</script>
</head>
<body>
Some text in body.
<div id="target">target</div>
<script>
function functionb(param2) {
return param2;
}
document.addEventListener("OnDOMContentLoaded", function(){
console.log("loaded");
var test = functiona(undefined);
});
</script>
</body>
</html>
turns into
<!doctype html>
<html lang=en>
<meta charset=UTF-8>
<meta name=viewport content="width=device-width,initial-scale=1">
<title>title</title>
<script>
function n(n) {
return functionb(n)
}
</script>Some text in body.<div id=target>target</div>
<script>
function n(n) {
return n
}
document.addEventListener("OnDOMContentLoaded", (function () {
functiona(void 0)
}))
</script>
It seems html-minifier-terser minifies these individually, rather than in the same "namespace" - correct? This of course also would explain the TypeError I am seeing with my actual HTML page.
Is there an option to prevent this? If not, and this is not in the scope of the project, is there a workaround?
When enabling JavaScript mangling in terser (e.g.
--minify-js {"compress":{"drop_console":"true"},"mangle":{"toplevel":"true"}}
my page breaks (TypeError: e is not a function
).Test case:
turns into
It seems html-minifier-terser minifies these individually, rather than in the same "namespace" - correct? This of course also would explain the TypeError I am seeing with my actual HTML page.
Is there an option to prevent this? If not, and this is not in the scope of the project, is there a workaround?
For reference