個人grunt配置

module.exports = function(grunt) {

    // 配置.
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        watch: {
            css: {
                files: 'static/introduce/scss/**/*.scss',
                tasks: ['clean:css','compass'],
                options: {
                    livereload: true
                }
            } ,
            includereplace:{
                files:'src/html/**/*.html',
                tasks:['includereplace','copy:html','clean:html']
            }

        },
        jshint:{//js代碼檢測工具
            options: {
                jshintrc: '.jshintrc'
            },
            src: ["src/static/introduce/js/app/**/*.js"]
        },
        includereplace: {//包含html片斷
            nav: {
                files: [
                    {src: 'src/html/**/*.html', dest: '.tmphtml/'}
                ]
            }
        },
        uglify: {//js壓縮
            options: {
                banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
            },
            js: {
                files: [{
                    expand: true,
                    cwd: 'static/introduce/js',
                    src: '**/*.js',
                    dest: 'static/introduce/js',
                    ext:".min.js"
                }]
            }
        },
        compass: {//compass
            dev: {
                options: {
                    sassDir: 'static/introduce/scss',
                    cssDir: 'static/introduce/css',
                    outputStyle:'compressed',
                    noLineComments: true
                }
            }
        },
        clean: {//清除
            mod:["static/introduce/css/module"],
            css:["static/introduce/css"],
            html:[".tmphtml/"]
        },
        copy: {//複製
            css: {
                expand: true,
                cwd: 'static/introduce/css/',
                src: '**',
                dest: '../../src/SVipSys/SVipSys.Web/static/Introduce/css',
                flatten: true,
                filter: 'isFile'
            },
            scss:{
                expand: true,
                cwd: 'static/introduce/scss/',
                src: '**',
                dest: '../../src/SVipSys/SVipSys.Web/static/Introduce/scss'
            },
            html:{
                expand: true,
                cwd: '.tmphtml/src/html/',
                src: '**',
                dest: 'view/'
            }
        },
        imagemin:{//圖片壓縮
            dynamic: {
                files: [{
                    expand: true,
                    cwd: 'static/',
                    src: ['**/*.{png,jpg,gif}'],
                    dest: 'static/'
                }]
            }
        }
    });

    // 加載任務
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-compass');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-include-replace');
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-imagemin');

    // 任務列表
    grunt.registerTask('default',['clean:css','compass','clean:mod',,'watch']);
    grunt.registerTask('tpl',['includereplace','copy:html','clean:html']);

};

寫在後面的話,最初聽到grunt這個詞的時候,是在去年上半年,當時前端構建工具很是火,我一直以爲它是一個很是高大上的東西,後來發現真的只是個工具而已。大神們說,大家不該該被工具所累,由於工具是學不完的。是的,咱們不須要跟風,但不表明沒必要要用。不少是項目需求,好比你在入職後接手了一些新的項目,那麼,最好就是學習它,掌握它。使用grunt的時候,確實感到了方便之處,好比圖片壓縮、js壓縮、代碼檢測。。。工具,它是幫咱們幹活,減小重複、無聊的工做量的。因此,使用它的時候,咱們應該明確的知道,但願它能幫咱們幹什麼活,而不是對着API寫一堆配置都不知道在幹嗎。。。css

相關文章
相關標籤/搜索