Gruntfile.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. // Generated on 2013-10-07 using generator-webapp 0.4.3
  2. 'use strict';
  3. // # Globbing
  4. // for performance reasons we're only matching one level down:
  5. // 'test/spec/{,*/}*.js'
  6. // use this if you want to recursively match all subfolders:
  7. // 'test/spec/**/*.js'
  8. module.exports = function (grunt) {
  9. // show elapsed time at the end
  10. require('time-grunt')(grunt);
  11. // load all grunt tasks
  12. require('load-grunt-tasks')(grunt);
  13. grunt.initConfig({
  14. // configurable paths
  15. uglify: {
  16. options: {
  17. mangle: false
  18. },
  19. },
  20. yeoman: {
  21. app: 'app',
  22. dist: 'dist'
  23. },
  24. watch: {
  25. compass: {
  26. files: ['<%= yeoman.app %>/styles/{,*/}*.{scss,sass}'],
  27. tasks: ['compass:server', 'autoprefixer']
  28. },
  29. styles: {
  30. files: ['<%= yeoman.app %>/styles/{,*/}*.css'],
  31. tasks: ['copy:styles', 'autoprefixer']
  32. },
  33. livereload: {
  34. options: {
  35. livereload: '<%= connect.options.livereload %>'
  36. },
  37. files: [
  38. '<%= yeoman.app %>/*.html',
  39. '.tmp/styles/{,*/}*.css',
  40. '{.tmp,<%= yeoman.app %>}/scripts/{,*/}*.js',
  41. '<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
  42. ]
  43. }
  44. },
  45. connect: {
  46. options: {
  47. port: 9000,
  48. livereload: 35729,
  49. // change this to '0.0.0.0' to access the server from outside
  50. hostname: 'localhost'
  51. },
  52. livereload: {
  53. options: {
  54. open: true,
  55. base: [
  56. '.tmp',
  57. '<%= yeoman.app %>'
  58. ]
  59. }
  60. },
  61. test: {
  62. options: {
  63. base: [
  64. '.tmp',
  65. 'test',
  66. '<%= yeoman.app %>'
  67. ]
  68. }
  69. },
  70. dist: {
  71. options: {
  72. open: true,
  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. },
  94. all: [
  95. '<%= yeoman.app %>/scripts/{,*/}*.js',
  96. '!<%= yeoman.app %>/scripts/vendor/*',
  97. ]
  98. },
  99. mocha: {
  100. all: {
  101. options: {
  102. run: true,
  103. urls: ['http://<%= connect.test.options.hostname %>:<%= connect.test.options.port %>/index.html']
  104. }
  105. }
  106. },
  107. compass: {
  108. options: {
  109. sassDir: '<%= yeoman.app %>/styles',
  110. cssDir: '.tmp/styles',
  111. generatedImagesDir: '.tmp/images/generated',
  112. imagesDir: '<%= yeoman.app %>/images',
  113. javascriptsDir: '<%= yeoman.app %>/scripts',
  114. fontsDir: '<%= yeoman.app %>/styles/fonts',
  115. importPath: '<%= yeoman.app %>/bower_components',
  116. httpImagesPath: '/images',
  117. httpGeneratedImagesPath: '/images/generated',
  118. httpFontsPath: '/styles/fonts',
  119. relativeAssets: false,
  120. assetCacheBuster: false
  121. },
  122. dist: {
  123. options: {
  124. generatedImagesDir: '<%= yeoman.dist %>/images/generated'
  125. }
  126. },
  127. server: {
  128. options: {
  129. debugInfo: true
  130. }
  131. }
  132. },
  133. autoprefixer: {
  134. options: {
  135. browsers: ['last 1 version']
  136. },
  137. dist: {
  138. files: [{
  139. expand: true,
  140. cwd: '.tmp/styles/',
  141. src: '{,*/}*.css',
  142. dest: '.tmp/styles/'
  143. }]
  144. }
  145. },
  146. // not used since Uglify task does concat,
  147. // but still available if needed
  148. /*concat: {
  149. dist: {}
  150. },*/
  151. requirejs: {
  152. dist: {
  153. // Options: https://github.com/jrburke/r.js/blob/master/build/example.build.js
  154. options: {
  155. // `name` and `out` is set by grunt-usemin
  156. baseUrl: '<%= yeoman.app %>/scripts',
  157. optimize: 'none',
  158. // TODO: Figure out how to make sourcemaps work with grunt-usemin
  159. // https://github.com/yeoman/grunt-usemin/issues/30
  160. //generateSourceMaps: true,
  161. // required to support SourceMaps
  162. // http://requirejs.org/docs/errors.html#sourcemapcomments
  163. preserveLicenseComments: false,
  164. useStrict: true,
  165. wrap: true
  166. //uglify2: {} // https://github.com/mishoo/UglifyJS2
  167. }
  168. }
  169. },
  170. useminPrepare: {
  171. options: {
  172. dest: '<%= yeoman.dist %>'
  173. },
  174. html: ['<%= yeoman.app %>/**/*.html']
  175. },
  176. usemin: {
  177. options: {
  178. dirs: ['<%= yeoman.dist %>']
  179. },
  180. html: ['<%= yeoman.dist %>/{,*/}*.html'],
  181. css: ['<%= yeoman.dist %>/styles/{,*/}*.css']
  182. },
  183. imagemin: {
  184. dist: {
  185. files: [{
  186. expand: true,
  187. cwd: '<%= yeoman.app %>/images',
  188. src: '{,*/}*.{png,jpg,jpeg}',
  189. dest: '<%= yeoman.dist %>/images'
  190. }]
  191. }
  192. },
  193. svgmin: {
  194. dist: {
  195. files: [{
  196. expand: true,
  197. cwd: '<%= yeoman.app %>/images',
  198. src: '{,*/}*.svg',
  199. dest: '<%= yeoman.dist %>/images'
  200. }]
  201. }
  202. },
  203. cssmin: {
  204. // This task is pre-configured if you do not wish to use Usemin
  205. // blocks for your CSS. By default, the Usemin block from your
  206. // `index.html` will take care of minification, e.g.
  207. //
  208. // <!-- build:css({.tmp,app}) styles/main.css -->
  209. //
  210. // dist: {
  211. // files: {
  212. // '<%= yeoman.dist %>/styles/main.css': [
  213. // '.tmp/styles/{,*/}*.css',
  214. // '<%= yeoman.app %>/styles/{,*/}*.css'
  215. // ]
  216. // }
  217. // }
  218. },
  219. htmlmin: {
  220. dist: {
  221. options: {
  222. /*removeCommentsFromCDATA: true,
  223. // https://github.com/yeoman/grunt-usemin/issues/44
  224. //collapseWhitespace: true,
  225. collapseBooleanAttributes: true,
  226. removeAttributeQuotes: true,
  227. removeRedundantAttributes: true,
  228. useShortDoctype: true,
  229. removeEmptyAttributes: true,
  230. removeOptionalTags: true*/
  231. },
  232. files: [{
  233. expand: true,
  234. cwd: '<%= yeoman.app %>',
  235. src: '*.html',
  236. dest: '<%= yeoman.dist %>'
  237. }]
  238. }
  239. },
  240. // Put files not handled in other tasks here
  241. copy: {
  242. dist: {
  243. files: [{
  244. expand: true,
  245. dot: true,
  246. cwd: '<%= yeoman.app %>',
  247. dest: '<%= yeoman.dist %>',
  248. src: [
  249. '*.{ico,png,txt}',
  250. '.htaccess',
  251. 'images/{,*/}*.{webp,gif}',
  252. 'styles/fonts/{,*/}*.*',
  253. 'views/*.*',
  254. 'index.html',
  255. 'bower_components/sass-bootstrap/fonts/*.*'
  256. ]
  257. }]
  258. },
  259. styles: {
  260. expand: true,
  261. dot: true,
  262. cwd: '<%= yeoman.app %>/styles',
  263. dest: '.tmp/styles/',
  264. src: '{,*/}*.css'
  265. }
  266. },
  267. modernizr: {
  268. devFile: '<%= yeoman.app %>/bower_components/modernizr/modernizr.js',
  269. outputFile: '<%= yeoman.dist %>/bower_components/modernizr/modernizr.js',
  270. files: [
  271. '<%= yeoman.dist %>/scripts/{,*/}*.js',
  272. '<%= yeoman.dist %>/styles/{,*/}*.css',
  273. '!<%= yeoman.dist %>/scripts/vendor/*'
  274. ],
  275. uglify: true
  276. },
  277. concurrent: {
  278. server: [
  279. 'compass',
  280. 'copy:styles'
  281. ],
  282. test: [
  283. 'copy:styles'
  284. ],
  285. dist: [
  286. 'compass',
  287. 'copy:styles',
  288. 'imagemin',
  289. 'svgmin',
  290. 'htmlmin'
  291. ]
  292. },
  293. bower: {
  294. options: {
  295. exclude: ['modernizr']
  296. },
  297. all: {
  298. rjsConfig: '<%= yeoman.app %>/scripts/main.js'
  299. }
  300. }
  301. });
  302. grunt.registerTask('server', function (target) {
  303. if (target === 'dist') {
  304. return grunt.task.run(['build', 'connect:dist:keepalive']);
  305. }
  306. grunt.task.run([
  307. 'clean:server',
  308. 'concurrent:server',
  309. 'autoprefixer',
  310. 'connect:livereload',
  311. 'watch'
  312. ]);
  313. });
  314. grunt.registerTask('test', [
  315. 'clean:server',
  316. 'concurrent:test',
  317. 'autoprefixer',
  318. 'connect:test',
  319. 'mocha'
  320. ]);
  321. grunt.registerTask('build', [
  322. 'clean:dist',
  323. 'useminPrepare',
  324. 'concurrent:dist',
  325. 'autoprefixer',
  326. 'concat',
  327. 'cssmin',
  328. 'uglify',
  329. 'usemin',
  330. 'copy:dist'
  331. ]);
  332. grunt.registerTask('default', [
  333. 'jshint',
  334. 'test',
  335. 'build'
  336. ]);
  337. };