jstransformer-terser

Sync and Async Terser support for JSTransformers.

Usage no npm install needed!

<script type="module">
  import jstransformerTerser from 'https://cdn.skypack.dev/jstransformer-terser';
</script>

README

jstransformer-terser

Sync and Async Terser support for JSTransformers.

Minifies javascript using terser via jstransformers.

npm Package Version Package Dependencies Coveralls github GitHub Workflow Status (branch) GitHub Repo License MIT


Install

# install using npm
npm install --save jstransformer-terser terser
# install using yarn
yarn add jstransformer-terser terser

API

This transformer supports render, renderAsync, renderFile and renderFileAsync. All according to the jstransformer API definition.

var terserTransformer = require('jstransformer')(require('jstransformer-terser'));

// SYNC
const result = terserTransformer.render('function add(first, second) { return first + second; }');
console.log(result.body);
//=> 'function add(n,d){return n+d;}'

// ASYNC (Promise API)
terserTransformer
  .renderAsync('function add(first, second) { return first + second; }')
  .then(result => console.log(result.body));
//=> 'function add(n,d){return n+d;}'

// ASYNC (Callback API)
terserTransformer.renderAsync('function add(first, second) { return first + second; }', {}, (err, result) => {
  if (err) console.error(err);
  else console.log(result.body);
});
//=> 'function add(n,d){return n+d;}'

Development

Requirements: node.js >=14, yarn >=1.22

# build using tsc
yarn build
# watch and rebuild
yarn build:watch
# lint using prettier and eslint
yarn lint
# test using jest
yarn test
# watch and retest
yarn test:watch
# open coverage in default browser
yarn coverage:open
# check everything
yarn preflight

License and Author

MIT © Simon Lepel