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.
 
 
 
 

352 lines
10 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. concat: {
  136. generated: {
  137. files: [
  138. {
  139. dest: '.tmp/scripts/main.js',
  140. src: ['<%= yeoman.app %>/scripts/main.js']
  141. },
  142. {
  143. dest: '.tmp/scripts/vendor/modernizr.js',
  144. src: ['<%= yeoman.app %>/scripts/vendor/modernizr.js']
  145. },
  146. {
  147. dest: '.tmp/scripts/vendor/video.js',
  148. src: ['<%= yeoman.app %>/scripts/vendor/video.js']
  149. }
  150. ]
  151. }
  152. },
  153. uglify: {
  154. generated: {
  155. files: [
  156. {
  157. dest: '<%= yeoman.dist %>/scripts/main.js',
  158. src: ['.tmp/scripts/main.js']
  159. },
  160. {
  161. dest: '<%= yeoman.dist %>/scripts/vendor/modernizr.js',
  162. src: ['.tmp/scripts/vendor/modernizr.js']
  163. },
  164. {
  165. dest: '<%= yeoman.dist %>/scripts/vendor/video.js',
  166. src: ['.tmp/scripts/vendor/video.js']
  167. }
  168. ]
  169. }
  170. },
  171. rev: {
  172. dist: {
  173. files: {
  174. src: [
  175. '<%= yeoman.dist %>/scripts/{,*/}*.js',
  176. '<%= yeoman.dist %>/styles/{,*/}*.css',
  177. '<%= yeoman.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}',
  178. '<%= yeoman.dist %>/fonts/{,*/}*.*'
  179. ]
  180. }
  181. }
  182. },
  183. useminPrepare: {
  184. html: '<%= yeoman.app %>/*.html',
  185. options: {
  186. dest: '<%= yeoman.dist %>'
  187. }
  188. },
  189. usemin: {
  190. html: ['<%= yeoman.dist %>/{,*/}*.html'],
  191. css: ['<%= yeoman.dist %>/styles/{,*/}*.css'],
  192. options: {
  193. dirs: ['<%= yeoman.dist %>']
  194. }
  195. },
  196. imagemin: {
  197. dist: {
  198. files: [{
  199. expand: true,
  200. cwd: '<%= yeoman.app %>/images',
  201. src: '{,*/}*.{png,jpg,jpeg}',
  202. dest: '<%= yeoman.dist %>/images'
  203. }]
  204. }
  205. },
  206. cssmin: {
  207. dist: {
  208. files: {
  209. '<%= yeoman.dist %>/styles/main.css': [
  210. '.tmp/styles/{,*/}*.css',
  211. '<%= yeoman.app %>/styles/{,*/}*.css'
  212. ]
  213. }
  214. }
  215. },
  216. htmlmin: {
  217. dist: {
  218. options: {
  219. /*removeCommentsFromCDATA: true,
  220. // https://github.com/yeoman/grunt-usemin/issues/44
  221. //collapseWhitespace: true,
  222. collapseBooleanAttributes: true,
  223. removeAttributeQuotes: true,
  224. removeRedundantAttributes: true,
  225. useShortDoctype: true,
  226. removeEmptyAttributes: true,
  227. removeOptionalTags: true*/
  228. },
  229. files: [{
  230. expand: true,
  231. cwd: '<%= yeoman.app %>',
  232. src: '*.html',
  233. dest: '<%= yeoman.dist %>'
  234. }]
  235. }
  236. },
  237. 'npm-command': {
  238. 'videojs-install': {
  239. options: {
  240. cwd: '<%= yeoman.app %>/bower_components/videojs/'
  241. }
  242. },
  243. 'videojs-build': {
  244. options: {
  245. cmd: 'run-script',
  246. args: ['build'],
  247. cwd: '<%= yeoman.app %>/bower_components/videojs/'
  248. }
  249. }
  250. }
  251. ,
  252. copy: {
  253. dist: {
  254. files: [{
  255. expand: true,
  256. dot: true,
  257. cwd: '<%= yeoman.app %>',
  258. dest: '<%= yeoman.dist %>',
  259. src: [
  260. '*.{ico,png,txt}',
  261. 'fonts/{,*/}*.*',
  262. '.htaccess',
  263. 'index.txt',
  264. '404.txt',
  265. 'images/{,*/}*.{webp,gif,svg}'
  266. ]
  267. }]
  268. },
  269. server: {
  270. files: [{
  271. expand: true,
  272. dot: true,
  273. cwd: '<%= yeoman.app %>/bower_components/font-awesome/fonts/',
  274. dest: '<%= yeoman.app %>/fonts/font-awesome',
  275. src: ['*']
  276. }, {
  277. expand: true,
  278. dot: true,
  279. cwd: '<%= yeoman.app %>/bower_components/bootstrap/dist/fonts/',
  280. dest: '<%= yeoman.app %>/fonts/glyphicons',
  281. src: ['*']
  282. }]
  283. }
  284. },
  285. concurrent: {
  286. dist: [
  287. 'less',
  288. 'imagemin',
  289. 'htmlmin'
  290. ]
  291. }
  292. });
  293. grunt.loadNpmTasks('grunt-npm-command');
  294. grunt.registerTask('serve', function (target) {
  295. if (target === 'dist') {
  296. return grunt.task.run(['build', 'connect:dist:keepalive']);
  297. }
  298. grunt.task.run([
  299. 'clean:server',
  300. 'less',
  301. 'includes:server',
  302. 'copy:server',
  303. 'connect:livereload',
  304. 'watch'
  305. ]);
  306. });
  307. grunt.registerTask('server', function () {
  308. grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.');
  309. grunt.task.run(['serve']);
  310. });
  311. grunt.registerTask('test', [
  312. 'clean:server',
  313. 'less',
  314. 'copy:server',
  315. 'connect:test'
  316. ]);
  317. grunt.registerTask('build', [
  318. 'clean:dist',
  319. //'npm-command',
  320. 'copy:server',
  321. 'useminPrepare',
  322. 'concurrent',
  323. 'cssmin',
  324. 'concat',
  325. 'includes:build',
  326. 'uglify',
  327. 'copy',
  328. 'usemin'
  329. ]);
  330. grunt.registerTask('default', [
  331. 'jshint',
  332. 'test',
  333. 'build'
  334. ]);
  335. };