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.
 
 
 
 

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