123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- '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'
- ]);
- });
- };
|