JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q38958F
  • License ISC

node.js compiler and minifier API for various web sources: jade, html, sass/scss, css, coffee-script, es6/6to5, javascript/es5, html2js

Package Exports

  • multic

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (multic) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

multic

node.js compiler and minifier API for various web sources: jade, html, sass/scss, css, coffee-script, es6/6to5, javascript/es5, html2js

Install for your app

cd /path/to/your/app
npm install multic --save

Usage

Pattern

var multic = require('multic');

multic(source|path[, options])[.file].coffee|css|es6|html|jade|sass[.css|html|js][.min](callback);

Examples

Concept

JavaScript string minification

multic(script, {file: 'my/file/name.js'}).js.min( function (err, res) {}) ;

Jade file->HTML compilation

multic('my/jade/file.jade').file.jade.html( function (err, res) {} );

Compile SASS file to CSS + minify

multic('my/sass/file.scss').file.sass.css.min( function (err, res) {} );

Jade to Angular module JavaScript

multic('my/sass/file.scss').file.sass.css.min( function (err, res) {
  if (err) {
    console.error(err);
  } else {
    console.log('source:', res.source);
    console.log('compiled:', res.compiled);
    console.log('minified:', res.minified);
  }
} );

Callback signitures

  • err: null or Error instance
  • res: object

Response object properties

  • source: source code (if file is read)
  • compiled: compiled, unminified source (if compiled)
  • minified: minified source (if minified)
  • includes: Array of included files (for jade and sass)
  • errors: Array of errors
  • warnings: Array of warnings

Consequent errors and warnings

Parsing errors from different kinds of compilers can be tricky. They have inconsistant error (although at times similar) error and warning messages.

Jade for example (as of v1.9.2) would produce propriatery warnings on STDERR output even when called from the API.

multic attempts to provide a unified interface for all errors and warnings. You get these properties on the errors/warnings:

  • message: (string) literal description of the error/warning
  • title: (string or null) short description of the error/warning
  • file: (string or null) file path of error
  • line: (number or null) indication of error/warning line (0-based index, i.e. first line is line 0)
  • column: (number or null) indication of error/warning column in line (0-based index, i.e. first column is column 0)
  • sourceLines: (object or null) a snippet of the source code around the error/warning. Keys are line numbers, values are the lines (without the \n character at the end). 11 lines (error/warning line + 5 previous + 5 following lines) or less (when the line is near the start or end of file).

Featured compilers

Minifiers

Coming soon (TODO)

  • Output to file
  • Lint support (generate warnings)