Advertisement
Guest User

gruntfile.js

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