Gruntfile.js 12 KB

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