@style.tools/async-iife
Node.js IIFE generator for @style.tools/async. Module and CLI program.
Last updated 17 days ago by optimization .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @style.tools/async-iife 
SYNC missed versions from official npm registry.

Build Status Version npm version

IIFE generator

A Node.js IIFE generator for @style.tools/async.

The generator is available online on https://style.tools/iife/

Documentation is available on docs.style.tools/async/iife-generator.


IIFE (Immediately-invoked Function Expressions) is a coding pattern for loading a script. An IIFE can be used in the browser safely.

The IIFE can be optmized using Google Closure Compiler with Advanced Optimizations for optimal compression.

The Node.js module can be executed as a CLI program from the command-line.

Install

npm install @style.tools/async-iife

Usage

CLI

The provided iife-cli.js script can be used from the command-line. The NPM package contains a npm run iife script.

Examples

Display usage information and a list with available modules.

npm run iife -- --help

image

The following command shows how to create an IIFE with unary format, output to path/to/iife.js and with 3 modules that automatically load the required dependencies.

npm run iife --  --format unary --compress --output path/to/iife.js --modules css-loader,localstorage,timing

Short flags and a space separated module list are supported.

npm run iife --  -f unary -c -o path/to/iife.js -m "css-loader localstorage timing"

When omitting the --output flag the script is printed to the console, e.g. for > output.js.

Node.js module

// load Node.js module
const iife = require('@style.tools/async-iife');

// return script text for inlining
// uses memory-cache @link https://www.npmjs.com/package/memory-cache
iife.generate(['css-loader', 'timing'], {
   debug: true, // debug sources
   format: 'unary' // !function(){ ... }()
}).then(function(iife_script) {
	
   // iife_script contains the IIFE script text

});

// output to file
iife.generate(['css-loader', 'timing'], {
   compress: true, // Google Closure Compiler API compression
   format: 'wrap', // (function(){ ... })()
   output: 'path/to/iife.js',
   output_stats: true // return { modules:[], size:0, gzip_size:0 }
}).then(function(stats) {
	
   // iife.js written
   console.log(stats);

});

The Node.js module can be used efficiently within a Node.js CMS. IIFE's are cached in memory using memory-cache.

Warning: the generator depends on the free Google Closure Compiler API that may not be 100% reliable. When using the generator in production it may be an option to use a local Google Closure Compiler service.

Current Tags

  • 1.0.9                                ...           latest (17 days ago)

10 Versions

  • 1.0.9                                ...           17 days ago
  • 1.0.8                                ...           23 days ago
  • 1.0.7                                ...           2 months ago
  • 1.0.6                                ...           2 months ago
  • 1.0.5                                ...           2 months ago
  • 1.0.4                                ...           2 months ago
  • 1.0.3                                ...           2 months ago
  • 1.0.2                                ...           2 months ago
  • 1.0.1                                ...           3 months ago
  • 1.0.0                                ...           4 months ago
Maintainers (1)
Downloads
Today 10
This Week 11
This Month 33
Last Day 0
Last Week 10
Last Month 16
Dependencies (7)
Dev Dependencies (4)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |