postinstall-js

postinstall command to compile and minify javascript files

Usage no npm install needed!

<script type="module">
  import postinstallJs from 'https://cdn.skypack.dev/postinstall-js';
</script>

README

postinstall-js

This is a postinstall command plugin.

It runs babel-preset-env and babel-preset-minify on inputs, and concatenate them on output.

To transform inputs using browserify, please check postinstall-browserify.

Usage

The plugin can be called directly, or through postinstall.

Directly:

require('postinstall-js')(inputs, output, options).then(function() {
 // done
});

Options

browsers

Breaking change in version 0.5.0: do not use browsers option.

Rely on browserslist to get a default reasonable set, or use package.json or .browserslistrc file. See browserslist.

minify

Pass minify: false to disable minification.

comments

By default, when minify is active, babel comments option is set to false.

modules

By default modules: false is passed to babel-preset-env.

cacheDir

A path to a cache directory must be set to enable cache.

extending native elements

Note that babel 7 and @babel/plugin-transform-classes only support this type of constructor overriding:

class HTMLMyCustomElement extends HTMLElement {
 constructor(me) {
  me = super(me);
  me.init();
  return me;
 }
 init() {}
}

Caveats

Support for source maps is not available and will be added eventually.