我正在使用“grunt-closure-tools”。
当我尝试缩小简单的 JS 文件时,一切正常。 但是当我尝试缩小 AngularJS 库或 Bootstrap 库时,我遇到了下一个异常:
Error: Command failed: build\lib\angular.js:9040 WARNING - Keywords and reserved words are not allowed as unquoted property names in older versions of JavaScript. If you are targeting newer versions of JavaScript, set the appropriate language_in otion.
build\lib\angular.js:256: ERROR - Parse error. identifier is a reserved word */
build\lib\angular.js:258: ERROR - Parse error. identifier is a reserved word if (isNaN(msie)) {
...................
Gruntfile.js:
module.exports = function(grunt) {
grunt.initConfig({
pkg : grunt.file.readJSON('package.json'),
closureCompiler: {
options: {
compilerFile: 'lib/google-closure-tools/compiler.jar'
},
minify: {
files: [
{
expand: true,
src: ['build/**/*.js', '!build/**/*.min.js'],
ext: '.min.js'
}
]
}
}
});
grunt.loadNpmTasks('grunt-closure-tools');
grunt.registerTask('closure', ['closureCompiler']);
};
感谢您的帮助。
最佳答案
解决方案是在缩小过程中使用 ( language_in: "ECMASCRIPT5")。
Gruntfile.js:
module.exports = function(grunt) {
grunt.initConfig({
pkg : grunt.file.readJSON('package.json'),
closureCompiler: {
options: {
compilerFile: 'lib/google-closure-tools/compiler.jar',
compilerOpts: {
language_in: "ECMASCRIPT5"
}
},
minify: {
files: [
{
expand: true,
src: ['build/**/*.js', '!build/**/*.min.js'],
ext: '.min.js'
}
]
}
}
});
grunt.loadNpmTasks('grunt-closure-tools');
grunt.registerTask('closure', ['closureCompiler']);
};
关于javascript - grunt-closure-tools : ERROR - Parse error. 标识符是保留字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24887500/