Created
December 21, 2015 10:02
-
-
Save s-leroux/ad334683b6367d66b718 to your computer and use it in GitHub Desktop.
Cousera "Front-End JavaScript Frameworks: AngularJS" course -- Gruntfile.js at the end of the course
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
'use strict'; | |
module.exports = function (grunt) { | |
// Time how long tasks take. Can help when optimizing build times | |
require('time-grunt')(grunt); | |
// Automatically load required Grunt tasks | |
require('jit-grunt')(grunt, { | |
useminPrepare: 'grunt-usemin' | |
}); | |
// Define the configuration for all the tasks | |
grunt.initConfig({ | |
pkg: grunt.file.readJSON('package.json'), | |
// Make sure code styles are up to par and there are no obvious mistakes | |
jshint: { | |
options: { | |
jshintrc: '.jshintrc', | |
reporter: require('jshint-stylish') | |
}, | |
all: { | |
src: [ | |
'Gruntfile.js', | |
'app/scripts/{,*/}*.js' | |
] | |
} | |
}, | |
copy: { | |
dist: { | |
cwd: 'app', | |
src: [ '**','!styles/**/*.css','!scripts/**/*.js' ], | |
dest: 'dist', | |
expand: true | |
}, | |
fonts: { | |
files:[ | |
{ | |
//for bootstrap fonts | |
expand: true, | |
dot: true, | |
cwd: 'bower_components/bootstrap/dist', | |
src: ['fonts/*.*'], | |
dest: 'dist' | |
}, { | |
//for font-awesome | |
expand: true, | |
dot: true, | |
cwd: 'bower_components/font-awesome', | |
src: ['fonts/*.*'], | |
dest: 'dist' | |
} | |
] | |
} | |
}, | |
clean: { | |
build:{ | |
src: [ 'dist/'] | |
} | |
}, | |
useminPrepare: { | |
html: 'app/menu.html', | |
options: { | |
dest: 'dist' | |
} | |
}, | |
// Concat | |
concat: { | |
options: { | |
separator: ';' | |
}, | |
// dist configuration is provided by useminPrepare | |
dist: {} | |
}, | |
// Uglify | |
uglify: { | |
// dist configuration is provided by useminPrepare | |
dist: {} | |
}, | |
cssmin: { | |
dist: {} | |
}, | |
// Filerev | |
filerev: { | |
options: { | |
encoding: 'utf8', | |
algorithm: 'md5', | |
length: 20 | |
}, | |
release: { | |
// filerev:release hashes(md5) all assets (images, js and css ) | |
// in dist directory | |
files: [{ | |
src: [ | |
'dist/scripts/*.js', | |
'dist/styles/*.css', | |
] | |
}] | |
} | |
}, | |
// Usemin | |
// Replaces all assets with their revved version in html and css files. | |
// options.assetDirs contains the directories for finding the assets | |
// according to their relative paths | |
usemin: { | |
html: ['dist/*.html'], | |
css: ['dist/styles/*.css'], | |
options: { | |
assetsDirs: ['dist', 'dist/styles'] | |
} | |
}, | |
watch: { | |
copy: { | |
files: [ 'app/**', '!app/**/*.css', '!app/**/*.js'], | |
tasks: [ 'build' ] | |
}, | |
scripts: { | |
files: ['app/scripts/app.js'], | |
tasks:[ 'build'] | |
}, | |
styles: { | |
files: ['app/styles/mystyles.css'], | |
tasks:['build'] | |
}, | |
livereload: { | |
options: { | |
livereload: '<%= connect.options.livereload %>' | |
}, | |
files: [ | |
'app/{,*/}*.html', | |
'.tmp/styles/{,*/}*.css', | |
'app/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}' | |
] | |
} | |
}, | |
connect: { | |
options: { | |
port: 9000, | |
// Change this to '0.0.0.0' to access the server from outside. | |
hostname: 'localhost', | |
livereload: 35729 | |
}, | |
dist: { | |
options: { | |
open: true, | |
base:{ | |
path: 'dist', | |
options: { | |
index: 'menu.html', | |
maxAge: 300000 | |
} | |
} | |
} | |
} | |
}, | |
}); | |
grunt.registerTask('serve',['build','connect:dist','watch']); | |
grunt.registerTask('default',['build']); | |
grunt.registerTask('build', [ | |
'jshint', | |
'clean', | |
'useminPrepare', | |
'concat', | |
'cssmin', | |
'uglify', | |
'copy', | |
'filerev', | |
'usemin', | |
]); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment