2015-04-04 22 views
1

我是Grunt的新手,我失去了所有的選擇。 我試圖做兩件事情:我的每個更改其中一個 Grunt - 將多個文件縮小/處理爲一個

  • 處理特定SCSS文件時間

    • 縮減大小我所有的js文件合併成一個,當我的SCSS文件的一個改變

    這是當前Gruntfile.js我:

    module.exports = function (grunt) { 
        grunt.initConfig({ 
    
        // define source files and their destinations 
        uglify: { 
         files: { 
          src: 'js/*.js', // source files mask 
          dest: 'jsm/', // destination folder 
          expand: true, // allow dynamic building 
          flatten: true, // remove all unnecessary nesting 
          ext: '.min.js' // replace .js to .min.js 
         } 
        }, 
        watch: { 
         js: { files: 'js/*.js', tasks: [ 'uglify' ] }, 
        } 
    }); 
    
    // load plugins 
    grunt.loadNpmTasks('grunt-contrib-watch'); 
    grunt.loadNpmTasks('grunt-contrib-uglify'); 
    
    // register at least this one task 
    grunt.registerTask('default', [ 'uglify' ]); 
    
    
    }; 
    

    我怎麼能做到這一點?

  • 回答

    1

    使用grunt-contrib-concat

    grunt.initConfig({  
        concat: { 
        dist: { 
         src: ['files/**.min.js'], 
         dest: 'project.js', 
        }, 
        } 
    }); 
    

    你應該換一個匿名函數的所有您的文件,並確定使用var所以你沒有得到的文件之間的可變衝突的變量。

    (function(){ 
    
        // foo has function scope 
        var foo = 3; 
        console.log(foo); 
    
        // FOO is a global variable and 
        // can be accessed between files 
        window.FOO = 3; 
        console.log(FOO); 
    
    }).call() 
    
    相關問題