-
-
Save dariocravero/2e3060fdf63f77937f7e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is the main application configuration file. It is a Grunt | |
// configuration file, which you can learn more about here: | |
// https://github.com/cowboy/grunt/blob/master/docs/configuring.md | |
module.exports = function(grunt) { | |
'use strict'; | |
grunt.loadNpmTasks('grunt-contrib-clean'); | |
grunt.loadNpmTasks('grunt-contrib-compress'); | |
grunt.loadNpmTasks('grunt-contrib-concat'); | |
grunt.loadNpmTasks('grunt-contrib-copy'); | |
grunt.loadNpmTasks('grunt-contrib-jst'); | |
grunt.loadNpmTasks('grunt-contrib-jshint'); | |
grunt.loadNpmTasks('grunt-contrib-mincss'); | |
grunt.loadNpmTasks('grunt-contrib-uglify'); | |
grunt.loadNpmTasks('grunt-md5'); | |
grunt.loadTasks('tasks'); | |
grunt.initConfig({ | |
pkg: function() { return grunt.file.readJSON('fingerprinted.json'); }, | |
// The lint task will run the build configuration and the application | |
// JavaScript through JSHint and report any errors. You can change the | |
// options for this task, by reading this: | |
// https://github.com/cowboy/grunt/blob/master/docs/task_lint.md | |
jshint: { | |
files: [ | |
"build/config.js", "require.config.js", "app/**/*.js" | |
], | |
options: { | |
curly: true, | |
eqeqeq: true, | |
immed: true, | |
latedef: true, | |
newcap: true, | |
noarg: true, | |
sub: true, | |
boss: true, | |
eqnull: true, | |
browser: true, | |
// The jshint option for scripturl is set to lax, because the anchor | |
// override inside main.js needs to test for them so as to not accidentally | |
// route. | |
scripturl: true, | |
globals: { | |
require: true, | |
define: true, | |
requirejs: true, | |
describe: true, | |
expect: true, | |
it: true | |
} | |
} | |
}, | |
// The jst task compiles all application templates into JavaScript | |
// functions with the underscore.js template function from 1.2.4. You can | |
// change the namespace and the template options, by reading this: | |
// https://github.com/gruntjs/grunt-contrib/blob/master/docs/jst.md | |
// | |
// The concat task depends on this file to exist, so if you decide to | |
// remove this, ensure concat is updated accordingly. | |
jst: { | |
"dist/debug/templates.js": [ | |
"app/templates/**/*.html" | |
], | |
options: { | |
templateSettings: { | |
// We use mustache-like instead of ERB-like templates. | |
interpolate: /\{\{(.+?)\}\}/g | |
} | |
} | |
}, | |
// This task uses James Burke's excellent r.js AMD build tool. In the | |
// future other builders may be contributed as drop-in alternatives. | |
requirejs: { | |
// Include the main configuration file. | |
mainConfigFile: "app/config.js", | |
// Also include Bower's configuration file. | |
packagesConfig: "require.config.js", | |
// Output file. | |
out: "dist/debug/require.js", | |
// Root application module. | |
name: "config", | |
// Do not wrap everything in an IIFE. | |
wrap: false | |
}, | |
// The concatenate task is used here to merge the almond require/define | |
// shim and the templates into the application code. It's named | |
// dist/debug/require.js, because we want to only load one script file in | |
// index.html. | |
concat: { | |
dist: { | |
src: [ | |
"components/almond/almond.js", | |
"dist/debug/templates.js", | |
"dist/debug/require.js" | |
], | |
dest: "dist/debug/require.js", | |
separator: ";" | |
} | |
}, | |
// This task uses the MinCSS Node.js project to take all your CSS files in | |
// order and concatenate them into a single CSS file named index.css. It | |
// also minifies all the CSS as well. This is named index.css, because we | |
// only want to load one stylesheet in index.html. | |
mincss: { | |
"dist/release/alvaromatias.css": [ | |
"../../public/stylesheets/h5bp.css", | |
"../../public/stylesheets/animate.css", | |
"../../public/stylesheets/application.css" | |
] | |
}, | |
// Takes the built require.js file and minifies it for filesize benefits. | |
uglify: { | |
"dist/release/alvaromatias.js": [ | |
"dist/debug/require.js" | |
], | |
"dist/release/modernizr.js": [ | |
"components/modernizr/modernizr.js" | |
] | |
}, | |
// Add asset fingerprinting | |
md5: { | |
compile: { | |
files: { | |
"../../public": ["dist/release/alvaromatias.js", "dist/release/modernizr.js", "dist/release/alvaromatias.css"] | |
}, | |
options: { | |
callback: function(newPath, oldPath) { | |
var config, configFile = './fingerprinted.json', | |
path = require('path'), fingerprintedAsset, asset; | |
// FIXME, it might not be like that, i.e., the path might be something else | |
fingerprintedAsset = path.basename(newPath); | |
asset = path.basename(oldPath); | |
try { | |
config = require(configFile); | |
} catch (e) { | |
config = {files: {}}; | |
} | |
config.files[asset] = '/' + fingerprintedAsset; | |
grunt.file.write(configFile, JSON.stringify(config, null, 4)); | |
}, | |
keepBasename: true, | |
keepExtension: true | |
} | |
} | |
}, | |
// GZip assets | |
compress: { | |
zip: { | |
files: { | |
'../../public<%= pkg().files["alvaromatias.js"] %>.gz': '../../public<%= pkg().files["alvaromatias.js"] %>', | |
'../../public<%= pkg().files["modernizr.js"] %>.gz': '../../public<%= pkg().files["modernizr.js"] %>', | |
'../../public<%= pkg().files["alvaromatias.css"] %>.gz': '../../public<%= pkg().files["alvaromatias.css"] %>' | |
}, | |
level: 9 | |
} | |
}, | |
// Lint files automatically if watching... | |
watch: { | |
files: "<config:jshint.files>", | |
tasks: "jshint" | |
}, | |
// The clean task ensures all files are removed from the dist/ directory so | |
// that no files linger from previous builds. | |
clean: { | |
all: ['dist'] | |
} | |
}); | |
// The debug task will remove all contents inside the dist/ folder, lint | |
// all your code, precompile all the underscore templates into | |
// dist/debug/templates.js, compile all the application code into | |
// dist/debug/require.js, and then concatenate the require/define shim | |
// almond.js and dist/debug/templates.js into the require.js file. | |
grunt.registerTask("debug", ["clean", "jshint", "jst", "requirejs", "concat"]); | |
// The release task will run the debug tasks and then minify the | |
// dist/debug/require.js file and CSS files. | |
grunt.registerTask("release", ["debug", "uglify", "mincss", "md5", "compress"]); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment