Created
November 10, 2014 16:13
-
-
Save rohn/ae9d7096ec485c9e9b19 to your computer and use it in GitHub Desktop.
more extensive Gruntfile
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) { | |
// | |
// Load Tasks | |
// | |
require('load-grunt-tasks')(grunt, [ | |
'grunt-*', | |
'time-grunt' | |
]); | |
// | |
// Configure Tasks | |
// | |
grunt.initConfig({ | |
// Watch for changes | |
watch: { | |
dev: { | |
options: { | |
livereload: true | |
}, | |
files: [ | |
// Scripts | |
'Gruntfile.js', | |
'src/client/scripts/**/*.js', | |
'test/spec/**/*.js', | |
// Styles | |
'src/client/styles/**/*.{css,scss,sass}', | |
'src/client/images/*', | |
'src/client/fonts/*', | |
// Views | |
'src/index.html', | |
'src/client/views/**/*.html' | |
], | |
tasks: [ | |
'build' | |
] | |
} | |
}, | |
// Connection settings | |
connect: { | |
options: { | |
port: 9000, | |
hostname: 'localhost', | |
livereload: 35729 | |
}, | |
src: { | |
options: { | |
base: 'src' | |
} | |
}, | |
dist: { | |
options: { | |
base: 'dist' | |
} | |
}, | |
test: { | |
options: { | |
port: 9001, | |
base: [ | |
'src', | |
'test' | |
] | |
} | |
}, | |
buildtest: { | |
options: { | |
port: 9001, | |
base: [ | |
'dist', | |
'test' | |
] | |
} | |
} | |
}, | |
// Code style enforcement | |
jshint: { | |
options: { | |
reporter: require('jshint-stylish') | |
}, | |
test: { | |
options: { | |
jshintrc: 'test/config/.jshintrc' | |
}, | |
src: [ | |
'test/spec/**/*.js' | |
] | |
}, | |
dist: { | |
options: { | |
jshintrc: '.jshintrc' | |
}, | |
src: [ | |
'Gruntfile.js', | |
'src/client/scripts/**/*.js' | |
] | |
} | |
}, | |
// Protractor test runner | |
protractor: { | |
test: { | |
// passive testing, use phantomjs | |
// @todo right now it just uses chrome to avoid complicated setup | |
configFile: 'test/config/protractor/passive.js', | |
keepAlive: true | |
}, | |
buildtest: { | |
// aggressive testing, use multiple browsers | |
configFile: 'test/config/protractor/aggressive.js', | |
keepAlive: false | |
} | |
}, | |
// Clean up before tasks | |
clean: { | |
dist: { | |
files: [{ | |
dot: true, | |
src: [ | |
'.tmp', | |
'dist' | |
] | |
}] | |
}, | |
server: '.tmp' | |
}, | |
// Copy source files | |
copy: { | |
dist: { | |
files: [{ | |
expand: true, | |
dot: true, | |
cwd: 'src', | |
dest: 'dist', | |
src: [ | |
'*.{html,txt,ico,png}', | |
'client/*.{ico,png}', | |
'client/fonts/*', | |
'client/images/*', | |
'client/dev.js' | |
] | |
}, { | |
expand: true, | |
cwd: '.tmp/client/images', | |
dest: 'dist/client/images', | |
src: ['generated/*'] | |
}] | |
} | |
}, | |
// Scan markup for automatic build config | |
useminPrepare: { | |
html: 'src/index.html', | |
options: { dest: 'dist' } | |
}, | |
// Adjust markup to reference minified and revisioned files | |
usemin: { | |
html: ['dist/**/*.html'], | |
css: ['dist/client/styles/**/*.css'] | |
}, | |
// Protect ng references from minification | |
ngmin: { | |
dist: { | |
files: [{ | |
expand: true, | |
cwd: '.tmp/concat/scripts', | |
src: '*.js', | |
dest: '.tmp/concat/scripts' | |
}] | |
} | |
}, | |
// Minify markup | |
htmlmin: { | |
dist: { | |
options: { | |
removeComments: true, | |
collapseWhitespace: true, | |
collapseBooleanAttributes: true, | |
removeRedundantAttributes: true | |
}, | |
files: [{ | |
expand: true, | |
cwd: 'dist', | |
src: 'index.html', | |
dest: 'dist' | |
}] | |
} | |
}, | |
// Compile angular templates | |
ngtemplates: { | |
dist: { | |
options: { | |
module: 'weatherplan', | |
htmlmin: '<%= htmlmin.dist %>', | |
usemin: 'client/scripts/app.js' | |
}, | |
cwd: 'src', | |
src: [ | |
'client/views/**/*.html' | |
], | |
dest: '.tmp/client/views.js' | |
} | |
}, | |
// Minify images | |
imagemin: { | |
dist: { | |
files: [{ | |
expand: true, | |
cwd: 'src/client/images', | |
src: '**/*.{png,jpg,jpeg,gif}', | |
dest: 'dist/client/images' | |
}] | |
} | |
}, | |
// Minify svg files | |
svgmin: { | |
dist: { | |
files: [{ | |
expand: true, | |
cwd: 'src/client/images', | |
src: '**/*.svg', | |
dest: 'dist/client/images' | |
}] | |
} | |
}, | |
// Renames files for browser caching purposes | |
rev: { | |
dist: { | |
files: { | |
src: [ | |
'dist/client/scripts/**/*.js', | |
'dist/client/styles/**/*.css', | |
'dist/client/images/**/*.{png,jpg,jpeg,gif,svg}', | |
'dist/client/fonts/*' | |
] | |
} | |
} | |
}, | |
// Compile Sass | |
sass: { | |
dist: { | |
src: 'src/client/styles/main.scss', | |
dest: '.tmp/client/styles/main.css' | |
} | |
}, | |
// Automatically convert data uri images | |
// turn: "url(../images/data-uri/some.png)" | |
// into: "url(data:image/png;base64,...)" | |
dataUri: { | |
dist: { | |
src: 'dist/client/styles/main.css', | |
dest: 'dist/client/styles/main.css', | |
options: { | |
target: 'dist/client/images/data-uri/*', | |
fixDirLevel: true | |
} | |
} | |
} | |
}); | |
// | |
// Register Tasks | |
// | |
// $> grunt build | |
// Compile the dist tree from src tree | |
grunt.registerTask('build', [ | |
'clean:dist', | |
'useminPrepare', | |
'sass:dist', | |
'ngtemplates', | |
'concat', | |
'ngmin', | |
'copy:dist', | |
'cssmin', | |
'uglify', | |
'rev', | |
'usemin', | |
'dataUri', | |
'htmlmin' | |
]); | |
// $> grunt test | |
// Runs unit tests against the src tree | |
// Use this during development then use buildtest prior to production | |
grunt.registerTask('test', [ | |
'newer:jshint:dist', | |
'newer:jshint:test', | |
'connect:test', | |
'protractor:test' | |
]); | |
// $> grunt buildtest | |
// Runs unit tests against the dist tree | |
// Use this to ensure the build process doesn't break the build | |
grunt.registerTask('buildtest', [ | |
'newer:jshint:dist', | |
'newer:jshint:test', | |
'build', | |
'connect:buildtest', | |
'protractor:buildtest' | |
]); | |
// $> grunt serve | |
// Build from source then host application | |
grunt.registerTask('serve', [ | |
'build', | |
'connect:dist:keepalive' | |
]); | |
grunt.registerTask('default', ['serve']); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment