Gruntfile.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. // Generated on 2015-06-05 using generator-angular 0.11.1
  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. // Load grunt tasks automatically
  10. require('load-grunt-tasks')(grunt);
  11. // Time how long tasks take. Can help when optimizing build times
  12. require('time-grunt')(grunt);
  13. // Configurable paths for the application
  14. var appConfig = {
  15. app: require('./bower.json').appPath || 'app',
  16. dist: 'dist'
  17. };
  18. // Define the configuration for all the tasks
  19. grunt.initConfig({
  20. // Project settings
  21. yeoman: appConfig,
  22. // Watches files for changes and runs tasks based on the changed files
  23. watch: {
  24. bower: {
  25. files: ['bower.json'],
  26. tasks: ['wiredep']
  27. },
  28. js: {
  29. files: ['<%= yeoman.app %>/scripts/{,*/}*.js'],
  30. options: {
  31. livereload: '<%= connect.options.livereload %>'
  32. }
  33. },
  34. jsTest: {
  35. files: ['test/spec/{,*/}*.js'],
  36. tasks: ['newer:jshint:test', 'karma']
  37. },
  38. styles: {
  39. files: ['<%= yeoman.app %>/styles/{,*/}*.css'],
  40. tasks: ['newer:copy:styles', 'autoprefixer']
  41. },
  42. gruntfile: {
  43. files: ['Gruntfile.js']
  44. },
  45. livereload: {
  46. options: {
  47. livereload: '<%= connect.options.livereload %>'
  48. },
  49. files: [
  50. '<%= yeoman.app %>/{,*/}*.html',
  51. '.tmp/styles/{,*/}*.css',
  52. '<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
  53. ]
  54. }
  55. },
  56. // The actual grunt server settings
  57. connect: {
  58. options: {
  59. port: 9000,
  60. // Change this to '0.0.0.0' to access the server from outside.
  61. hostname: 'localhost',
  62. livereload: 35729
  63. },
  64. livereload: {
  65. options: {
  66. open: true,
  67. middleware: function (connect) {
  68. return [
  69. connect.static('.tmp'),
  70. connect().use(
  71. '/bower_components',
  72. connect.static('./bower_components')
  73. ),
  74. connect().use(
  75. '/app/styles',
  76. connect.static('./app/styles')
  77. ),
  78. connect.static(appConfig.app)
  79. ];
  80. }
  81. }
  82. },
  83. test: {
  84. options: {
  85. port: 9001,
  86. middleware: function (connect) {
  87. return [
  88. connect.static('.tmp'),
  89. connect.static('test'),
  90. connect().use(
  91. '/bower_components',
  92. connect.static('./bower_components')
  93. ),
  94. connect.static(appConfig.app)
  95. ];
  96. }
  97. }
  98. },
  99. dist: {
  100. options: {
  101. open: true,
  102. base: '<%= yeoman.dist %>'
  103. }
  104. }
  105. },
  106. // Make sure code styles are up to par and there are no obvious mistakes
  107. jshint: {
  108. options: {
  109. jshintrc: '.jshintrc',
  110. reporter: require('jshint-stylish')
  111. },
  112. all: {
  113. src: [
  114. 'Gruntfile.js',
  115. '<%= yeoman.app %>/scripts/{,*/}*.js'
  116. ]
  117. },
  118. test: {
  119. options: {
  120. jshintrc: 'test/.jshintrc'
  121. },
  122. src: ['test/spec/{,*/}*.js']
  123. }
  124. },
  125. // Empties folders to start fresh
  126. clean: {
  127. dist: {
  128. files: [{
  129. dot: true,
  130. src: [
  131. '.tmp',
  132. '<%= yeoman.dist %>/{,*/}*',
  133. '!<%= yeoman.dist %>/.git{,*/}*'
  134. ]
  135. }]
  136. },
  137. server: '.tmp'
  138. },
  139. // Add vendor prefixed styles
  140. autoprefixer: {
  141. options: {
  142. browsers: ['last 1 version']
  143. },
  144. server: {
  145. options: {
  146. map: true,
  147. },
  148. files: [{
  149. expand: true,
  150. cwd: '.tmp/styles/',
  151. src: '{,*/}*.css',
  152. dest: '.tmp/styles/'
  153. }]
  154. },
  155. dist: {
  156. files: [{
  157. expand: true,
  158. cwd: '.tmp/styles/',
  159. src: '{,*/}*.css',
  160. dest: '.tmp/styles/'
  161. }]
  162. }
  163. },
  164. // Automatically inject Bower components into the app
  165. wiredep: {
  166. app: {
  167. src: ['<%= yeoman.app %>/index.html'],
  168. ignorePath: /\.\.\//
  169. },
  170. test: {
  171. devDependencies: true,
  172. src: '<%= karma.unit.configFile %>',
  173. ignorePath: /\.\.\//,
  174. fileTypes:{
  175. js: {
  176. block: /(([\s\t]*)\/{2}\s*?bower:\s*?(\S*))(\n|\r|.)*?(\/{2}\s*endbower)/gi,
  177. detect: {
  178. js: /'(.*\.js)'/gi
  179. },
  180. replace: {
  181. js: '\'{{filePath}}\','
  182. }
  183. }
  184. }
  185. }
  186. },
  187. // Renames files for browser caching purposes
  188. filerev: {
  189. dist: {
  190. src: [
  191. '<%= yeoman.dist %>/scripts/{,*/}*.js',
  192. '<%= yeoman.dist %>/styles/{,*/}*.css',
  193. '<%= yeoman.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}',
  194. '<%= yeoman.dist %>/styles/fonts/*'
  195. ]
  196. }
  197. },
  198. // Reads HTML for usemin blocks to enable smart builds that automatically
  199. // concat, minify and revision files. Creates configurations in memory so
  200. // additional tasks can operate on them
  201. useminPrepare: {
  202. html: '<%= yeoman.app %>/index.html',
  203. options: {
  204. dest: '<%= yeoman.dist %>',
  205. flow: {
  206. html: {
  207. steps: {
  208. js: ['concat', 'uglifyjs'],
  209. css: ['cssmin']
  210. },
  211. post: {}
  212. }
  213. }
  214. }
  215. },
  216. // Performs rewrites based on filerev and the useminPrepare configuration
  217. usemin: {
  218. html: ['<%= yeoman.dist %>/{,*/}*.html'],
  219. css: ['<%= yeoman.dist %>/styles/{,*/}*.css'],
  220. options: {
  221. assetsDirs: [
  222. '<%= yeoman.dist %>',
  223. '<%= yeoman.dist %>/images',
  224. '<%= yeoman.dist %>/styles'
  225. ]
  226. }
  227. },
  228. // The following *-min tasks will produce minified files in the dist folder
  229. // By default, your `index.html`'s <!-- Usemin block --> will take care of
  230. // minification. These next options are pre-configured if you do not wish
  231. // to use the Usemin blocks.
  232. // cssmin: {
  233. // dist: {
  234. // files: {
  235. // '<%= yeoman.dist %>/styles/main.css': [
  236. // '.tmp/styles/{,*/}*.css'
  237. // ]
  238. // }
  239. // }
  240. // },
  241. // uglify: {
  242. // dist: {
  243. // files: {
  244. // '<%= yeoman.dist %>/scripts/scripts.js': [
  245. // '<%= yeoman.dist %>/scripts/scripts.js'
  246. // ]
  247. // }
  248. // }
  249. // },
  250. // concat: {
  251. // dist: {}
  252. // },
  253. imagemin: {
  254. dist: {
  255. files: [{
  256. expand: true,
  257. cwd: '<%= yeoman.app %>/images',
  258. src: '{,*/}*.{png,jpg,jpeg,gif}',
  259. dest: '<%= yeoman.dist %>/images'
  260. }]
  261. }
  262. },
  263. svgmin: {
  264. dist: {
  265. files: [{
  266. expand: true,
  267. cwd: '<%= yeoman.app %>/images',
  268. src: '{,*/}*.svg',
  269. dest: '<%= yeoman.dist %>/images'
  270. }]
  271. }
  272. },
  273. htmlmin: {
  274. dist: {
  275. options: {
  276. collapseWhitespace: true,
  277. conservativeCollapse: true,
  278. collapseBooleanAttributes: true,
  279. removeCommentsFromCDATA: true,
  280. removeOptionalTags: true
  281. },
  282. files: [{
  283. expand: true,
  284. cwd: '<%= yeoman.dist %>',
  285. src: ['*.html', 'views/{,*/}*.html'],
  286. dest: '<%= yeoman.dist %>'
  287. }]
  288. }
  289. },
  290. // ng-annotate tries to make the code safe for minification automatically
  291. // by using the Angular long form for dependency injection.
  292. ngAnnotate: {
  293. dist: {
  294. files: [{
  295. expand: true,
  296. cwd: '.tmp/concat/scripts',
  297. src: '*.js',
  298. dest: '.tmp/concat/scripts'
  299. }]
  300. }
  301. },
  302. // Replace Google CDN references
  303. cdnify: {
  304. dist: {
  305. html: ['<%= yeoman.dist %>/*.html']
  306. }
  307. },
  308. // Copies remaining files to places other tasks can use
  309. copy: {
  310. dist: {
  311. files: [{
  312. expand: true,
  313. dot: true,
  314. cwd: '<%= yeoman.app %>',
  315. dest: '<%= yeoman.dist %>',
  316. src: [
  317. '*.{ico,png,txt}',
  318. '.htaccess',
  319. '*.html',
  320. 'views/{,*/}*.html',
  321. 'images/{,*/}*.{webp}',
  322. 'styles/fonts/{,*/}*.*'
  323. ]
  324. }, {
  325. expand: true,
  326. cwd: '.tmp/images',
  327. dest: '<%= yeoman.dist %>/images',
  328. src: ['generated/*']
  329. }, {
  330. expand: true,
  331. cwd: 'bower_components/bootstrap/dist',
  332. src: 'fonts/*',
  333. dest: '<%= yeoman.dist %>'
  334. }]
  335. },
  336. styles: {
  337. expand: true,
  338. cwd: '<%= yeoman.app %>/styles',
  339. dest: '.tmp/styles/',
  340. src: '{,*/}*.css'
  341. }
  342. },
  343. // Run some tasks in parallel to speed up the build process
  344. concurrent: {
  345. server: [
  346. 'copy:styles'
  347. ],
  348. test: [
  349. 'copy:styles'
  350. ],
  351. dist: [
  352. 'copy:styles',
  353. 'imagemin',
  354. 'svgmin'
  355. ]
  356. },
  357. // Test settings
  358. karma: {
  359. unit: {
  360. configFile: 'test/karma.conf.js',
  361. singleRun: true
  362. }
  363. }
  364. });
  365. grunt.registerTask('serve', 'Compile then start a connect web server', function (target) {
  366. if (target === 'dist') {
  367. return grunt.task.run(['build', 'connect:dist:keepalive']);
  368. }
  369. grunt.task.run([
  370. 'clean:server',
  371. 'wiredep',
  372. 'concurrent:server',
  373. 'autoprefixer:server',
  374. 'connect:livereload',
  375. 'watch'
  376. ]);
  377. });
  378. grunt.registerTask('server', 'DEPRECATED TASK. Use the "serve" task instead', function (target) {
  379. grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.');
  380. grunt.task.run(['serve:' + target]);
  381. });
  382. grunt.registerTask('test', [
  383. 'clean:server',
  384. 'wiredep',
  385. 'concurrent:test',
  386. 'autoprefixer',
  387. 'connect:test',
  388. 'karma'
  389. ]);
  390. grunt.registerTask('build', [
  391. 'clean:dist',
  392. 'wiredep',
  393. 'useminPrepare',
  394. 'concurrent:dist',
  395. 'autoprefixer',
  396. 'concat',
  397. 'ngAnnotate',
  398. 'copy:dist',
  399. 'cdnify',
  400. 'cssmin',
  401. 'uglify',
  402. 'filerev',
  403. 'usemin',
  404. 'htmlmin'
  405. ]);
  406. grunt.registerTask('default', [
  407. 'newer:jshint',
  408. 'test',
  409. 'build'
  410. ]);
  411. };