Snippets

Mathias Elle Gruntfile.js

Created by Mathias Elle
var themepath = 'path/to/my/css/and/js/';
//var jsfiles = 'js/**/*.js';

var jsFiles = [
    themepath + 'js/example.js',
    themepath + 'otherFolder/js/example2.js'
];
module.exports = function(grunt) {
    require('jit-grunt')(grunt);

    grunt.initConfig({
        less: {
            development: {
                options: {
                    compress: false,
                    yuicompress: false,
                    optimization: 9
                },
                files: {
                    "path/to/my/css/and/js/styles.dev.css": themepath + "less/styles.less" // destination file and source file
                }
            },
            production: {
                options: {
                    compress: true,
                    yuicompress: true,
                    optimization: 9
                },
                files: {
                    "path/to/my/css/and/js/styles.min.css": themepath + "less/styles.less" // destination file and source file
                }
            }
        },
        watch: {
            less: {
                files: ['path/to/my/css/and/js/less/**/*.less'],
                tasks: ['less'],
                options: {
                    nospawn: true
                }
            },
            js: {
                files: ['path/to/my/css/and/js/**/*.js'],
                tasks: ['uglify'],
                options: {
                    spawn: false,
                    livereload: true
                }
            }
        },
        uglify: {
            development: {
                options: {
                    mangle: true,
                    compress: {
                        drop_console: true
                    },
                    beautify: true,
                    report: "min",
                    wrap: undefined,

                    /**
                     * When using wrap this will make all global functions and variables available via the export variable.
                     */
                    exportAll: false,

                    /**
                     * Turn on preservation of comments.
                     * More details on https://github.com/gruntjs/grunt-contrib-uglify
                     * false | 'all' | 'some'
                     */
                    preserveComments: false,

                    /**
                     * This string will be prepended to the beginning of the minified output.
                     */
                    banner: '', //'/*! <%= pkg.name %> - v<%= pkg.version %> - ' + '<%= grunt.template.today("yyyy-mm-dd") %> */'

                    /**
                     * This string will be append to the end of the minified output.
                     */
                    footer: ''
                },
                files: [
                    {
                        src: [jsFiles],
                        dest: 'path/to/my/css/and/js/example.js'
                    }
                ]
            },
            production: {
                files: [
                    {
                        src: [jsFiles],
                        dest: 'path/to/my/css/and/js/js/example.min.js'
                    }
                ]
            }
        }
    });

    grunt.registerTask('default', ['less', 'watch']);
};

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.