Skip to content

Cookbook: Add Vendor Libraries

DavidSouther edited this page Oct 23, 2014 · 1 revision

Q: How do I add libraries to the compiled vendors.(js|css) files?

Additional libraries can be added to a project using any dependency mechanism, then added to the vendors key in the stassets configuration. For instance, let's add [Moment.js][moment] for date handling.

  1. Install the dependency: $ npm install --save moment

  2. Add a vendors section to the stassets config

     "stassets": {
         "vendors": {
             "prefix": ["./node_modules"],
             "js": ["moment/min/moment.min.js"]
         }
     }
    
  3. Use moment through the global moment variable. (In an angular project, the recommended best practice is to wrap that variable in a service.)

  • The prefix key is an array of directories to look in. For instance, when mixing both node_modules and bower dependencies, the prefix key could be [ "./node_modules", "./components" ]
  • The js and css keys are arrays of files to concatenate in their respective vendors.js and vendors.css files. The prefix directories will be searched in order for these paths, and the first match will be returned.