Advertisement
Guest User

gruntfile

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