Skip to content

[REMOVED] Aggregation core module

Christopher Lowenthal edited this page Nov 21, 2016 · 1 revision

REMOVED as of Mean 0.6 (Meanio 0.9)

This core module aggregates all the specified JavaScript and CSS resources and produces three files:

  • aggregated.css for the header of the page
  • aggregated.js for the header of the page
  • aggregated.js for the footer of the page

Specifying files to be aggregated

For each file to be aggregated, Aggregation module has to be told:

  1. Path to the file
  2. Type of the file (js or css)
  3. If the file is of js type, location of the file (header or footer)
  4. (Optionally) a weight number may be specified to hint for the ordering of the file within the aggregated.js

There are two basic ways to tell the Aggregation module what files to aggregate:

  1. Global approach: use the assets.json file in the config directory of your mean installation
  2. Local approach (the Package approach): use the aggregateAsset method of your Module class (from which all the Package Modules are/should be derived)

assets.json

Standard contents of this file is

{
  "core": {
    "css": {
      "bower_components/build/css/dist.min.css": []
    },
    "js": {
      "bower_components/build/js/dist.min.js": [
        "bower_components/jquery/dist/jquery.min.js",
        "bower_components/angular/angular.js",
        "bower_components/angular-mocks/angular-mocks.js",
        "bower_components/angular-cookies/angular-cookies.js",
        "bower_components/angular-resource/angular-resource.js",
        "bower_components/angular-ui-router/release/angular-ui-router.js",
        "bower_components/angular-bootstrap/ui-bootstrap.js",
        "bower_components/angular-bootstrap/ui-bootstrap-tpls.js"
      ]
    }
  }
}

Currently, only the core group is supported. It has the css section (that goes to the header, just like any css) and the js section that goes to the footer. js files listed in assets.json will appear in the aggregated.js in the same order.

aggregateAsset

Once your package module is instantiated from Meanio.Module (or class inherited from Meanio.Module), you will have the Module's aggregateAsset at hand. The method accepts 3 parameters:

  1. type of the asset (String, 'js' or 'css')
  2. path to the file to be aggregated (relative from the public/assets directory of your package directory root)
  3. (optional) options

The options parameter is a hash. It may have the following keys:

  • group - String, 'header' or 'footer'. Default value is 'footer'
  • inline - boolean, true or false. Default value is false. If true, Aggregation module will treat the path to the file as a String, and put that String verbatim into the aggregated result file.
  • url - String, url pointing to a remote css or js resource. Server will send a request to the url specified and put the response from the remote server verbatim into the aggregated result file. Default value is an empty string, so no request will be sent.

Suppressing the Aggregation

For debugging purposes, you may wish to turn the Aggregation functionality off. That is done by placing a aggregate:false key-value pair in the appropriate config file (in the config/env directory of your mean installation).

Suppressing the minification

Aggregation module minifies all the JavaScript resources by default. You may turn this feature off by placing a debug:true key-value pair in the appropriate config file (in the config/env directory of your mean installation).

Clone this wiki locally