Compress Javascript files using Terser.
Compress Javascript files using Terser.
@fang/terser"">
@fang/terser" alt="NPM"> @fang/core"">
@fang/terser" alt="Libraries.io dependency status for latest release">
@fang/terser" alt="Snyk Vulnerabilities for npm package">
I created this plugin to be able to compress Javascript files. Terser is the most popular and currently maintained Javascript compression tool, and I wanted fang to have an official plugin for it.
Having @fang/core"">@fang/core installed on version 0.*
.
This example assumes you have a example/code.js
file containing your code, and you want to output a compressed code in example/dist/js/code.js
.
// script.js
const { run } = require("@fang/core");
const save = require("@fang/save");
const terser = require("@fang/terser");
const js = {
name: "Javascript",
input: "example/code.js",
tasks: [
terser(),
save({
folder: "example/dist/js",
}),
],
};
const main = async () => await run([js]);
main();
Run your script, and you should see something like this in the console.
$ node script.js
fang: start
8 CPUs core(s)
1 tasks to run
Javascript: start
Javascript: 30.604ms
fang: 183.533ms
This examples assumes you havbe a example/code.js
file containing your code, and your want to output a compressed code in example/dist/js/code.js
.
// script.js
const { run } = require("@fang/core");
const save = require("@fang/save");
const terser = require("../lib");
const js = {
name: "Javascript",
input: "example/code.js",
tasks: [
terser({
compress: {
passes: 5,
unsafe: true,
pure_getters: true,
},
toplevel: true,
}),
save({
folder: "example/dist/js",
}),
],
};
const main = async () => await run([js]);
main();
Run node script.js
, and you should see something like this in your console.
$ node script.js
fang: start
8 CPUs core(s)
1 tasks to run
Javascript: start
Javascript: 37.211ms
fang: 168.672ms