New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Online terser minifier? #106
Comments
Each Terser release creates a browser bundle in the <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<script src="https://unpkg.com/terser@3.10.11/dist/bundle.js"></script>
<script>
function Minify() {
var code = document.getElementById("code").value;
var options = {}, output = "";
try {
options = eval("(" + document.getElementById("options").value + ")");
} catch (ex) {
output = "// invalid terser minify options - using defaults\n";
}
var result = Terser.minify(code, options);
var out = document.getElementById("out");
if (result.error) {
output += JSON.stringify(result.error, null, 2);
} else {
output += result.code;
}
out.value = output;
}
</script>
</head>
<body>
<textarea id="options" rows="14" cols="80" onchange="Minify()"
onkeypress="this.onchange()" onpaste="this.onchange()" oninput="this.onchange()">
// terser minify options
{
toplevel: true,
compress: {
passes: 3,
//pure_getters: true,
//unsafe: true,
},
mangle: true,
output: {
//beautify: true,
},
}
</textarea>
<br>
<textarea id="code" rows="15" cols="80" onchange="Minify()"
onkeypress="this.onchange()" onpaste="this.onchange()" oninput="this.onchange()">
// ECMAScript input
function app(x, y) {
const message = (text) => {
console.log(text);
}
message(`Hello ES${x + y}`);
}
let five = 5, one = 1;
app(five, one);
</textarea>
<br>
<input type="button" id="ok" value="minify" onclick="Minify()" />
<br>
<textarea id="out" rows="15" cols="80"></textarea>
</body>
<script>Minify()</script>
</html> This information should probably go in the README. Pull request welcome. |
Thanks a lot! |
If you want to use If you want to explore more aggressive optimization options see |
Here's a first demo: https://xem.github.io/terser-online |
Hello,
I'd like to make an online Terser minifier, with just HTML + JS, similar to those that existed for uglifyjs/es, but I'm not sure where to start.
Can the JS files of your project be used in the browser, without using node/npm?
Would loading all the JS files in the lib folder be enough to replace "require('terser')" ?
Thanks!
The text was updated successfully, but these errors were encountered: