The asset pipeline bundled in Sails is a set of Grunt tasks configured with conventional defaults designed to make your project more consistent and productive. The entire frontend asset workflow is completely customizable, while providing some default tasks out of the box. Sails makes it easy to configure new tasks to fit your needs.
Here are a few things that the default Grunt configuration in Sails does to help you out:
Below is a list of the Grunt tasks that are included by default in new Sails projects:
This grunt task is configured to clean out the contents in the
.tmp/public/of your Sails project.
Compiles CoffeeScript files from
Creates and adds an unique hash to the end of a filename for cache busting.
dev task config
Copies all directories and files, except coffeescript and less files, from the sails assets folder into the
build task config
Copies all directories and files from the .tmp/public directory into a www directory.
Minifies CSS files and places them into
Precompiles Underscore templates to a
Compiles LESS files into CSS. Only the
assets/styles/importer.lessis compiled. This allows you to control the ordering yourself (i.e. import your dependencies, mixins, variables, resets, etc. before other stylesheets).
<link>tags for CSS files. Also automatically links an output file containing precompiled templates using a
<script>tag. A much more detailed description of this task can be found here, but the big takeaway is that script and stylesheet injection is only done in files containing
<!--STYLES--><!--STYLES END-->tags. These are included in the default views/layouts/layout.ejs file in a new Sails project. If you don't want to use the linker for your project, you can simply remove those tags.
A grunt task to keep directories in sync. It is very similar to grunt-contrib-copy but tries to copy only those files that have actually changed. It specifically synchronizes files from the
.tmp/public/, overwriting anything that's already there.
mangleoption when setting up this task.
Runs predefined tasks whenever watched file patterns are added, changed, or deleted. Watches for changes on files in the
assets/folder, and re-runs the appropriate tasks (e.g. LESS and JST compilation). This allows you to see changes to your assets reflected in your app without having to restart the Sails server.