montagejs / mop

Montage Optimizer (mop): Minifies (to reduce file size) and creates bundles (to reduce the number of requests) of Montage applications.
Other
31 stars 15 forks source link

Montage Optimizer (aka mop)

npm version

Build Status

for Montage ~0.14.6 and Mr ~0.15.0, ~0.14.2 and ~0.13.0.

Optimizes Montage applications for production by minifying, to reduce file size, and creating bundles, to reduce the number of requests.

Install Mop globally with NPM.

npm install -g mop

Mop can be run in any directory containing a Montage application.

$ ls
index.html    node_modules/ package.json  ui/
$ ls node_modules/
montage/
$ mop
# performs reading, processing and bundling steps
$ ls builds/
my-app        my-app@f7e7db2/

Features

Usage

Creates a builds directory from one or more applications, packages, and all their dependencies. The builds directory will be created in your current working directory.

Usage:

mop [-lfc] [-d @] [--target <build-dir>] <source-package>

e.g,

$ mop calculator
$ mop -t builds calculator

-t or --target changes the default target build directory. The default is builds relative to the current working directory.

-o 0 or --optimize 0 disables optimizating transforms.

-l or --lint provides per-file warnings if packaged files do not pass JSLint or various other sanity checks like script MIME types and known JSON schemas.

-d or --delimiter allows you to override the symbol used between package names and package hashes in the builds directory, which is @ by default.

--no-css allows you to disable CSS transforms. CSSOM cannot handle some modern CSS.

Your project will be assembled in the builds directory.

Notes

The bootstrap bundle Mop creates is usually large, as it contains the bootrapping code and the initial modules and all their dependencies. To avoid the download of this file blocking the rendering of your page make sure to include the async attribute in the bootstrap script tag:

<!-- Mr -->
<script src="https://github.com/montagejs/mop/raw/master/node_modules/mr/bootstrap.js" data-module="index" async></script>
<!-- Montage -->
<script src="https://github.com/montagejs/mop/raw/master/node_modules/montage/montage.js" async></script>

API

var optimize = require("mop");

optimize(process.cwd()).then(function () {
    console.log("Optimization done.");
});

optimize(location, [config])

Optimize the package at the given location.

Package JSON

The build system uses package.json files to discover dependencies. These dependencies must always be packages themselves.

For a comprehensive view of what can be in a package.json, see the UncommonJS specification.

For the purpose of the build system, the following properties are important: