本地环境下grunt操作报错
{
"name": "webapp",
"version": "1.0.0",
"description": "This is a project set-up using Grunt to take case of some standard tasks such as: compiling AMD based modules using RequireJS, watching/compiling Sass into CSS, watching/linting JS code and some other things such as running unit tests",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"Grunt"
],
"author": "***",
"license": "ISC",
"devDependencies": {
"grunt": "^0.4.5",
"grunt-autoprefixer": "^3.0.3",
"grunt-contrib-clean": "^0.7.0",
"grunt-contrib-concat": "^0.5.1",
"grunt-contrib-copy": "^0.8.2",
"grunt-contrib-cssmin": "^0.14.0",
"grunt-contrib-jshint": "^0.11.3",
"grunt-contrib-uglify": "^0.11.0",
"grunt-contrib-watch": "^0.6.1"
}
}
module.exports = function (grunt) {
// 项目配置
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint:{
files:['Gruntfile.js','js/*.js'],
options:{
curly:true,
eqeqeq:true,
immed:true,
newcap:true,
noarg:true,
undef:true,
boss:false,
eqnull:true,
browser:true,
expr:true,
noempty:true,
regexp:true,
devel:true,
node:true
}
},
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
build: {
src: 'js/concated.js',
dest: 'js/uglify.min.js'
}
},
concat: {
options: {
separator: ';'
},
dist: {
src: [ 'js/*.js' ],
dest: 'js/concated.js'
}
},
copy: {
build: {
cwd: 'js/',
src: '*.js',
dest: 'js2/',
expand: true
},
},
clean: {
build: {
src: 'js/*.html'
},
},
// 给CSS3属性添加前缀插件,使用的autoprefixer输出的文件和读取的文件在同一个目录中。
autoprefixer: {
build: {
expand: true,
cwd: 'css/',
src: '*.css',
dest: 'css/'
}
},
// 将CSS文件压缩,并将多个文件合并成一个单一的文件。
cssmin: {
build: {
files: {
'css/cssmin.min.css': [ 'css/*.css' ]
}
}
},
watch: {
js: {
files: [ 'js/*.js' ],
tasks: [ 'uglify','copy' ]
},
css: {
files: [ 'css/*.css' ],
tasks: [ 'autoprefixer','cssmin' ]
}
}
});
// 加载提供任务的插件
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTask('grunt-autoprefixer');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-watch');
// 默认任务
grunt.registerTask(
'default', ['jshint', 'copy', 'concat', 'uglify', 'watch']);
}
以上是package.json和Gruntfile.js文件的配置以及目录结构;
操作命令grunt时,为什么报以下错误?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
可能大家没有注意到,报的错误是
grunt.loadNpmTask is not a function
,仔细看你的代码,有一行grunt.loadNpmTask('grunt-autoprefixer')
,这一行报错了,少了个s
。试试安装grunt-cli。
npm install grunt-cli -g
task 里面,没有default任务。