|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +module.exports = function (grunt) { |
| 4 | + |
| 5 | + // Load grunt tasks automatically |
| 6 | + require('load-grunt-tasks')(grunt); |
| 7 | + |
| 8 | + /* |
| 9 | + * Time how long grunt tasks take to run, this might be important when having complex builds that take forever. |
| 10 | + * For now just to show how fancy grunt is. |
| 11 | + */ |
| 12 | + require('time-grunt')(grunt); |
| 13 | + |
| 14 | + // init required configurations for each task. |
| 15 | + grunt.initConfig({ |
| 16 | + |
| 17 | + // Project settings |
| 18 | + config: { |
| 19 | + path: { |
| 20 | + webapp: { |
| 21 | + root: 'src/main/webapp' |
| 22 | + }, |
| 23 | + temp: { |
| 24 | + root: 'temp' |
| 25 | + }, |
| 26 | + build: { |
| 27 | + root: 'build' |
| 28 | + } |
| 29 | + } |
| 30 | + }, |
| 31 | + |
| 32 | + // From grunt-contrib-clean |
| 33 | + clean: { |
| 34 | + build: [ |
| 35 | + '<%= config.path.temp.root %>', |
| 36 | + '<%= config.path.build.root %>' |
| 37 | + ] |
| 38 | + }, |
| 39 | + |
| 40 | + // From grunt-bower-install-simple. Downloads the web dependencies. |
| 41 | + "bower-install-simple": { |
| 42 | + options: { |
| 43 | + color: true, |
| 44 | + production: false |
| 45 | + } |
| 46 | + }, |
| 47 | + |
| 48 | + // From grunt-wiredep. Automatically inject Bower components into the HTML file |
| 49 | + wiredep: { |
| 50 | + target: { |
| 51 | + src: '<%= config.path.webapp.root %>/index.html', |
| 52 | + ignorePath: '<%= config.path.webapp.root %>' |
| 53 | + } |
| 54 | + }, |
| 55 | + |
| 56 | + // From grunt-contrib-concat. This is usefull when we have more than one css file, not the case now... |
| 57 | + /* |
| 58 | + concat: { |
| 59 | + styles: { |
| 60 | + src: [ |
| 61 | + '<%= config.path.webapp.root %>/css/style.css', |
| 62 | + ], |
| 63 | + dest: '<%= config.path.temp.root %>/concat/css/application.css' |
| 64 | + } |
| 65 | + }, |
| 66 | + */ |
| 67 | + |
| 68 | + // From grunt-contrib-copy. Copies remaining files to places other tasks can use |
| 69 | + copy: { |
| 70 | + build: { |
| 71 | + files: [ |
| 72 | + { |
| 73 | + src: '<%= config.path.webapp.root %>/index.html', |
| 74 | + dest: '<%= config.path.build.root %>/index.html' |
| 75 | + } |
| 76 | + ] |
| 77 | + } |
| 78 | + }, |
| 79 | + |
| 80 | + // From grunt-contrib-htmlmin. Minifies index.html file. |
| 81 | + htmlmin: { |
| 82 | + prod: { |
| 83 | + options: { |
| 84 | + collapseBooleanAttributes: true, |
| 85 | + collapseWhitespace: true, |
| 86 | + removeComments: true, |
| 87 | + removeCommentsFromCDATA: true, |
| 88 | + removeEmptyAttributes: true, |
| 89 | + removeOptionalTags: true, |
| 90 | + removeRedundantAttributes: true, |
| 91 | + useShortDoctype: true |
| 92 | + }, |
| 93 | + files: [ |
| 94 | + { |
| 95 | + expand: true, |
| 96 | + cwd: '<%= config.path.build.root %>', |
| 97 | + src: ['index.html'], |
| 98 | + dest: '<%= config.path.build.root %>' |
| 99 | + } |
| 100 | + ] |
| 101 | + } |
| 102 | + }, |
| 103 | + |
| 104 | + // From grunt-usemin. Reads HTML for usemin blocks to enable smart builds |
| 105 | + useminPrepare: { |
| 106 | + html: '<%= config.path.webapp.root %>/index.html', |
| 107 | + options: { |
| 108 | + staging: '<%= config.path.temp.root %>', |
| 109 | + root: '<%= config.path.webapp.root %>', |
| 110 | + dest: '<%= config.path.build.root %>' |
| 111 | + } |
| 112 | + }, |
| 113 | + |
| 114 | + // From grunt-usemin. |
| 115 | + usemin: { |
| 116 | + html: '<%= config.path.build.root %>/index.html' |
| 117 | + }, |
| 118 | + |
| 119 | + // From grunt-contrib-uglify. |
| 120 | + uglify: { |
| 121 | + options: { |
| 122 | + mangle: false |
| 123 | + } |
| 124 | + } |
| 125 | + } |
| 126 | + ); |
| 127 | + |
| 128 | + // Task: Build production version ready for deployment |
| 129 | + grunt.registerTask('build', [ |
| 130 | + 'clean:build', |
| 131 | + 'bower-install-simple', |
| 132 | + //'concat:styles', |
| 133 | + 'wiredep', |
| 134 | + 'useminPrepare', |
| 135 | + 'concat:generated', |
| 136 | + 'cssmin', |
| 137 | + 'uglify', |
| 138 | + 'copy:build', |
| 139 | + 'usemin', |
| 140 | + 'htmlmin' |
| 141 | + ]); |
| 142 | + |
| 143 | + grunt.registerTask('default', [ |
| 144 | + 'build' |
| 145 | + ]); |
| 146 | +}; |
0 commit comments