node package manager

assetslocals

assetsLocals

combine assets.json file and locals.js, It can be used in jade and grunt.

合并assets.json和locals的内容,方便jade或是grunt调用.

assets.json AssetManager.

locals.js Expressjs app.locals.

install

$ npm install assetslocals
app.locals = assetslocals({
    localsFile: require('./config/locals'),
    assetmanagerOptions: {
        assets: require('./config/assets.json'),
        debug: (process.env.NODE_ENV !== 'production'),
        webroot: 'public/'
    }
});

locals.js

module.exports = {
  appName:"myApp",
  lang:"cn",
  title:"wow myApp",
  description:"balabala",
  pretty: true, //jade setting
  NODE_ENV:"development" //for jade
};

assets.json

{
  "vendor": {
    "css": {
      "bin/css/vendor.css": [
        "public/bower_components/angular-loading-bar/build/loading-bar.min.css",
        "public/bower_components/bootstrap/dist/css/bootstrap.min.css"
      ]
    },
    "js": {
      "bin/js/vendor.js": [
        "public/bower_components/angular/angular.min.js",
        "public/bower_components/angular-animate/angular-animate.min.js",
        "public/bower_components/angular-loading-bar/build/loading-bar.min.js",
        "public/bower_components/bootstrap/dist/js/bootstrap.min.js",
        "public/bower_components/angular-bootstrap/ui-bootstrap.min.js",
        "public/bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js",
        "public/bower_components/angular-ui-router/release/angular-ui-router.min.js"
      ]
    },
    "ie": {
      "bin/js/Modernizr-repond.js": [
        "public/bower_components/html5-boilerplate/js/vendor/modernizr-2.6.2.min.js",
        "public/bower_components/respond/dest/respond.min.js"
      ]
    }
  },
  "main": {
    "css": {
      "bin/css/main.css": ["public/css/main.css"]
    },
    "js": {
      "bin/js/main.js": [
        "public/js/*.js"
      ]
    }
  }
}

test.jade

each item in locals.assets.js
  script(src=item)
each item in locals.assets.css
  link(rel='stylesheet', href=item)

gruntfile.js jade config

jade: {
    options: {
        pretty: true,
        data: function(dest, src) {
            return require('assetsLocals')({
                localsFile: require('./config/locals'),
                assetmanagerOptions: {
                    assets: require('./config/assets.json'),
                    debug: (process.env.NODE_ENV !== 'production'),
                    webroot: 'public/'
                }
            });
        }
    }
}