You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

309 lines
8.2 KiB

  1. 'use strict';
  2. // # Globbing
  3. // for performance reasons we're only matching one level down:
  4. // 'test/spec/{,*/}*.js'
  5. // use this if you want to match all subfolders:
  6. // 'test/spec/**/*.js'
  7. module.exports = function (grunt) {
  8. // load all grunt tasks
  9. require('load-grunt-tasks')(grunt);
  10. // show elapsed time at the end
  11. require('time-grunt')(grunt);
  12. // configurable paths
  13. var yeomanConfig = {
  14. app: require('./bower.json').appPath || 'src',
  15. dist: 'dist/'
  16. };
  17. grunt.initConfig({
  18. yeoman: yeomanConfig,
  19. watch: {
  20. less: {
  21. files: ['<%= yeoman.app %>/styles/{,*/}*.less'],
  22. tasks: ['less']
  23. },
  24. gruntfile: {
  25. files: ['Gruntfile.js']
  26. },
  27. includes: {
  28. files: ['<%= yeoman.app %>/*.html', '.tmp/*.html'],
  29. tasks: ['includes:server']
  30. },
  31. livereload: {
  32. options: {
  33. livereload: '<%= connect.options.livereload %>'
  34. },
  35. files: [
  36. '<%= yeoman.app %>/*.html',
  37. '{.tmp,<%= yeoman.app %>}/styles/{,*/}*.css',
  38. '{.tmp,<%= yeoman.app %>}/scripts/{,*/}*.js',
  39. '<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
  40. ],
  41. tasks: ['includes:server']
  42. }
  43. },
  44. connect: {
  45. options: {
  46. port: 9000,
  47. // change this to '0.0.0.0' to access the server from outside
  48. hostname: 'localhost',
  49. livereload: 35729
  50. },
  51. livereload: {
  52. options: {
  53. open: true,
  54. base: [
  55. '.tmp',
  56. '<%= yeoman.app %>'
  57. ]
  58. }
  59. },
  60. test: {
  61. options: {
  62. port: 9001,
  63. base: [
  64. '.tmp',
  65. 'test',
  66. '<%= yeoman.app %>'
  67. ]
  68. }
  69. },
  70. dist: {
  71. options: {
  72. base: '<%= yeoman.dist %>'
  73. }
  74. }
  75. },
  76. clean: {
  77. dist: {
  78. files: [{
  79. dot: true,
  80. src: [
  81. '.tmp',
  82. '<%= yeoman.dist %>/*',
  83. '!<%= yeoman.dist %>/.git*'
  84. ]
  85. }]
  86. },
  87. server: '.tmp'
  88. },
  89. jshint: {
  90. options: {
  91. jshintrc: '.jshintrc',
  92. reporter: require('jshint-stylish')
  93. },
  94. all: [
  95. 'Gruntfile.js',
  96. '<%= yeoman.app %>/scripts/{,*/}*.js',
  97. '!<%= yeoman.app %>/scripts/vendor/*',
  98. 'test/spec/{,*/}*.js'
  99. ]
  100. },
  101. less: {
  102. dist: {
  103. files: {
  104. '<%= yeoman.app %>/styles/main.css': ['<%= yeoman.app %>/styles/main.less']
  105. },
  106. options: {
  107. sourceMap: true,
  108. sourceMapFilename: '<%= yeoman.app %>/styles/main.css.map',
  109. sourceMapBasepath: '<%= yeoman.app %>/',
  110. sourceMapRootpath: '/'
  111. }
  112. }
  113. },
  114. includes: {
  115. build: {
  116. cwd: '<%= yeoman.app %>',
  117. src: ['*.html', 'includes/*.html'],
  118. dest: '<%= yeoman.dist %>',
  119. options: {
  120. flatten: true,
  121. banner: ''
  122. }
  123. },
  124. server: {
  125. cwd: '<%= yeoman.app %>',
  126. src: ['*.html', 'includes/*.html'],
  127. dest: '.tmp/',
  128. options: {
  129. flatten: true,
  130. banner: ''
  131. }
  132. }
  133. },
  134. // not used since Uglify task does concat,
  135. // but still available if needed
  136. /*concat: {
  137. dist: {}
  138. },*/
  139. // not enabled since usemin task does concat and uglify
  140. // check index.html to edit your build targets
  141. // enable this task if you prefer defining your build targets here
  142. /*uglify: {
  143. dist: {}
  144. },*/
  145. rev: {
  146. dist: {
  147. files: {
  148. src: [
  149. '<%= yeoman.dist %>/scripts/{,*/}*.js',
  150. '<%= yeoman.dist %>/styles/{,*/}*.css',
  151. '<%= yeoman.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}',
  152. '<%= yeoman.dist %>/fonts/{,*/}*.*'
  153. ]
  154. }
  155. }
  156. },
  157. useminPrepare: {
  158. html: '<%= yeoman.app %>/*.html',
  159. options: {
  160. dest: '<%= yeoman.dist %>'
  161. }
  162. },
  163. usemin: {
  164. html: ['<%= yeoman.dist %>/{,*/}*.html'],
  165. css: ['<%= yeoman.dist %>/styles/{,*/}*.css'],
  166. options: {
  167. dirs: ['<%= yeoman.dist %>']
  168. }
  169. },
  170. imagemin: {
  171. dist: {
  172. files: [{
  173. expand: true,
  174. cwd: '<%= yeoman.app %>/images',
  175. src: '{,*/}*.{png,jpg,jpeg}',
  176. dest: '<%= yeoman.dist %>/images'
  177. }]
  178. }
  179. },
  180. cssmin: {
  181. dist: {
  182. files: {
  183. '<%= yeoman.dist %>/styles/main.css': [
  184. '.tmp/styles/{,*/}*.css',
  185. '<%= yeoman.app %>/styles/{,*/}*.css'
  186. ]
  187. }
  188. }
  189. },
  190. htmlmin: {
  191. dist: {
  192. options: {
  193. /*removeCommentsFromCDATA: true,
  194. // https://github.com/yeoman/grunt-usemin/issues/44
  195. //collapseWhitespace: true,
  196. collapseBooleanAttributes: true,
  197. removeAttributeQuotes: true,
  198. removeRedundantAttributes: true,
  199. useShortDoctype: true,
  200. removeEmptyAttributes: true,
  201. removeOptionalTags: true*/
  202. },
  203. files: [{
  204. expand: true,
  205. cwd: '<%= yeoman.app %>',
  206. src: '*.html',
  207. dest: '<%= yeoman.dist %>'
  208. }]
  209. }
  210. },
  211. copy: {
  212. dist: {
  213. files: [{
  214. expand: true,
  215. dot: true,
  216. cwd: '<%= yeoman.app %>',
  217. dest: '<%= yeoman.dist %>',
  218. src: [
  219. '*.{ico,png,txt}',
  220. 'fonts/{,*/}*.*',
  221. '.htaccess',
  222. 'index.txt',
  223. '404.txt',
  224. 'images/{,*/}*.{webp,gif,svg}'
  225. ]
  226. }]
  227. },
  228. server: {
  229. files: [{
  230. expand: true,
  231. dot: true,
  232. cwd: '<%= yeoman.app %>/bower_components/font-awesome/fonts/',
  233. dest: '<%= yeoman.app %>/fonts/font-awesome',
  234. src: ['*']
  235. }, {
  236. expand: true,
  237. dot: true,
  238. cwd: '<%= yeoman.app %>/bower_components/bootstrap/dist/fonts/',
  239. dest: '<%= yeoman.app %>/fonts/glyphicons',
  240. src: ['*']
  241. }]
  242. }
  243. },
  244. concurrent: {
  245. dist: [
  246. 'less',
  247. 'imagemin',
  248. 'htmlmin'
  249. ]
  250. }
  251. });
  252. grunt.registerTask('serve', function (target) {
  253. if (target === 'dist') {
  254. return grunt.task.run(['build', 'connect:dist:keepalive']);
  255. }
  256. grunt.task.run([
  257. 'clean:server',
  258. 'less',
  259. 'includes:server',
  260. 'copy:server',
  261. 'connect:livereload',
  262. 'watch'
  263. ]);
  264. });
  265. grunt.registerTask('server', function () {
  266. grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.');
  267. grunt.task.run(['serve']);
  268. });
  269. grunt.registerTask('test', [
  270. 'clean:server',
  271. 'less',
  272. 'copy:server',
  273. 'connect:test',
  274. ]);
  275. grunt.registerTask('build', [
  276. 'clean:dist',
  277. 'copy:server',
  278. 'useminPrepare',
  279. 'concurrent',
  280. 'cssmin',
  281. 'concat',
  282. 'includes:build',
  283. 'uglify',
  284. 'copy',
  285. 'usemin',
  286. ]);
  287. grunt.registerTask('default', [
  288. 'jshint',
  289. 'test',
  290. 'build'
  291. ]);
  292. };