Gruntfile.js
'use strict';
module.exports = function (grunt) {
// Add require for connect-modewrite
var modRewrite = require('connect-modrewrite');
// Define the configuration for all the tasks
grunt.initConfig({
// Project settings
bowerApp: {
// configurable app path
app: require('./bower.json').appPath || 'app'
},
// Watches files for changes and runs tasks based on the changed files
watch: {
js: {
files: ['<%= bowerApp.app %>/js/{,*/}*.js'],
options: {
livereload: true
}
},
styles: {
files: ['<%= bowerApp.app %>/css/{,*/}*.css'],
options: {
livereload: true
}
},
gruntfile: {
files: ['Gruntfile.js']
},
livereload: {
options: {
livereload: '<%= connect.options.livereload %>'
},
files: [
'<%= bowerApp.app %>/{,*/}*.html',
'<%= bowerApp.app %>/img/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
]
}
},
// The actual grunt server settings
connect: {
options: {
port: 9000,
// Change this to '0.0.0.0' to access the server from outside.
hostname: 'localhost',
livereload: 35729,
base: '<%= bowerApp.app %>'
},
livereload: {
options: {
open: 'http://localhost:<%= connect.options.port %>',
base: [
'.tmp',
'<%= bowerApp.app %>'
],
// MODIFIED: Add this middleware configuration
middleware: function (connect, options) {
var middlewares = [];
middlewares.push(modRewrite(['^[^\\.]*$ /index.html [L]'])); //Matches everything that does not contain a '.' (period)
options.base.forEach(function (base) {
middlewares.push(connect.static(base));
});
return middlewares;
}
}
}
},
clean: ['dist/'],
copy: {
files: {
expand: true,
cwd: 'src/main/',
src: ['**'],
dest: 'dist/'
}
},
uglify: {
main: {
files: {
'dist/template-prefetch.min.js': ['src/main/template-prefetch.js']
}
}
},
// Upload bower component
shell: {
bowerRegister: {
command: 'bower register ' + require('./bower.json').name + ' ' + require('./bower.json').repository.url
}
},
karma: {
unit: {
configFile: 'src/test/karma.conf.js'
},
continuous: {
configFile: 'src/test/karma.conf.js',
singleRun: true
}
}
});
// Load tasks
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-bower-install');
grunt.loadNpmTasks('grunt-express');
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-karma');
// Register new tasks
grunt.registerTask('serve', ['bowerInstall', 'connect', 'watch']);
grunt.registerTask('build', ['clean', 'copy', 'uglify']);
grunt.registerTask('publish', ['shell:bowerRegister']);
};