大多数咕噜声任务都找不到



这是我第一天使用grunt,我正在尝试使用这些教程使其工作

https://24ways.org/2013/grunt-is-not-weird-and-hard/

https://css-tricks.com/autoprefixer/

而我的咕噜咕噜文件.js是这样的:

module.exports = function(grunt) {
// 1. All configuration goes here 
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
watch: {
scripts: {
files: ['scripts/app.js'],
tasks: ['uglify'],
options: {
spawn: false,
}//For some reason I had a come here. Don't know if it matters
},
css: {
files: ['content/app.scss'],
tasks: ['sass'],
options: {
spawn: false,
}
},
styles: {
files: ['content/app.css'],
tasks: ['autoprefixer']
}
},
uglify: {
build: {
src: "scripts/app.js",
dest: "scripts/app-final.js"
}
},
sass: {
dist: {
options: {
style: 'compressed'
},
files: {
'content/app.css': 'content/app.scss'
}
}
},
autoprefixer: {
dist: {
files: {
'content/app-prefixed.css': 'content/app.css'
}
}
},
imagemin: {
dynamic: {
files: [{
expand: true,
cwd: 'assets/img/',
src: ['**/*.{png,jpg,gif}'],
dest: 'assets/img/'
}]
}
}
});

// 3. Where we tell Grunt we plan to use this plug-in.
grunt.loadNpmTasks(
'grunt-contrib-uglify',
'grunt-contrib-sass',
'grunt-autoprefixer',
'grunt-contrib-watch',
'grunt-contrib-imagemin'
);
// 4. Where we tell Grunt what to do when we type "grunt" into the terminal.
grunt.registerTask(
'default', [
'watch',
'uglify',
'sass',
'autoprefixer',
'imagemin'
]);
};

但是当我尝试咕噜咕噜手表手表时,我得到这个:

# grunt watch
Warning: Task "watch" not found. Use --force to continue.
Aborted due to warnings.

让事情变得更奇怪grunt uglify被看到

# grunt uglify
Running "uglify:build" (uglify) task
>> Destination scripts/app-final.js not written because src files were empty.
>> No files created.
Done, without errors.

跑步grunt --help给了我一件有趣的事情

Available tasks
uglify  Minify files with UglifyJS. *
default  Alias for "watch", "uglify", "sass", "autoprefixer", "imagemin" tasks.

我真的找不到丑陋和其他功能之间的区别。VS Code 没有给我任何错误。我安装了所有使用过的任务。我已安装节点。

重新启动 VS Code 无济于事。我认为这并不重要,但以防万一,我使用的是 Linux。

重新安装依赖项也无济于事

您执行以下操作:

grunt.loadNpmTasks(
'grunt-contrib-uglify',
'grunt-contrib-sass',
'grunt-autoprefixer',
'grunt-contrib-watch',
'grunt-contrib-imagemin'
);

将其替换为:

grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-autoprefixer');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-uglify');

出于某种原因,Grunt 不会在grunt.loadNpmTasks中接受多个参数。您可以在文档中查看 loadNpmTasks - 函数的正确用法:https://gruntjs.com/sample-gruntfile

最新更新