Edit Page

Default Tasks

Overview

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 it provides 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:

  • Automatic LESS compilation
  • Automatic JST compilation
  • Automatic Coffeescript compilation
  • Optional automatic asset injection, minification, and concatenation
  • Creation of a web ready public directory
  • File watching and syncing
  • Optimization of assets in production

Default Grunt tasks

Below is a list of the Grunt tasks that are included by default in new Sails projects:

clean

This grunt task is configured to clean out the contents in the .tmp/public/ of your sails project.

usage docs

coffee

Compiles coffeeScript files from assets/js/ into Javascript and places them into .tmp/public/js/ directory.

usage docs

concat

Concatenates javascript and css files, and saves concatenated files in .tmp/public/concat/ directory.

usage docs

copy

dev task config Copies all directories and files, except coffeescript and less files, from the sails assets folder into the .tmp/public/ directory.

build task config Copies all directories and files from the .tmp/public directory into a www directory.

usage docs

cssmin

Minifies css files and places them into .tmp/public/min/ directory.

usage docs

jst

Precompiles Underscore templates to a .jst file. (i.e. it takes HTML template files and turns them into tiny javascript functions). This can speed up template rendering on the client, and reduce bandwidth usage.

usage docs

less

Compiles LESS files into CSS. Only the assets/styles/importer.less is compiled. This allows you to control the ordering yourself, i.e. import your dependencies, mixins, variables, resets, etc. before other stylesheets.

usage docs

sails-linker

Automatically inject <script> tags for javascript files and <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 <!--SCRIPTS--><!--SCRIPTS END--> and/or <!--STYLES--><!--STYLES END--> tags. These are included in the default views/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.

usage docs

sync

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 assets/ folder to .tmp/public/, overwriting anything that's already there.

usage docs

uglify

Minifies client-side javascript assets. Note that by default, this task will "mangle" all of your function and variable names (either by changing them to a much shorter name, or stripping them entirely). This is usually desirable as it makes your code significantly smaller, but in some cases can lead to unexpected results (particularly when you expect an object's constructor to have a certain name). To turn off or modify this behavior, use the mangle option when setting up this task.

usage docs

watch

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.

usage docs

Is something missing?

If you notice something we've missed or could be improved on, please follow this link and submit a pull request to the sails-docs repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.

Sails logo
  • Home
  • Get started
  • Support
  • Documentation
  • Documentation

For a better experience on sailsjs.com, update your browser.

Documentation

Reference Concepts App structure | Upgrading Contribution guide | Tutorials More

Concepts

  • Assets
    • Default Tasks
    • Disabling Grunt
    • Task Automation
  • Blueprints
    • Blueprint Actions
    • Blueprint Routes
  • Configuration
    • The local.js file
    • Using `.sailsrc` Files
  • Controllers
    • Generating Controllers
    • Routing to Controllers
  • Custom Responses
    • Adding a Custom Response
    • Default Responses
  • Deployment
    • FAQ
    • Hosting
    • Scaling
  • Extending Sails
    • Adapters
      • Available Adapters
      • Custom Adapters
    • Generators
      • Available Generators
      • Custom Generators
    • Hooks
      • Hook Specification
        • .configure()
        • .defaults
        • .initialize()
        • .routes
      • Installable Hooks
      • Project Hooks
      • Using Hooks
  • File Uploads
    • Uploading to GridFS
    • Uploading to S3
  • Globals
    • Disabling Globals
  • Internationalization
    • Locales
    • Translating Dynamic Content
  • Logging
    • Custom log messages
  • Middleware
    • Conventional Defaults
  • Models and ORM
    • Associations
      • Dominance
      • Many-to-Many
      • One Way Association
      • One-to-Many
      • One-to-One
      • Through Associations
    • Attributes
    • Lifecycle callbacks
    • Model Settings
    • Models
    • Query Language
    • Validations
  • Policies
    • Sails + Passport
  • Programmatic Usage
    • Tips and Tricks
  • Realtime
    • Multi-server environments
    • On the client
    • On the server
  • Routes
    • Custom Routes
    • URL Slugs
  • Security
    • Clickjacking
    • Content Security Policy
    • CORS
    • CSRF
    • DDOS
    • P3P
    • Socket Hijacking
    • Strict Transport Security
    • XSS
  • Services
    • Creating a Service
  • Sessions
  • Testing
  • Views
    • Layouts
    • Locals
    • Partials
    • View Engines

Built with Love

The Sails framework is maintained by a web & mobile studio in Austin, TX, with the help of our contributors. We created Sails in 2012 to assist us on Node.js projects. Naturally we open-sourced it. We hope it makes your life a little bit easier!

Sails:
  • What is Sails?
  • Treeline IDE
  • Contribute
  • Logos/artwork
About:
  • The Sails Company
  • Security
  • News
  • Legal
Help:
  • Get started
  • Documentation
  • Docs
  • Enterprise
  • Hire us

© 2012-2018 The Sails Company. 
The Sails framework is free and open-source under the MIT License.