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 assetmanager
var assetslocals =require('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:"debug" //for jade
};
test.jade
each item in locals.assets.js
script(src=item)
each item in locals.assets.css
link(rel='stylesheet', href=item)
assets.json
{
"css": {
"public/build/css/main.min.css": [
"public/bower_components/bootstrap/dist/css/bootstrap.min.css",
"public/bower_components/bootstrap/dist/css/bootstrap-theme.min.css",
"public/css/main.css"
]
},
"js": {
"public/build/css/main.min.js": [
"public/bower_components/angular/angular.min.js",
"public/bower_components/angular-route/angular-route.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/holderjs/holder.js",
"public/js/app.js",
"public/js/services.js",
"public/js/controllers.js",
"public/js/filters.js",
"public/js/directives.js"
]
}
}
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/'
}
});
}
},
files: {
expand: true,
cwd: "src/views/",
src: ["*.jade", "partials/*.jade"],
dest: "public/",
ext: ".html"
}
}