gpt4 book ai didi

gruntjs - 动态更改任务 uglify 的配置

转载 作者:行者123 更新时间:2023-12-04 07:39:15 26 4
gpt4 key购买 nike

我需要根据需要更改我的 uglify 任务的配置,仅用于缩小文件(如 jshint 任务的解释:https://github.com/gruntjs/grunt-contrib-watch#compiling-files-as-needed)

修改适用于 jshint 任务,但不适用于 uglify,我认为问题在于属性路径...

任何帮助,将不胜感激 ;)

这是我的 Gruntfile.js :

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 }]);
});

};

最佳答案

线

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

正在完全替换 uglify.dynamic_mappings.files 的原始配置

而是尝试包含其他原始参数以及新的 src: filepath

关于gruntjs - 动态更改任务 uglify 的配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18128223/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com