2013-08-08 16 views
7

tôi cần phải thay đổi cấu hình của việc làm xấu đi của tôi cho file chỉ giảm bớt khi cần thiết (như đã giải thích ở đây cho nhiệm vụ jshint: https://github.com/gruntjs/grunt-contrib-watch#compiling-files-as-needed)Thay đổi cấu hình của nhiệm vụ làm xấu đi động

Việc sửa đổi hoạt động tốt cho nhiệm vụ jshint nhưng không cho làm xấu đi, tôi nghĩ rằng vấn đề là con đường bất động sản ...

Bất kỳ trợ giúp sẽ được đánh giá cao;)

đây là Gruntfile.js tôi:

module.exports = function (grunt) { 
    grunt.initConfig({ 

     // define source files and their destinations 
     jshint: { 
      all: ['dev/**/*.js'], 
     }, 
     uglify: { 
      dynamic_mappings: { 
       // Grunt will search for "**/*.js" under "dev/" when the "minify" task 
       // runs and build the appropriate src-dest file mappings then, so you 
       // don't need to update the Gruntfile when files are added or removed. 
      files: [{ 
        expand: true,  // Enable dynamic expansion. 
        cwd: 'dev/',  // Src matches are relative to this path. 
        src: ['**/*.js'], // Actual pattern(s) to match. 
        dest: 'build', // Destination path prefix. 
        ext: '.min.js', // Dest filepaths will have this extension. 
       }, 
       ], 
      } 
     } 
     watch: { 
     options: { spawn: false }, 
      js: { files: 'dev/**/*.js', tasks: [ 'uglify' ] }, 
     } 
    }); 

    // load plugins 
    grunt.loadNpmTasks('grunt-contrib-watch'); 
    grunt.loadNpmTasks('grunt-contrib-uglify'); 
    grunt.loadNpmTasks('grunt-contrib-jshint'); 

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

    grunt.event.on('watch', function(action, filepath) { 
     grunt.config(['jshint', 'all'], filepath); 
     grunt.config('uglify.dynamic_mappings.files', [{src: filepath }]); 
    }); 

}; 
+1

Tôi chưa thử điều này, nhưng có thể câu lệnh cấu hình tệp hoàn toàn thay thế cấu hình tệp của bạn. Bạn đã thử cung cấp tất cả các thuộc tính (mở rộng, cwd, v.v ...) khi bạn sửa đổi cấu hình uglify chưa? – dc5

+0

Đó là giải pháp! Cảm ơn rất nhiều. – Fab

Trả lời

8

Dòng

grunt.config('uglify.dynamic_mappings.files', [{src: filepath }]); 

là hoàn toàn thay thế các cấu hình ban đầu cho uglify.dynamic_mappings.files

Thay vì cố gắng bao gồm các thông số ban đầu khác cùng với src mới: filepath

0

Làm thế nào để không rút gọn đã được rút gọn trên mỗi "xây dựng grunt" trong yeoman

uglify:  { 
     onlyScripts: { 
     files: [{ 
      dest: '<%= yeoman.dist %>/scripts/scripts.js', 
      src: ['.tmp/concat/scripts/scripts.js'] 
     }] 
     } 
    } 

Ngoài ra, bây giờ uglify sẽ không sao chép vendor.js của bạn từ thư mục tạm thời, vì vậy thêm "vendorJS" để "sao chép" nhiệm vụ:

copy: 
     //... 
     vendorJS: { 
     expand: true, 
     cwd: '.tmp/concat/scripts/', 
     dest: '<%= yeoman.dist %>/scripts/', 
     src: 'vendor.js' 
     } 

Sau đó, trong "xây dựng" công việc, thiết lập mục tiêu làm xấu đi đến 'onlyScripts' và sao chép vendor.js:

grunt.registerTask('build', [ 
    'jshint', 
    'clean:dist', 
    //'wiredep', 
    // ... 
    'useminPrepare', 
    //'concurrent:dist', 
    'autoprefixer', 
    'concat', 
    'ngAnnotate', 
    'copy:dist', 
    'cssmin', 
    'uglify:onlyScripts', 
    'copy:vendorJS', 
    // ... 
    ]); 

http://eugenioz.blogspot.in/2014/08/how-to-not-minify-already-minified-on.html

Các vấn đề liên quan