move js & css files to public/manifest.json, allow for stylus files editing without restarting server on development, removed hashres from dev build

This commit is contained in:
Matteo Pagliazzi
2013-11-04 22:11:45 +01:00
parent 54225d38f1
commit d0c29eba78
6 changed files with 143 additions and 189 deletions

View File

@@ -1,4 +1,5 @@
/*global module:false*/ /*global module:false*/
var _ = require('lodash');
module.exports = function(grunt) { module.exports = function(grunt) {
// Project configuration. // Project configuration.
@@ -19,82 +20,6 @@ module.exports = function(grunt) {
build: ['build'] build: ['build']
}, },
uglify: {
buildApp: {
files: {
'build/app.js': [
'public/bower_components/jquery/jquery.min.js',
'public/bower_components/jquery.cookie/jquery.cookie.js',
'public/bower_components/bootstrap-growl/jquery.bootstrap-growl.min.js',
'public/bower_components/bootstrap-tour/build/js/bootstrap-tour.min.js',
'public/bower_components/angular/angular.min.js',
'public/bower_components/angular-sanitize/angular-sanitize.min.js',
'public/bower_components/marked/lib/marked.js',
'public/bower_components/angular-ui-router/release/angular-ui-router.js',
'public/bower_components/angular-resource/angular-resource.min.js',
'public/bower_components/angular-ui/build/angular-ui.min.js',
'public/bower_components/angular-ui-utils/modules/keypress/keypress.js',
'public/bower_components/angular-loading-bar/build/loading-bar.js',
// we'll remove this once angular-bootstrap is fixed
'public/bower_components/bootstrap/docs/assets/js/bootstrap.min.js',
'public/bower_components/angular-bootstrap/ui-bootstrap.min.js',
'public/bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js',
// Sortable
'public/bower_components/jquery-ui/ui/minified/jquery.ui.core.min.js',
'public/bower_components/jquery-ui/ui/minified/jquery.ui.widget.min.js',
'public/bower_components/jquery-ui/ui/minified/jquery.ui.mouse.min.js',
'public/bower_components/jquery-ui/ui/minified/jquery.ui.sortable.min.js',
// habitrpg-shared
'public/bower_components/habitrpg-shared/dist/habitrpg-shared.js',
// app
'public/js/app.js',
'public/js/services/authServices.js',
'public/js/services/notificationServices.js',
'public/js/services/sharedServices.js',
'public/js/services/userServices.js',
'public/js/services/groupServices.js',
'public/js/services/memberServices.js',
'public/js/services/guideServices.js',
'public/js/services/challengeServices.js',
'public/js/filters/filters.js',
'public/js/directives/directives.js',
'public/js/controllers/authCtrl.js',
'public/js/controllers/notificationCtrl.js',
'public/js/controllers/rootCtrl.js',
'public/js/controllers/settingsCtrl.js',
'public/js/controllers/headerCtrl.js',
'public/js/controllers/tasksCtrl.js',
'public/js/controllers/filtersCtrl.js',
'public/js/controllers/userCtrl.js',
'public/js/controllers/groupsCtrl.js',
'public/js/controllers/petsCtrl.js',
'public/js/controllers/inventoryCtrl.js',
'public/js/controllers/marketCtrl.js',
'public/js/controllers/footerCtrl.js',
'public/js/controllers/challengesCtrl.js'
]
}
},
buildStatic: {
files: {
'build/static.js': [
'public/bower_components/jquery/jquery.min.js',
'public/bower_components/habitrpg-shared/dist/habitrpg-shared.js',
'public/bower_components/angular/angular.min.js',
'public/bower_components/angular-resource/angular-resource.min.js',
'public/bower_components/bootstrap/docs/assets/js/bootstrap.min.js',
'public/bower_components/angular-loading-bar/build/loading-bar.js',
'public/js/static.js',
'public/js/services/userServices.js',
'public/js/controllers/authCtrl.js'
]
}
}
},
stylus: { stylus: {
build: { build: {
options: { options: {
@@ -109,19 +34,6 @@ module.exports = function(grunt) {
} }
}, },
cssmin: {
build: {
files: {
'build/app.css': ['build/app.css'],
'build/static.css': ['build/static.css'],
'build/bower_components/habitrpg-shared/dist/spritesheets.css': ['public/bower_components/habitrpg-shared/dist/spritesheets.css'],
'build/bower_components/bootstrap/docs/assets/css/bootstrap.css': ['public/bower_components/bootstrap/docs/assets/css/bootstrap.css'],
'build/bower_components/bootstrap/docs/assets/css/bootstrap-responsive.css': ['public/bower_components/bootstrap/docs/assets/css/bootstrap-responsive.css'],
'build/bower_components/bootstrap/docs/assets/css/docs.css': ['public/bower_components/bootstrap/docs/assets/css/docs.css']
}
}
},
copy: { copy: {
build: { build: {
files: [{expand: true, cwd: 'public/', src: 'favicon.ico', dest: 'build/'}] files: [{expand: true, cwd: 'public/', src: 'favicon.ico', dest: 'build/'}]
@@ -168,9 +80,31 @@ module.exports = function(grunt) {
}); });
//Load build files from public/manifest.json
grunt.registerTask('loadManifestFiles', 'Load all build files from public/manifest.json', function(){
var files = grunt.file.readJSON('./public/manifest.json');
var uglify = {};
var cssmin = {};
_.each(files, function(val, key){
var js = uglify['build/' + key + '.js'] = [];
_.each(files[key]['js'], function(val){
js.push('public/' + val);
});
_.each(files[key]['css'], function(val){
if(val == 'app.css' || val == 'static.css'){
cssmin['build/' + val] = ['build/' + val]
}else{
cssmin['build/' + val] = ['public/' + val]
}
});
});
grunt.config.set('uglify.build.files', uglify);
grunt.config.set('cssmin.build.files', cssmin);
});
// Register tasks. // Register tasks.
grunt.registerTask('build:prod', ['clean:build', 'uglify', 'stylus', 'cssmin', 'copy:build', 'hashres']); grunt.registerTask('build:prod', ['loadManifestFiles', 'clean:build', 'uglify', 'stylus', 'cssmin', 'copy:build', 'hashres']);
grunt.registerTask('build:dev', ['clean:build', 'stylus', 'cssmin', 'copy:build', 'hashres']); grunt.registerTask('build:dev', ['loadManifestFiles', 'clean:build', 'stylus', 'cssmin', 'copy:build']);
grunt.registerTask('run:dev', [ 'build:dev', 'concurrent' ]); grunt.registerTask('run:dev', [ 'build:dev', 'concurrent' ]);

83
public/manifest.json Normal file
View File

@@ -0,0 +1,83 @@
{
"app": {
"js": [
"bower_components/jquery/jquery.js",
"bower_components/bootstrap-growl/jquery.bootstrap-growl.js",
"bower_components/bootstrap-tour/build/js/bootstrap-tour.js",
"bower_components/angular/angular.js",
"bower_components/angular-sanitize/angular-sanitize.js",
"bower_components/marked/lib/marked.js",
"bower_components/angular-ui-router/release/angular-ui-router.js",
"bower_components/angular-resource/angular-resource.min.js",
"bower_components/angular-ui/build/angular-ui.js",
"bower_components/angular-ui-utils/modules/keypress/keypress.js",
"bower_components/angular-loading-bar/build/loading-bar.js",
"bower_components/bootstrap/docs/assets/js/bootstrap.js",
"bower_components/angular-bootstrap/ui-bootstrap.js",
"bower_components/angular-bootstrap/ui-bootstrap-tpls.js",
"bower_components/jquery-ui/ui/minified/jquery.ui.core.min.js",
"bower_components/jquery-ui/ui/minified/jquery.ui.widget.min.js",
"bower_components/jquery-ui/ui/minified/jquery.ui.mouse.min.js",
"bower_components/jquery-ui/ui/minified/jquery.ui.sortable.min.js",
"bower_components/habitrpg-shared/dist/habitrpg-shared.js",
"js/app.js",
"js/services/authServices.js",
"js/services/notificationServices.js",
"js/services/sharedServices.js",
"js/services/userServices.js",
"js/services/groupServices.js",
"js/services/memberServices.js",
"js/services/guideServices.js",
"js/services/challengeServices.js",
"js/filters/filters.js",
"js/directives/directives.js",
"js/controllers/authCtrl.js",
"js/controllers/notificationCtrl.js",
"js/controllers/rootCtrl.js",
"js/controllers/settingsCtrl.js",
"js/controllers/headerCtrl.js",
"js/controllers/tasksCtrl.js",
"js/controllers/filtersCtrl.js",
"js/controllers/userCtrl.js",
"js/controllers/groupsCtrl.js",
"js/controllers/petsCtrl.js",
"js/controllers/inventoryCtrl.js",
"js/controllers/marketCtrl.js",
"js/controllers/footerCtrl.js",
"js/controllers/challengesCtrl.js"
],
"css": [
"bower_components/bootstrap/docs/assets/css/bootstrap.css",
"app.css",
"bower_components/habitrpg-shared/dist/spritesheets.css"
]
},
"static": {
"js": [
"bower_components/jquery/jquery.js",
"bower_components/habitrpg-shared/dist/habitrpg-shared.js",
"bower_components/angular/angular.js",
"bower_components/bootstrap/docs/assets/js/bootstrap.js",
"bower_components/angular-loading-bar/build/loading-bar.js",
"js/static.js",
"js/services/userServices.js",
"js/controllers/authCtrl.js"
],
"css": [
"bower_components/bootstrap/docs/assets/css/bootstrap.css",
"bower_components/bootstrap/docs/assets/css/bootstrap-responsive.css",
"bower_components/bootstrap/docs/assets/css/docs.css",
"static.css"
]
}
}

View File

@@ -54,9 +54,35 @@ var walk = function(folder){
walk(path.join(__dirname, "/../build")); walk(path.join(__dirname, "/../build"));
var getBuildUrl = function(url){ var getBuildUrl = function(url){
if(buildFiles[url]) return buildFiles[url]; console.log(url, buildFiles[url])
if(buildFiles[url]) return '/' + buildFiles[url];
return '/' + url;
}
var manifestFiles = require("../public/manifest.json");
var getManifestFiles = function(page){
var files = manifestFiles[page];
if(!files) throw new Error("Page not found!");
var css = '';
_.each(files.css, function(file){
css += '<link rel="stylesheet" type="text/css" href="' + getBuildUrl(file) + '">';
});
if(nconf.get('NODE_ENV') === 'production'){
return css + '<script type="text/javascript" src="' + getBuildUrl(page + '.js') + '"></script>';
}else{
var results = css;
_.each(files.js, function(file){
results += '<script type="text/javascript" src="' + getBuildUrl(file) + '"></script>';
});
return results;
}
return url;
} }
module.exports.locals = function(req, res, next) { module.exports.locals = function(req, res, next) {
@@ -67,6 +93,7 @@ module.exports.locals = function(req, res, next) {
PAYPAL_MERCHANT: nconf.get('PAYPAL_MERCHANT'), PAYPAL_MERCHANT: nconf.get('PAYPAL_MERCHANT'),
IS_MOBILE: /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(req.header('User-Agent')), IS_MOBILE: /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(req.header('User-Agent')),
STRIPE_PUB_KEY: nconf.get('STRIPE_PUB_KEY'), STRIPE_PUB_KEY: nconf.get('STRIPE_PUB_KEY'),
getManifestFiles: getManifestFiles,
getBuildUrl: getBuildUrl getBuildUrl: getBuildUrl
}); });
next() next()

View File

@@ -101,8 +101,8 @@ app.use(passport.session());
app.use(app.router); app.use(app.router);
var oneYear = 31536000000; var maxAge = (nconf.get('NODE_ENV') === 'production') ? 31536000000 : 0;
app.use(express['static'](path.join(__dirname, "/../build"), { maxAge: oneYear })); app.use(express['static'](path.join(__dirname, "/../build"), { maxAge: maxAge }));
app.use(express['static'](path.join(__dirname, "/../public"))); app.use(express['static'](path.join(__dirname, "/../public")));
// development only // development only

View File

@@ -4,7 +4,7 @@ html
title HabitRPG | Your Life The Role Playing Game title HabitRPG | Your Life The Role Playing Game
// ?v=1 needed to force refresh // ?v=1 needed to force refresh
link(rel='shortcut icon' href='/#{env.getBuildUrl("favicon.ico")}?v=2') link(rel='shortcut icon' href='#{env.getBuildUrl("favicon.ico")}?v=2')
script(type='text/javascript'). script(type='text/javascript').
window.env = !{JSON.stringify(env)}; window.env = !{JSON.stringify(env)};
@@ -14,74 +14,7 @@ html
display: none; display: none;
} }
// CSS Remember to update also in Grunfile.js cssmin task! != env.getManifestFiles("app")
link(rel='stylesheet', href='/#{env.getBuildUrl("bower_components/bootstrap/docs/assets/css/bootstrap.css")}')
link(rel='stylesheet', href='/#{env.getBuildUrl("app.css")}')
// HabitRPG Shared
link(rel='stylesheet', href='/#{env.getBuildUrl("bower_components/habitrpg-shared/dist/spritesheets.css")}')
- if(env.NODE_ENV == 'production'){
script(type='text/javascript', src='/#{env.getBuildUrl("app.js")}')
- }else{
// Remember to update the file list in Gruntfile.js!
script(type='text/javascript', src='/bower_components/jquery/jquery.min.js')
script(type='text/javascript', src='/bower_components/jquery.cookie/jquery.cookie.js')
script(type='text/javascript', src='/bower_components/bootstrap-growl/jquery.bootstrap-growl.min.js')
script(type='text/javascript', src='/bower_components/bootstrap-tour/build/js/bootstrap-tour.min.js')
script(type='text/javascript', src='/bower_components/angular/angular.js')
script(type='text/javascript', src='/bower_components/angular-ui-router/release/angular-ui-router.js')
script(type='text/javascript', src='/bower_components/angular-sanitize/angular-sanitize.min.js')
script(type='text/javascript', src='/bower_components/marked/lib/marked.js')
script(type='text/javascript', src='/bower_components/angular-resource/angular-resource.js')
script(type='text/javascript', src='/bower_components/angular-ui/build/angular-ui.js')
script(type='text/javascript', src='/bower_components/angular-ui-utils/modules/keypress/keypress.js')
script(type='text/javascript', src='/bower_components/angular-loading-bar/build/loading-bar.js')
// we'll remove this once angular-bootstrap is fixed
script(type='text/javascript', src='/bower_components/bootstrap/docs/assets/js/bootstrap.min.js')
script(type='text/javascript', src='/bower_components/angular-bootstrap/ui-bootstrap.min.js')
script(type='text/javascript', src='/bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js')
// Sortable
script(type='text/javascript', src='/bower_components/jquery-ui/ui/minified/jquery.ui.core.min.js')
script(type='text/javascript', src='/bower_components/jquery-ui/ui/minified/jquery.ui.widget.min.js')
script(type='text/javascript', src='/bower_components/jquery-ui/ui/minified/jquery.ui.mouse.min.js')
script(type='text/javascript', src='/bower_components/jquery-ui/ui/minified/jquery.ui.sortable.min.js')
// habitrpg-shared
script(type='text/javascript', src='/bower_components/habitrpg-shared/dist/habitrpg-shared.js')
// app
script(type='text/javascript', src='/js/app.js')
script(type='text/javascript', src='/js/services/authServices.js')
script(type='text/javascript', src='/js/services/notificationServices.js')
script(type='text/javascript', src='/js/services/sharedServices.js')
script(type='text/javascript', src='/js/services/userServices.js')
script(type='text/javascript', src='/js/services/groupServices.js')
script(type='text/javascript', src='/js/services/memberServices.js')
script(type='text/javascript', src='/js/services/guideServices.js')
script(type='text/javascript', src='/js/services/challengeServices.js')
script(type='text/javascript', src='/js/filters/filters.js')
script(type='text/javascript', src='/js/directives/directives.js')
script(type='text/javascript', src='/js/controllers/authCtrl.js')
script(type='text/javascript', src='/js/controllers/notificationCtrl.js')
script(type='text/javascript', src='/js/controllers/rootCtrl.js')
script(type='text/javascript', src='/js/controllers/settingsCtrl.js')
script(type='text/javascript', src='/js/controllers/headerCtrl.js')
script(type='text/javascript', src='/js/controllers/tasksCtrl.js')
script(type='text/javascript', src='/js/controllers/filtersCtrl.js')
script(type='text/javascript', src='/js/controllers/userCtrl.js')
script(type='text/javascript', src='/js/controllers/groupsCtrl.js')
script(type='text/javascript', src='/js/controllers/petsCtrl.js')
script(type='text/javascript', src='/js/controllers/inventoryCtrl.js')
script(type='text/javascript', src='/js/controllers/marketCtrl.js')
script(type='text/javascript', src='/js/controllers/footerCtrl.js')
script(type='text/javascript', src='/js/controllers/challengesCtrl.js')
-}
//webfonts //webfonts
link(href='//fonts.googleapis.com/css?family=Lato:300,400,700,400italic,700italic', rel='stylesheet', type='text/css') link(href='//fonts.googleapis.com/css?family=Lato:300,400,700,400italic,700italic', rel='stylesheet', type='text/css')

View File

@@ -7,35 +7,12 @@ html
block title block title
title HabitRPG | Your Life the Role Playing Game title HabitRPG | Your Life the Role Playing Game
link(rel='shortcut icon', href='/#{env.getBuildUrl("favicon.ico")}?v=2') link(rel='shortcut icon', href='#{env.getBuildUrl("favicon.ico")}?v=2')
meta(charset='utf-8') meta(charset='utf-8')
meta(name='viewport', content='width=device-width, initial-scale=1.0') meta(name='viewport', content='width=device-width, initial-scale=1.0')
// CSS Remember to update also in Grunfile.js cssmin task! != env.getManifestFiles("static")
link(rel='stylesheet', href='/#{env.getBuildUrl("bower_components/bootstrap/docs/assets/css/bootstrap.css")}')
// Keep this out of build because the one after has some images and would like not to override it
link(rel='stylesheet', href='/#{env.getBuildUrl("bower_components/bootstrap/docs/assets/css/bootstrap-responsive.css")}')
link(rel='stylesheet', href='/#{env.getBuildUrl("bower_components/bootstrap/docs/assets/css/docs.css")}')
link(rel='stylesheet', href='/#{env.getBuildUrl("static.css")}')
// JS
- if(layoutEnv.NODE_ENV == 'production'){
script(type='text/javascript', src='/#{env.getBuildUrl("static.js")}')
- }else{
// Remember to update the file list in Gruntfile.js!
script(type='text/javascript', src='/bower_components/jquery/jquery.min.js')
script(type='text/javascript', src='/bower_components/habitrpg-shared/dist/habitrpg-shared.js')
script(type='text/javascript', src='/bower_components/angular/angular.min.js')
script(type='text/javascript', src='/bower_components/angular-resource/angular-resource.min.js')
script(type='text/javascript', src='/bower_components/bootstrap/docs/assets/js/bootstrap.min.js')
script(type='text/javascript', src='/bower_components/angular-loading-bar/build/loading-bar.js')
script(type='text/javascript', src='/js/static.js')
script(type='text/javascript', src='/js/services/userServices.js')
script(type='text/javascript', src='/js/controllers/authCtrl.js')
-}
script(type='text/javascript'). script(type='text/javascript').
$.getScript("//s7.addthis.com/js/250/addthis_widget.js#pubid=lefnire"); $.getScript("//s7.addthis.com/js/250/addthis_widget.js#pubid=lefnire");