Guest User

Gruntfile.js

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