2013-10-30 3 views
2

방금 ​​변경된 파일을 uglify하는 Gruntfile.js를 설정하려고합니다. 내가 질문에서 이것 좀 적응했고 나는이 이해 한대로Gruntfile.js는 변경된 파일 만 uglifies합니다.

How to uglify only changed file with Grunt.js watch task if dynamic expansion in Uglify has been enabled?

에 주어진 답 이벤트는 다음이 될하기 위해 추하게 작업 src 변경되는, 시계 이벤트를 트리거해야 현재 파일 경로. 그러나 GruntJS는 방금 변경된 파일이 아니라 모든 파일을 여전히 uglify합니다.

GruntJS가 여기에서 작동하는 방식을 오해했는지 확실하지 않지만 누구나 내가 잘못 가고 있다고 제안 할 수 있습니까?

var productionPath = "production", devPath = "dev"; 

module.exports = function(grunt) { 
    require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks); 

    grunt.initConfig({ 
     pkg: grunt.file.readJSON('package.json'), 
     uglify: { 
      options: { 
       banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n' 
      }, 
      build: { 
       expand: true, 
       cwd: devPath + '/js/', 
       src: ['**/*.js'], 
       dest: productionPath + '/js/', 
       ext: '.min.js' 
      } 
     }, 
     watch: { 
      options: { spawn: false }, 
      scripts: { 
       files: [devPath + '/**/*.js'], 
       tasks: ['uglify'] 
      } 
     } 
    }); 

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

    grunt.event.on('watch', function(action, filepath, target) { 
     grunt.config('uglify.build.src', filepath); 
    }); 
}; 

답변

4

당신이 아주 쉽게하고 싶은 것을 할 수있는 grunt-newer을 사용하면이 경우에 호의적이어야합니다.

이론 상으로는 일반 uglify 작업과 대상을 등록한 다음 newer을 붙이기 만하면됩니다.

grunt.registerTask('build', ['newer:uglify:something']); 

하거나 명령 줄에서

grunt newer:uglify:something 
관련 문제