Advertisement
Guest User

gruntfile

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