JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 27
  • Score
    100M100P100Q36654F
  • 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);
  }
} );

Lint only (syntax errors and warnings, no processing)

multic('my/js/file.js').file.js( function (err, res) { }

Callback signitures

  • err: null or Error instance (same as the first item in res.errors)
  • res: response object

Response object properties

  • source:
    • content: source code
    • type: string
    • optional: only exists if file is read
  • compiled:
    • content: compiled, unminified code
    • type: string
    • optional: only exists if compilation was requested
  • minified:
    • content: minified code
    • type: string
    • optional: only exists if minification was requested
  • includes
    • content: included files for jade and sass files with includes/import
    • type: Array object
    • default value: empty Array
    • always created
  • errors: Array of errors (always exists)
    • content: errors in consistent Error objects (see below)
    • type: Array object
    • default value: empty Array
    • always created
  • warnings:
    • content: warnings in consistent Error objects (see below)
    • type: Array object
    • default value: empty Array
    • always created

Options

Add file path when compiling from string

file: *filepath_string*useful for

This is useful for error messages and to define include path start point for jade and sass

Turn linting off

{lint: false}

Generate warnings for lines exceeding the 80 character limit

{maxLength80: true}

Generate warnings for non-matching indentation spaces

{indentation: N} // N > 0, usually 2 or 4

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

Linters

Coming soon (TODO)

  • Output to file
  • SASS, CSS and Jade linting