Compress
Compress copied to clipboard
Terser JavaScript output
I'm testing with Terser and i don't seem to get the same result.
My astro.config.mjs
import { defineConfig } from "astro/config";
import compress from "astro-compress";
export default defineConfig({
integrations: [compress({
JavaScript: {
terser: {
compress: true,
mangle: true,
module: true,
}
}
})]
});
When i set up a clean test project (without astro) with Terser and run
terser index.js -o dist/index.min.js --compress --mangle --module
It makes from this:
// index.js
function sayHello() {
console.log("Hello, world!");
}
function greet(name) {
console.log("Greetings, " + name + "!");
}
const myNumber = 42;
sayHello();
greet("Alice");
console.log("My number is: " + myNumber);
this (desired outcome):
var o;console.log("Hello, world!"),o="Alice",console.log("Greetings, "+o+"!"),console.log("My number is: 42");
But with my astro config the output is (not expected outcome):
function e(){console.log("Hello, world!")}function l(o){console.log("Greetings, "+o+"!")}const n=42;e(),l("Alice"),console.log("My number is: 42")