Advertisement
lidia_defreitas

Gruntfile.js

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