Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.17 KB | None | 0 0
  1. // Generated on 2016-11-20 using generator-angular 0.15.1
  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.  
  13.  
  14. // Time how long tasks take. Can help when optimizing build times
  15. require('time-grunt')(grunt);
  16.  
  17. require('load-grunt-config')(grunt, {
  18. jitGrunt: true
  19. });
  20.  
  21. // Automatically load required Grunt tasks
  22. require('jit-grunt')(grunt, {
  23. start: 'start',
  24. useminPrepare: 'grunt-usemin',
  25. ngtemplates: 'grunt-angular-templates',
  26. cdnify: 'grunt-google-cdn'
  27. });
  28.  
  29.  
  30. // Configurable paths for the application
  31. var appConfig = {
  32. app: require('./bower.json').appPath || 'app',
  33. dist: 'dist'
  34. };
  35.  
  36. // Define the configuration for all the tasks
  37. grunt.initConfig({
  38. // Project settings
  39. config: appConfig,
  40.  
  41.  
  42.  
  43. // Watches files for changes and runs tasks based on the changed files
  44. watch: {
  45. livereload: {
  46. options: { livereload: true }
  47. },
  48. bower: {
  49. files: ['bower.json'],
  50. tasks: ['wiredep']
  51. },
  52. js: {
  53. files: ['<%=config.app %>/scripts/{,*/}*.js'],
  54. tasks: ['newer:jshint:all', 'newer:jscs:all'],
  55. options: {
  56. livereload: '<%= connect.options.livereload %>'
  57. }
  58. },
  59. jsTest: {
  60. files: ['test/spec/{,*/}*.js'],
  61. tasks: ['newer:jshint:test', 'newer:jscs:test', 'karma']
  62. },
  63. compass: {
  64. files: ['<%=config.app %>/styles/{,*/}*.{scss,sass}'],
  65. tasks: ['compass:server', 'postcss:server']
  66. },
  67. gruntfile: {
  68. files: ['Gruntfile.js']
  69. },
  70. livereload: {
  71. options: {
  72. livereload: '<%= connect.options.livereload %>'
  73. },
  74. files: [
  75. '<%=config.app %>/{,*/}*.html',
  76. '.tmp/styles/{,*/}*.css',
  77. '<%=app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
  78. ]
  79. }
  80. },
  81.  
  82. // The actual grunt server settings
  83. connect: {
  84. options: {
  85. port: 9000,
  86. // Change this to '0.0.0.0' to access the server from outside.
  87. hostname: 'localhost',
  88. livereload: 35729
  89. },
  90. livereload: {
  91. options: {
  92. open: true,
  93. middleware: function (connect) {
  94. return [
  95. connect.static('.tmp'),
  96. connect().use(
  97. '/bower_components',
  98. connect.static('./bower_components')
  99. ),
  100. connect().use(
  101. '/app/styles',
  102. connect.static('./app/styles')
  103. ),
  104. connect.static(appConfig.app)
  105. ];
  106. }
  107. }
  108. },
  109. test: {
  110. options: {
  111. port: 9001,
  112. middleware: function (connect) {
  113. return [
  114. connect.static('.tmp'),
  115. connect.static('test'),
  116. connect().use(
  117. '/bower_components',
  118. connect.static('./bower_components')
  119. ),
  120. connect.static(appConfig.app)
  121. ];
  122. }
  123. }
  124. },
  125. dist: {
  126. options: {
  127. open: true,
  128. base: '<%= config.dist %>'
  129. }
  130. }
  131. },
  132.  
  133. // Make sure there are no obvious mistakes
  134. jshint: {
  135. options: {
  136. jshintrc: '.jshintrc',
  137. reporter: require('jshint-stylish')
  138. },
  139. all: {
  140. src: [
  141. 'Gruntfile.js',
  142. '<%= config.app %>/scripts/{,*/}*.js'
  143. ]
  144. },
  145. test: {
  146. options: {
  147. jshintrc: 'test/.jshintrc'
  148. },
  149. src: ['test/spec/{,*/}*.js']
  150. }
  151. },
  152.  
  153. // Make sure code styles are up to par
  154. jscs: {
  155. options: {
  156. config: '.jscsrc',
  157. verbose: true
  158. },
  159. all: {
  160. src: [
  161. 'Gruntfile.js',
  162. '<%= config.app %>/scripts/{,*/}*.js'
  163. ]
  164. },
  165. test: {
  166. src: ['test/spec/{,*/}*.js']
  167. }
  168. },
  169.  
  170. // Empties folders to start fresh
  171. clean: {
  172. dist: {
  173. files: [{
  174. dot: true,
  175. src: [
  176. '.tmp',
  177. '<%= config.dist %>/{,*/}*',
  178. '!<%= config.dist %>/.git{,*/}*'
  179. ]
  180. }]
  181. },
  182. server: '.tmp'
  183. },
  184.  
  185. // Add vendor prefixed styles
  186. postcss: {
  187. options: {
  188. processors: [
  189. require('autoprefixer-core')({browsers: ['last version']})
  190. ]
  191. },
  192. server: {
  193. options: {
  194. map: true
  195. },
  196. files: [{
  197. expand: true,
  198. cwd: '.tmp/styles/',
  199. src: '{,*/}*.css',
  200. dest: '.tmp/styles/'
  201. }]
  202. },
  203. dist: {
  204. files: [{
  205. expand: true,
  206. cwd: '.tmp/styles/',
  207. src: '{,*/}*.css',
  208. dest: '.tmp/styles/'
  209. }]
  210. }
  211. },
  212.  
  213. // Automatically inject Bower components into the app
  214. wiredep: {
  215. app: {
  216. src: ['<%= config.app %>/index.html'],
  217. ignorePath: /..//
  218. },
  219. test: {
  220. devDependencies: true,
  221. src: '<%= karma.unit.configFile %>',
  222. ignorePath: /..//,
  223. fileTypes:{
  224. js: {
  225. block: /(([st]*)/{2}s*?bower:s*?(S*))(n|r|.)*?(/{2}s*endbower)/gi,
  226. detect: {
  227. js: /'(.*.js)'/gi
  228. },
  229. replace: {
  230. js: ''{{filePath}}','
  231. }
  232. }
  233. }
  234. },
  235. sass: {
  236. src: ['<%= config.app %>/styles/{,*/}*.{scss,sass}'],
  237. ignorePath: /(../){1,2}bower_components//
  238. }
  239. },
  240.  
  241. // Compiles Sass to CSS and generates necessary files if requested
  242. compass: {
  243. options: {
  244. sassDir: '<%= config.app %>/styles',
  245. cssDir: '.tmp/styles',
  246. generatedImagesDir: '.tmp/images/generated',
  247. imagesDir: '<%= config.app %>/images',
  248. javascriptsDir: '<%= config.app %>/scripts',
  249. fontsDir: '<%= config.app %>/styles/fonts',
  250. importPath: './bower_components',
  251. httpImagesPath: '/images',
  252. httpGeneratedImagesPath: '/images/generated',
  253. httpFontsPath: '/styles/fonts',
  254. relativeAssets: false,
  255. assetCacheBuster: false,
  256. raw: 'Sass::Script::Number.precision = 10n'
  257. },
  258. dist: {
  259. options: {
  260. generatedImagesDir: '<%= config.dist %>/images/generated'
  261. }
  262. },
  263. server: {
  264. options: {
  265. sourcemap: true
  266. }
  267. }
  268. },
  269.  
  270. // Renames files for browser caching purposes
  271. filerev: {
  272. dist: {
  273. src: [
  274. '<%= config.dist %>/scripts/{,*/}*.js',
  275. '<%= config.dist %>/styles/{,*/}*.css',
  276. '<%= config.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}',
  277. '<%= config.dist %>/styles/fonts/*'
  278. ]
  279. }
  280. },
  281.  
  282. // Reads HTML for usemin blocks to enable smart builds that automatically
  283. // concat, minify and revision files. Creates configurations in memory so
  284. // additional tasks can operate on them
  285. useminPrepare: {
  286. html: '<%= config.app %>/index.html',
  287. options: {
  288. dest: '<%= config.dist %>',
  289. flow: {
  290. html: {
  291. steps: {
  292. js: ['concat', 'uglifyjs'],
  293. css: ['cssmin']
  294. },
  295. post: {}
  296. }
  297. }
  298. }
  299. },
  300.  
  301. // Performs rewrites based on filerev and the useminPrepare configuration
  302. usemin: {
  303. html: ['<%= config.dist %>/{,*/}*.html'],
  304. css: ['<%= config.dist %>/styles/{,*/}*.css'],
  305. js: ['<%= config.dist %>/scripts/{,*/}*.js'],
  306. options: {
  307. assetsDirs: [
  308. '<%= config.dist %>',
  309. '<%= config.dist %>/images',
  310. '<%= config.dist %>/styles'
  311. ],
  312. patterns: {
  313. js: [[/(images/[^''""]*.(png|jpg|jpeg|gif|webp|svg))/g, 'Replacing references to images']]
  314. }
  315. }
  316. },
  317. imagemin: {
  318. dist: {
  319. files: [{
  320. expand: true,
  321. cwd: '<%= config.app %>/images',
  322. src: '{,*/}*.{png,jpg,jpeg,gif}',
  323. dest: '<%= config.dist %>/images'
  324. }]
  325. }
  326. },
  327.  
  328. svgmin: {
  329. dist: {
  330. files: [{
  331. expand: true,
  332. cwd: '<%= config.app %>/images',
  333. src: '{,*/}*.svg',
  334. dest: '<%= config.dist %>/images'
  335. }]
  336. }
  337. },
  338.  
  339. htmlmin: {
  340. dist: {
  341. options: {
  342. collapseWhitespace: true,
  343. conservativeCollapse: true,
  344. collapseBooleanAttributes: true,
  345. removeCommentsFromCDATA: true
  346. },
  347. files: [{
  348. expand: true,
  349. cwd: '<%= config.dist %>',
  350. src: ['*.html'],
  351. dest: '<%= config.dist %>'
  352. }]
  353. }
  354. },
  355.  
  356. ngtemplates: {
  357. dist: {
  358. options: {
  359. module: 'resourcesApp',
  360. htmlmin: '<%= htmlmin.dist.options %>',
  361. usemin: 'scripts/scripts.js'
  362. },
  363. cwd: '<%= config.app %>',
  364. src: 'views/{,*/}*.html',
  365. dest: '.tmp/templateCache.js'
  366. }
  367. },
  368.  
  369. // ng-annotate tries to make the code safe for minification automatically
  370. // by using the Angular long form for dependency injection.
  371. ngAnnotate: {
  372. dist: {
  373. files: [{
  374. expand: true,
  375. cwd: '.tmp/concat/scripts',
  376. src: '*.js',
  377. dest: '.tmp/concat/scripts'
  378. }]
  379. }
  380. },
  381.  
  382. // Replace Google CDN references
  383. cdnify: {
  384. dist: {
  385. html: ['<%= config.dist %>/*.html']
  386. }
  387. },
  388.  
  389. // Copies remaining files to places other tasks can use
  390. copy: {
  391. dist: {
  392. files: [{
  393. expand: true,
  394. dot: true,
  395. cwd: '<%= config.app %>',
  396. dest: '<%= config.dist %>',
  397. src: [
  398. '*.{ico,png,txt}',
  399. '*.html',
  400. 'images/{,*/}*.{webp}',
  401. 'styles/fonts/{,*/}*.*'
  402. ]
  403. }, {
  404. expand: true,
  405. cwd: '.tmp/images',
  406. dest: '<%= config.dist %>/images',
  407. src: ['generated/*']
  408. }, {
  409. expand: true,
  410. cwd: '.',
  411. src: 'bower_components/bootstrap-sass-official/assets/fonts/bootstrap/*',
  412. dest: '<%= config.dist %>'
  413. }]
  414. },
  415. styles: {
  416. expand: true,
  417. cwd: '<%= config.app %>/styles',
  418. dest: '.tmp/styles/',
  419. src: '{,*/}*.css'
  420. }
  421. },
  422.  
  423. // Run some tasks in parallel to speed up the build process
  424. concurrent: {
  425. server: [
  426. 'compass:server'
  427. ],
  428. test: [
  429. 'compass'
  430. ],
  431. dist: [
  432. 'compass:dist',
  433. 'imagemin',
  434. 'svgmin'
  435. ]
  436. },
  437.  
  438. // Test settings
  439. karma: {
  440. unit: {
  441. configFile: 'test/karma.conf.js',
  442. singleRun: true
  443. }
  444. }
  445. });
  446.  
  447.  
  448.  
  449.  
  450. grunt.registerTask('serve', 'Compile then start a connect web server', function (target) {
  451. if (target === 'dist') {
  452. return grunt.task.run(['build', 'connect:dist:keepalive']);
  453. }
  454.  
  455. grunt.task.run([
  456. 'clean:server',
  457. 'wiredep',
  458. 'concurrent:server',
  459. 'postcss:server',
  460. 'connect:livereload',
  461. 'watch'
  462. ]);
  463. });
  464.  
  465. grunt.registerTask('server', 'DEPRECATED TASK. Use the "serve" task instead', function (target) {
  466. grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.');
  467. grunt.task.run(['serve:' + target]);
  468. });
  469.  
  470. grunt.registerTask('test', [
  471. 'clean:server',
  472. 'wiredep',
  473. 'concurrent:test',
  474. 'postcss',
  475. 'connect:test',
  476. 'karma'
  477. ]);
  478.  
  479. grunt.registerTask('build', [
  480. 'clean:dist',
  481. 'wiredep',
  482. 'useminPrepare',
  483. 'concurrent:dist',
  484. 'postcss',
  485. 'ngtemplates',
  486. 'concat',
  487. 'ngAnnotate',
  488. 'copy:dist',
  489. 'cdnify',
  490. 'cssmin',
  491. 'uglify',
  492. 'filerev',
  493. 'usemin',
  494. 'htmlmin'
  495. ]);
  496.  
  497. grunt.registerTask('default', [
  498. 'newer:jshint',
  499. 'newer:jscs',
  500. 'test',
  501. 'build'
  502. ]);
  503. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement