Advertisement
Javi

grunt: less configured

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