当我想用 grunt 和 uglifyjs 压缩我的 javascript 代码时,但 uglifyjs 不支持 es6,所以我使用 grunt-babel,但我遇到了一些问题,它警告 Binding 'arguments' in strict mode,所以我写了一些简单的代码测试它。在这个文件中,参数只是一个普通的局部变量,不是 call(arguments) 或 apply,我不明白它是如何发生的以及如何修复它。这是示例代码:
'use strict';
let a = 1;
async function test() {
return new Promise(resolve, reject => {
let b = 1;
let c = a + b;
resolve(c);
})
}
function no(arguments) {
console.log(arguments);
}
然后 gruntfile.js
module.exports = function(grunt) {
require("load-grunt-tasks")(grunt);
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
clean: {
src: 'dist/'
},
copy: {
main: {
expand: true,
cwd: 'test',
src: '**',
dest: 'dist/',
},
},
babel: {
options: {
sourceMap: false,
presets: ["@babel/preset-env"],
ignore: ["/node_modules","./resources/vendor/**"],
plugins: [
"@babel/plugin-transform-runtime",
["@babel/plugin-transform-modules-commonjs", { "strictMode": false }]
]
},
dist: {
files: [{
expand:true,
cwd:'test/',
src:['**/*.js'],
dest:'dist/'
}]
}
},
uglify: {
options: {
mangle: true,
comments: 'some'
},
my_target: {
files: [{
expand:true,
cwd:'dist/',
src:['**/*.js'],
dest:'dist/'
}]
}
}
});
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-babel');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-usemin');
grunt.registerTask('default', ['clean','copy','babel','uglify']);
}
然后执行grunt 控制台日志
Warning: F:\project\grunttest\test\test.js: Binding 'arguments' in strict mode (11:12)
我尝试配置 babel 选项["@babel/plugin-transform-modules-commonjs", { "strictMode": false }]
,但它不起作用,我该如何解决?谢谢