这是我的Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
uglify: {
options: {
mangle: true
}
build: {
src: "js/*.js",
dest: "js/min/script.js"
}
}
});
grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.registerTask('default', [uglify]);
};
这是我的package.json-我已经运行npm install
了,在我的Gruntfile中将使用的所有插件都包括grunt-contrib-uglify。
{
"name": "bootbuckle",
"version": "0.1.0",
"engines": {
"node": ">= 0.10.0"
},
"devDependencies": {
"grunt": "~0.4.2",
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-sass": "~0.6.0",
"grunt-csscomb": "~2.0.1",
"grunt-contrib-htmlmin": "~0.1.3",
"grunt-contrib-imagemin": "~0.4.1",
"grunt-contrib-uglify": "~0.2.7"
}
}
当我只是grunt
在终端中运行时-这是错误
build: {
^^^^^
Loading "Gruntfile.js" tasks...ERROR
>> SyntaxError: Unexpected identifier
Warning: Task "default" not found. Use --force to continue.
Aborted due to warnings.
预先感谢您可能提供的任何帮助。
编辑在Matti的指导下,我插入了一个缺少的逗号,现在引发了一个新错误
Loading "Gruntfile.js" tasks...ERROR
>> ReferenceError: uglify is not defined
Warning: Task "default" not found. Use --force to continue.
Aborted due to warnings.
您在这里错过了逗号:
uglify: {
options: {
mangle: true
}, // <-------
build: {
src: "js/*.js",
dest: "js/min/script.js"
}
}
编辑:正如japrescott发布的那样,您必须将uglify任务定义为字符串。
grunt.registerTask('default', ["uglify"]);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句