241 lines
7 KiB
JavaScript
241 lines
7 KiB
JavaScript
'use strict';
|
|
|
|
/*global module:false*/
|
|
module.exports = function (grunt) {
|
|
// Time how long tasks take. Can help when optimizing build times
|
|
require('time-grunt')(grunt);
|
|
|
|
// Configurable paths
|
|
var config = {
|
|
app: 'app',
|
|
dist: 'dist'
|
|
};
|
|
|
|
// Project configuration.
|
|
grunt.initConfig({
|
|
// Project settings
|
|
config: config,
|
|
|
|
// Metadata.
|
|
pkg: grunt.file.readJSON('package.json'),
|
|
|
|
banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
|
|
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
|
|
'<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
|
|
'* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
|
|
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n',
|
|
|
|
// Task configuration.
|
|
concat: {
|
|
options: {
|
|
banner: '<%= banner %>',
|
|
stripBanners: true
|
|
},
|
|
dist: {
|
|
src: ['<%= config.app %>/lib/<%= pkg.name %>.js'],
|
|
dest: 'dist/<%= pkg.name %>.js'
|
|
}
|
|
},
|
|
|
|
uglify: {
|
|
options: {
|
|
banner: '<%= banner %>'
|
|
},
|
|
dist: {
|
|
src: '<%= concat.dist.dest %>',
|
|
dest: 'dist/<%= pkg.name %>.min.js'
|
|
}
|
|
},
|
|
|
|
jshint: {
|
|
options: {
|
|
curly: true,
|
|
eqeqeq: true,
|
|
immed: true,
|
|
latedef: true,
|
|
newcap: true,
|
|
noarg: true,
|
|
sub: true,
|
|
undef: true,
|
|
unused: true,
|
|
boss: true,
|
|
eqnull: true,
|
|
browser: true,
|
|
globals: {
|
|
jQuery: true
|
|
}
|
|
},
|
|
gruntfile: {
|
|
src: 'Gruntfile.js'
|
|
},
|
|
lib_test: {
|
|
src: ['<%= config.app %>/lib/**/*.js', 'test/**/*.js']
|
|
}
|
|
},
|
|
|
|
watch: {
|
|
bower: {
|
|
files: ['bower.json'],
|
|
tasks: ['wiredep']
|
|
},
|
|
js: {
|
|
files: ['<%= config.app %>/scripts/{,*/}*.js'],
|
|
tasks: ['jshint'],
|
|
options: {
|
|
livereload: true
|
|
}
|
|
},
|
|
styles: {
|
|
files: ['<%= config.app %>/styles/{,*/}*.css'],
|
|
tasks: ['newer:copy:styles', 'autoprefixer']
|
|
},
|
|
livereload: {
|
|
options: {
|
|
livereload: '<%= connect.options.livereload %>'
|
|
},
|
|
files: [
|
|
'<%= config.app %>/{,*/}*.html',
|
|
'.tmp/styles/{,*/}*.css',
|
|
'<%= config.app %>/img/{,*/}*'
|
|
]
|
|
},
|
|
gruntfile: {
|
|
files: '<%= jshint.gruntfile.src %>',
|
|
},
|
|
},
|
|
|
|
clean: {
|
|
dist: {
|
|
files: [{
|
|
dot: true,
|
|
src: [
|
|
'.tmp',
|
|
'<%= config.dist %>/*'
|
|
]
|
|
}]
|
|
},
|
|
server: '.tmp'
|
|
},
|
|
|
|
// Automatically inject Bower components into the HTML file
|
|
wiredep: {
|
|
app: {
|
|
ignorePath: /^\/|\.\.\//,
|
|
src: ['<%= config.app %>/index.html'],
|
|
/*exclude: ['bower_components/bootstrap/dist/js/bootstrap.js']*/
|
|
}
|
|
},
|
|
|
|
// Run some tasks in parallel to speed up build process
|
|
concurrent: {
|
|
server: [
|
|
'copy:styles'
|
|
]
|
|
},
|
|
|
|
// Add vendor prefixed styles
|
|
autoprefixer: {
|
|
options: {
|
|
browsers: ['> 1%', 'last 2 versions', 'Firefox ESR', 'Opera 12.1']
|
|
},
|
|
dist: {
|
|
files: [{
|
|
expand: true,
|
|
cwd: '.tmp/styles/',
|
|
src: '{,*/}*.css',
|
|
dest: '.tmp/styles/'
|
|
}]
|
|
}
|
|
},
|
|
|
|
// The actual grunt server settings
|
|
connect: {
|
|
options: {
|
|
port: 8090,
|
|
open: true,
|
|
livereload: 35729,
|
|
// Change this to '0.0.0.0' to access the server from outside
|
|
hostname: 'localhost'
|
|
},
|
|
livereload: {
|
|
options: {
|
|
middleware: function (connect) {
|
|
return [
|
|
connect.static('.tmp'),
|
|
connect().use('/bower_components', connect.static('./bower_components')),
|
|
connect.static(config.app)
|
|
];
|
|
}
|
|
}
|
|
},
|
|
dist: {
|
|
options: {
|
|
base: '<%= config.dist %>',
|
|
livereload: false
|
|
}
|
|
}
|
|
},
|
|
|
|
// Copies remaining files to places other tasks can use
|
|
copy: {
|
|
dist: {
|
|
files: [{
|
|
expand: true,
|
|
dot: true,
|
|
cwd: '<%= config.app %>',
|
|
dest: '<%= config.dist %>',
|
|
src: [
|
|
'*.{ico,png,txt}',
|
|
'{,*/}*.html',
|
|
'fonts/{,*/}*.*'
|
|
]
|
|
}, {
|
|
src: '<%= config.app %>/.htaccess',
|
|
dest: '<%= config.dist %>/.htaccess'
|
|
}]
|
|
},
|
|
styles: {
|
|
expand: true,
|
|
dot: true,
|
|
cwd: '<%= config.app %>/styles',
|
|
dest: '.tmp/styles/',
|
|
src: '{,*/}*.css'
|
|
}
|
|
},
|
|
});
|
|
|
|
// These plugins provide necessary tasks.
|
|
grunt.loadNpmTasks('grunt-contrib-concat');
|
|
grunt.loadNpmTasks('grunt-contrib-uglify');
|
|
grunt.loadNpmTasks('grunt-contrib-jshint');
|
|
grunt.loadNpmTasks('grunt-contrib-watch');
|
|
grunt.loadNpmTasks('grunt-contrib-clean');
|
|
grunt.loadNpmTasks('grunt-wiredep');
|
|
grunt.loadNpmTasks('grunt-concurrent');
|
|
grunt.loadNpmTasks('grunt-autoprefixer');
|
|
grunt.loadNpmTasks('grunt-contrib-connect');
|
|
grunt.loadNpmTasks('grunt-contrib-copy');
|
|
grunt.loadNpmTasks('grunt-newer');
|
|
|
|
// Default task.
|
|
//grunt.registerTask('default', ['jshint', 'concat', 'uglify']);
|
|
|
|
grunt.registerTask('serve', 'start the server and preview your app, --allow-remote for remote access', function (target) {
|
|
if (grunt.option('allow-remote')) {
|
|
grunt.config.set('connect.options.hostname', '0.0.0.0');
|
|
}
|
|
/*if (target === 'dist') {
|
|
return grunt.task.run(['build', 'connect:dist:keepalive']);
|
|
}*/
|
|
|
|
grunt.task.run([
|
|
'clean:server',
|
|
'wiredep',
|
|
'concurrent:server',
|
|
'autoprefixer',
|
|
'connect:livereload',
|
|
'watch'
|
|
]);
|
|
});
|
|
|
|
};
|