Extend Mimosa's default functionality
A Mimosa module is a node.js package that, when installed inside Mimosa or your project, can be used as part of Mimosa's workflows. Mimosa is able to use a module because modules implement a simple interface Mimosa understands and can use.
Unlike other build tools, Mimosa modules do not rely on communicating with each other via the file system. Mimosa's core is responsible for lining up the modules on an execution conveyor belt, passing information from one module to another directly. So, for example, a CoffeeScript file can be read, compiled, linted, minified, written to disk and live reload-ed in the browser -- effectively being touched by 6 modules -- with only two IOs: the read of the input CoffeeScript and the write of the output minified JavaScript. This keeps Mimosa fast. Live Reload will kick off before you even get a chance to toggle back to the browser.
Modules are collaborative in nature. They can access other modules directly. One good example is the dependency-graph module which creates d3 visualizations depicting an application's dependency tree. Rather than needing to build the dependency tree itself, that module can utilize the data already available in the mimosa-require
module, which exposes a dependency object. This lets the module author just focus on using d3 to create a cool visualization.
The tables below contain an abbreviated list of available Mimosa modules. If you are interested to see if a specific module is available, the best place to search, besides Google, is NPM, where all the modules are registered.
Mimosa core's JavaScript compiler wraps the following module compilers and provides a base level of common functionality.
Name | Description |
---|---|
babel | A babel (formerly 6to5) compiler |
coffeescript | A CoffeeScript compiler |
iced-coffeescript | An Iced Coffeescript compiler |
emberscript | An EmberScript compiler. |
coco | A Coco compiler. |
livescript | A LiveScript compiler. |
react | A React compiler. |
cjsx | A CoffeeScript + JSX/React compiler. |
typescript | A TypeScript compiler./td> |
Mimosa does a little bit of extra work with CSS. Mimosa takes care not to compile files that do not need it. If CSS gets included back through a single base CSS file, changing a file deep down the tree of includes will only trigger a compile of that single base file and not the changed file. Similarly if there are multiple base files, changing a file included in two places will trigger the recompile of those two files.
Name | Description |
---|---|
stylus | A Stylus CSS pre-processor with built-in nib support. |
sass | A SASS CSS pre-processor that works with both node-sass and Ruby SASS. |
less | A Less CSS pre-processor. |
Using the following compiler modules Mimosa will precompile your project's templates. Based on its configuration, Mimosa will create one-to-many compiled template files. See the template documentation below and the general configuration for templates for details on base template compiler behavior.
Name | Description |
---|---|
handlebars | A Handlebars template compiler. |
ember-handlebars | A Handlebars template compiler specific for use with Ember.js |
ember-htmlbars | A HTMLBars template compiler specific for use with Ember.js |
emblem | An Emblem template compiler. |
dust | A Dust template compiler. |
hogan | A Hogan template compiler |
jade | A Jade template compiler. |
jade-static | A Jade template compiler that outputs HTML rather than dynamic templates. |
underscore | An Underscore template compiler |
lodash | A Lodash template compiler. |
ejs | An EJS template compiler. |
eco | An ECO template compiler. |
ractive | A Ractive template compiler. |
nunjucks | A Nunjucks template compiler. |
twig | A Twig template compiler. |
html-templates | Plain, non-dynamic, HTML templates |
Name | Description |
---|---|
copy | A file copying module responsible for transporting files from Mimosa's input directory to its output directory. By default it copies 25+ different types of files. |
Miscellaneous compilers don't fit nicely into the categories above. They don't copy files, transpile JavaScript, pre-process CSS or compile templates.
There are currently no Miscellaneous compilers, if you are interested in creating one, check out this example Miscellaeous compiler.
The following are additional modules that compile/copy/transpile assets but are not considered "compilers" by Mimosa.
Name | Description |
---|---|
ember-module-import | Builds ember.js module manifests for an AMD/CommonJS-based application |
stream-copy | Copies files that do not need to be processed otherwise by Mimosa and it does so with super-fast streams. |
markdown | Compiles markdown syntax to html. |
myth | A simple Myth CSS preprocessor module. |
regenerator | Use ES6 generator syntax today. This module compiles ES6 generators down to ES5 compatible javascript. |
esperanto-es6-modules | Use ES6 module syntax today. This module compiles ES6 module syntax down to AMD or CommonJS. |
es6-module-transpiler | Use ES6 module syntax today. This module compiles ES6 module syntax down to AMD, CommonJS or globals. |
client-jade-static | Compiles Jade files with a ".html.jade" extension statically and writes them out as individual plain HTML files. |
jade-static | Actually a template compiler like any other that executes compiled jade templates, transforming them to HTML and then merging the templates into a single file. |
hogan-static | Compiles individual Hogan/Mustache templates to separate html files while allowing for partials and template contexts to be provided. |
Name | Description |
---|---|
phantomcss | Run automated visual testing via PhantomCSS. |
ember-test | Ember specific QUnit/Testem test integration. |
testem-qunit | A Testem, QUnit, Sinon, Chai integration that utilizes your RequireJS config and spec naming conventions to allow for immediate testing, no configuration required. |
testem-require | A Testem, Mocha, Sinon, Chai integration that utilizes your RequireJS config and spec naming conventions to allow for immediate testing, no configuration required. |
testem-simple | Simple Testem test runner integration. |
karma | Karma test runner integration. |
karma-enterprise | Advanced and maintained Karma test runner integration. |
jasmine-node | Start up a Jasmine-Node test suite alongside Mimosa |
Name | Description |
---|---|
vulcanize | Web component optimization support via Polymer/Vulcanize |
require | AMD/RequireJS support including optimization |
uncss | Removes unused CSS as part of a build. |
minify-css | Minification of CSS assets |
minify-js | Minification of JS assets |
minify-html | HTML minification. |
htmlclean | HTML cleaning. |
minify-svg | SVG minification. |
minify-img | Image minification. |
minify-json | JSON minification. |
sprite | Generate CSS sprite images and stylesheets. |
spritesmith | Generate CSS sprite images and stylesheets. With retina support. |
combine | Combine all non-binary files in a folder into a single file |
Name | Description |
---|---|
build-task | Run scripts/servers during a mimosa build . |
npm-web-dependencies | Install web dependencies from NPM using Browserify. |
bower | Bower integration for managing vendor assets. |
defeature | Will slice individual features out of an application's templates, javascript and CSS at build time. |
fix-rjs-ember | This module addresses specific issues with Ember.js packaging via r.js. The issues were introduced with version 1.7 of Ember but fixed with version 1.8+. |
groundskeeper | Clean console.log, debugger and pragmas from your code during a build. |
dependency-bundler | Bundles multiple AMD modules into a single module for easy import. |
asset-cache-bust | Asset cache busting. |
browserify | A module for the very popular CommonJS node-in-the-browser build tool. |
require-library-package | Package up library code built using AMD/RequireJS for use in other applications. |
web-package | Packaging of a web application for deployment. |
rpm-package | Packaging of a web application for deployment as an RPM. |
s3-deployer | Deploy your static files to AWS S3. |
Name | Description |
---|---|
csslint | Run CSSLint over your CSS. |
jshint | Run JSHint over your JavaScript code. |
jscs | Wraps the popular JSCS JavaScript style checking utility. |
css-colorguard | Tells you if you have colors in your CSS that are too close together. |
eslint | Runs ESLint over your JavaScript code. |
plato | Run the Plato Static Analysis tool over your JavaScript. |
require-lint | Detect unused dependencies in your AMD code. |
dependency-graph | Build awesome d3 visualizations of your require.js dependency graph. |
coffeelint | Process your CoffeeScript for style and variances from the language idiom. |
js-validate | Parses JavaScript to ensure code is valid. |
Name | Description |
---|---|
require | AMD/RequireJS support including optimization |
require-commonjs | CommonJS support via AMD/RequireJS |
requirebuild-include | A module to include assets into r.js runs before optimization occurs. |
requirebuild-textplugin-include | Will include files attached to the text plugin to r.js runs. |
requirebuild-module-include | Find dependencies and include them in r.js module config include arrays. |
requirebuild-textplugin-module-include | Find text dependencies and include them in r.js module config include arrays. |
Building an Ember app? Mimosa isn't Ember specific, but these modules are.
Name | Description |
---|---|
ember-module-import | Builds ember.js module manifests for an AMD/CommonJS-based application |
fix-rjs-ember | (For Ember pre-1.8) This module addresses specific issues with Ember.js packaging via r.js. The issues were introduced with version 1.7 of ember. |
ember-env | Adds EmberENV object to ember library. |
ember-handlebars | Ember specific Handlebars template compilation. |
ember-htmlbars | Ember specific HTMLBars template compilation. |
ember-test | Ember specific QUnit/Testem test integration. |
Name | Description |
---|---|
server | Mimosa-based hosting and managing of node-based user hosting |
live-reload | Application reloads when the code does |
start-server | Start your server when the build completes. |
server-template-compile | Copy your server templates into static HTML as part of a build. |
server-reload | Restart a node server when server assets change. |
Name | Description |
---|---|
coffeescript-preprocess | Before coffeescript is compiled replace template-like variables in the code. |
replace | Perform simple text replacement. |
rename | Rename files before they are written to output. |
svgs-to-iconfonts | Generate a full set of icon fonts from a set of svg files. |
restart | Automatically restarts a running Mimosa when the compiled directory is deleted. |
vault | Uses the vault project to generate passwords derived from a secret key. |
autoprefixer | This module will automatically prefix your vendor CSS and provides source map support. |
handlebars-on-window | Use this module to alter handlebars.js to place Handlebars on the window object. |
d3-on-window | Use this module to alter d3.js to place d3 on the window object. |
post-hook | Run scripts/commands at the end of the mimosa watch startup. |
just-copy | Allow assets to bypass Mimosa module processing and just be copied. |
import-source | Copy other files into a project to be included as part of the project. |
volo | Introduces a import command that wraps Volo functionality. Comprises the import command that came bundled with Mimosa pre 0.7.2. |
There are several ways to install a module.
modules
arrayOne way to install a module is to just add the name to the modules
array in the mimosa-config
. This is a shortcut for the project level npm install
(covered next). The next time Mimosa is started for that project it will install the module into the Mimosa project from NPM.
To use a module it needs to be added to the modules
array anyway, so this shortcut saves the installation step.
Install Mimosa modules in the project itself and Mimosa will prioritize those modules above all others. Run npm install mimosa-nameOfModule
and the module will be installed. Modules installed inside a project take precedence over any modules installed into other scopes.
One way to install a module is the mod:install
command discussed further below. mimosa mod:install mimosa-web-package
will install mimosa-web-package
from NPM. The module will still need to be added to any projects that need to use it. This command adds the module to the globally installed Mimosa making it available to every Mimosa project.
Use npm install -g
to install any modules into the global node scope. Modules installed with mod:install
take priority, so if any modules are installed with both npm install -g
and mod:install
, the npm install -g
module will be ignored.
To install a specific version of a module, to, for instance, ensure everyone on a project stays on the same version, add a @
followed by the version after the module name. Ex: web-package@0.1.0
. This can also be accomplished by managing versions in a project's package.json
.
For performance reasons, templates should be pre-compiled on the server rather than the browser. Mimosa, through many external compiler modules (see the list at the top of the page) will precompile a project's templates. Based on its configuration, Mimosa will create one-to-many compiled template files. See Output Variations below for the output options.
For each templating language, the compiled template files provide a JavaScript object of templates, keyed by the template file name (the default configuration for template name). Each template needs to have a unique name. Should this be violated, Mimosa will warn of template collision issues.
Most of the libraries require a client side version to run the compiled templates. If using AMD wrapping for your templates (more on that below), most Mimosa template compilers will handle including that library in your project. They will place an AMD wrapped version of the library inside the vendor.javascripts
library and reference it from the compiled template file. If a library that matches Mimosa's name for the library exists, Mimosa will not overwrite that file. Also, if using AMD wrapping and a requirejs path alias is set up pointing at the library, like underscore:"vendor/underscore"
, Mimosa will use the path.
By default the resulting compiled templates will be merged into a single AMD-wrapped file for use in the client. The name and location of that single file is configurable, compilers.template.outputFileName
, but by default it is kept at javascripts/templates.js
. Use of the templates in this file differs per library, so see the template compiler documentation for details.
If a single-page web app is being built, then a single template file is ideal and Mimosa's defaults can be left alone. But if a site has multiple pages, then ideally Mimosa should build a template file per page.
template: { output: [{ folders:["search","shared"], outputFileName: "search_templates" },{ folders:["user","shared"], outputFileName: "user_templates" }] }
The mimosa-config
can be altered to build multiple compiled template output files. Instead of using template.outputFileName
, use the template.output
array. Each element in the array has a folders
array and an outputFileName
. output[].outputFileName
is identical to template.outputFileName
except that is has no default so it must be provided. folders
specifies which folders of templates should be bundled together. Every template contained in the folder structure under each of the folders
will be compiled and concatenated into the output file. The mimosa-config-documented
also includes a commented out example for this configuration.
So, for example, if an app has two pages, "search" and "user", which each have many templates of their own (inside "search" and "user" directories), but that also share common templates from a "shared" folder, that can be configured as listed here.
Multiple templating libraries can be used at once, but to do so properly, there is some additional config Mimosa needs. Mimosa bundles templates into the same file, but templates from different libraries don't belong in the same file. So if multiple libraries are being used, provide Mimosa, via the mimosa-config
, a map/hash of compiler name to output file name with the template.outputFileName
(or the template.output[].outputFileName
) config property.
If template.wrapType
is set to none
, then Mimosa does no wrapping. Mimosa will also not write the AMD-wrapped template client library into the watch.javascriptDir
/vendor
directory. If going the non-AMD route, the client library must be provided by the project.
If template.wrapType
config is set to common
, Mimosa will create CommonJS compliant template files. Mimosa will also not write any client libraries so the project author must provide a version of the library that works in a CommonJS project.
Each command has a section dedicated to it below, but here is a quick list of the available module commands.
Command | Options | Description |
---|---|---|
mod:list | [-i/--installed] [-v/--verbose] | List all Mimosa modules in NPM, or, with a flag, just those you have installed including version information. |
mod:install | <moduleName> | Install a Mimosa module into your global Mimosa. |
mod:uninstall | <moduleName> | Remove a Mimosa module from your global Mimosa. |
mod:list
will search NPM to find all available Mimosa modules. mod:list
will list the most recent version of the module and if that module is currently installed, the installed version. If there is a difference, the installed version will be colored to signal that the version is out of date.
Execute mod:list
with the --installed
flag to limit the full list to just those currently installed.
$ mimosa mod:list -installed $ mimosa mod:list -i
Add a --verbose
flag and Mimosa will including a short description and the list of dependencies the module has on other node.js modules.
$ mimosa mod:list --verbose $ mimosa mod:list -v
To install a module execute mimosa mod:install
and provide the name of the module.
$ mimosa mod:install mimosa-server
If the module has already been installed, this will update it to the latest version. To install a specific version of a module, add the version after a @.
$ mimosa mod:install mimosa-server@0.2.0
To use and test a module under local development that isn't in NPM execute mod:install
without providing a name for the module. For this to work properly, the command must be executed from the same directory as the module's package.json
, which should be the root of the module. Once the module is installed, Mimosa treats it the same as a module it installed from NPM.
Execute mod:uninstall
to remove a module from the Mimosa global install. This will not remove it from your local project if it is installed there. To do that simply remove it from the node_modules
directory.
$ mimosa mod:uninstall mimosa-server