Gruntfile.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. 'use strict';
  2. /*global module:false*/
  3. module.exports = function (grunt) {
  4. // Time how long tasks take. Can help when optimizing build times
  5. require('time-grunt')(grunt);
  6. // Configurable paths
  7. var config = {
  8. app: 'app',
  9. dist: 'dist'
  10. };
  11. // Project configuration.
  12. grunt.initConfig({
  13. // Project settings
  14. config: config,
  15. // Metadata.
  16. pkg: grunt.file.readJSON('package.json'),
  17. banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
  18. '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
  19. '<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
  20. '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
  21. ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n',
  22. // Task configuration.
  23. concat: {
  24. options: {
  25. banner: '<%= banner %>',
  26. stripBanners: true
  27. },
  28. dist: {
  29. src: ['<%= config.app %>/lib/<%= pkg.name %>.js'],
  30. dest: 'dist/<%= pkg.name %>.js'
  31. }
  32. },
  33. uglify: {
  34. options: {
  35. banner: '<%= banner %>'
  36. },
  37. dist: {
  38. src: '<%= concat.dist.dest %>',
  39. dest: 'dist/<%= pkg.name %>.min.js'
  40. }
  41. },
  42. jshint: {
  43. options: {
  44. curly: true,
  45. eqeqeq: true,
  46. immed: true,
  47. latedef: true,
  48. newcap: true,
  49. noarg: true,
  50. sub: true,
  51. undef: true,
  52. unused: true,
  53. boss: true,
  54. eqnull: true,
  55. browser: true,
  56. globals: {
  57. jQuery: true
  58. }
  59. },
  60. gruntfile: {
  61. src: 'Gruntfile.js'
  62. },
  63. lib_test: {
  64. src: ['<%= config.app %>/lib/**/*.js', 'test/**/*.js']
  65. }
  66. },
  67. watch: {
  68. bower: {
  69. files: ['bower.json'],
  70. tasks: ['wiredep']
  71. },
  72. js: {
  73. files: ['<%= config.app %>/scripts/{,*/}*.js'],
  74. tasks: ['jshint'],
  75. options: {
  76. livereload: true
  77. }
  78. },
  79. styles: {
  80. files: ['<%= config.app %>/styles/{,*/}*.css'],
  81. tasks: ['newer:copy:styles', 'autoprefixer']
  82. },
  83. livereload: {
  84. options: {
  85. livereload: '<%= connect.options.livereload %>'
  86. },
  87. files: [
  88. '<%= config.app %>/{,*/}*.html',
  89. '.tmp/styles/{,*/}*.css',
  90. '<%= config.app %>/img/{,*/}*'
  91. ]
  92. },
  93. gruntfile: {
  94. files: '<%= jshint.gruntfile.src %>',
  95. },
  96. },
  97. clean: {
  98. dist: {
  99. files: [{
  100. dot: true,
  101. src: [
  102. '.tmp',
  103. '<%= config.dist %>/*'
  104. ]
  105. }]
  106. },
  107. server: '.tmp'
  108. },
  109. // Automatically inject Bower components into the HTML file
  110. wiredep: {
  111. app: {
  112. ignorePath: /^\/|\.\.\//,
  113. src: ['<%= config.app %>/index.html'],
  114. /*exclude: ['bower_components/bootstrap/dist/js/bootstrap.js']*/
  115. }
  116. },
  117. // Run some tasks in parallel to speed up build process
  118. concurrent: {
  119. server: [
  120. 'copy:styles'
  121. ]
  122. },
  123. // Add vendor prefixed styles
  124. autoprefixer: {
  125. options: {
  126. browsers: ['> 1%', 'last 2 versions', 'Firefox ESR', 'Opera 12.1']
  127. },
  128. dist: {
  129. files: [{
  130. expand: true,
  131. cwd: '.tmp/styles/',
  132. src: '{,*/}*.css',
  133. dest: '.tmp/styles/'
  134. }]
  135. }
  136. },
  137. // The actual grunt server settings
  138. connect: {
  139. options: {
  140. port: 8090,
  141. open: true,
  142. livereload: 35729,
  143. // Change this to '0.0.0.0' to access the server from outside
  144. hostname: 'localhost'
  145. },
  146. livereload: {
  147. options: {
  148. middleware: function (connect) {
  149. return [
  150. connect.static('.tmp'),
  151. connect().use('/bower_components', connect.static('./bower_components')),
  152. connect.static(config.app)
  153. ];
  154. }
  155. }
  156. },
  157. dist: {
  158. options: {
  159. base: '<%= config.dist %>',
  160. livereload: false
  161. }
  162. }
  163. },
  164. // Copies remaining files to places other tasks can use
  165. copy: {
  166. dist: {
  167. files: [{
  168. expand: true,
  169. dot: true,
  170. cwd: '<%= config.app %>',
  171. dest: '<%= config.dist %>',
  172. src: [
  173. '*.{ico,png,txt}',
  174. '{,*/}*.html',
  175. 'fonts/{,*/}*.*'
  176. ]
  177. }, {
  178. src: '<%= config.app %>/.htaccess',
  179. dest: '<%= config.dist %>/.htaccess'
  180. }]
  181. },
  182. styles: {
  183. expand: true,
  184. dot: true,
  185. cwd: '<%= config.app %>/styles',
  186. dest: '.tmp/styles/',
  187. src: '{,*/}*.css'
  188. }
  189. },
  190. });
  191. // These plugins provide necessary tasks.
  192. grunt.loadNpmTasks('grunt-contrib-concat');
  193. grunt.loadNpmTasks('grunt-contrib-uglify');
  194. grunt.loadNpmTasks('grunt-contrib-jshint');
  195. grunt.loadNpmTasks('grunt-contrib-watch');
  196. grunt.loadNpmTasks('grunt-contrib-clean');
  197. grunt.loadNpmTasks('grunt-wiredep');
  198. grunt.loadNpmTasks('grunt-concurrent');
  199. grunt.loadNpmTasks('grunt-autoprefixer');
  200. grunt.loadNpmTasks('grunt-contrib-connect');
  201. grunt.loadNpmTasks('grunt-contrib-copy');
  202. grunt.loadNpmTasks('grunt-newer');
  203. // Default task.
  204. //grunt.registerTask('default', ['jshint', 'concat', 'uglify']);
  205. grunt.registerTask('serve', 'start the server and preview your app, --allow-remote for remote access', function (target) {
  206. if (grunt.option('allow-remote')) {
  207. grunt.config.set('connect.options.hostname', '0.0.0.0');
  208. }
  209. /*if (target === 'dist') {
  210. return grunt.task.run(['build', 'connect:dist:keepalive']);
  211. }*/
  212. grunt.task.run([
  213. 'clean:server',
  214. 'wiredep',
  215. 'concurrent:server',
  216. 'autoprefixer',
  217. 'connect:livereload',
  218. 'watch'
  219. ]);
  220. });
  221. };