@fang/terser
v0.1.0
Published
Compress Javascript files using Terser.
Downloads
2
Maintainers
Readme
fang-starter-plugin
Compress Javascript files using Terser.
Summary
About
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.
Features
- Compress Javascript files using Terser.
- Support all the Terser options.
Requirements
Having @fang/core installed on version 0.*
.
Installation
- Using NPM:
npm install --save-dev @fang/terser
- Using Yarn:
yarn add --dev @fang/terser
Examples
1. Compress a Javascript file
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
2. Customize how Terser compress your file
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