简体   繁体   English

使用 Grunt 任务运行器时未找到任务错误

[英]Task not found error while using Grunt task runner

I am on a Windows machine and I believe I have installed everything I need to run the grunt task: grunt sass I have already executed the following commands in my terminal:我在 Windows 机器上,我相信我已经安装了运行 grunt 任务所需的一切: grunt sass我已经在终端中执行了以下命令:

npm install grunt-sass --save-dev

npm install time-grunt --save-dev

npm install jit-grunt --save-dev

npm install grunt-contrib-watch --save-dev

npm install grunt-browser-sync --save-dev

I am getting the following error:我收到以下错误:

Warning: Task "sass" not found. Use --force to continue.

Aborted due to warnings.

I have tried every possible solution from other similar posts but to no avail.我已经尝试了其他类似帖子的所有可能解决方案,但无济于事。 My Gruntfile.js is as follows:我的Gruntfile.js如下:

"use strict";

module.exports = function (grunt) {

    require("time-grunt")(grunt);

    require("jit-grunt");

    grunt.initConfig({
        sass: {
            dist: {
                files: {
                    "css/styles.css": "css/styles.scss"
                }
            }
        },
        watch: {
            files: "css/*.scss", 
            tasks: ["sass"]
        },
        browserSync: {
            dev: {
                bsFiles: {
                    src: [
                        "css/*.css",
                        "*.html",
                        "js/*.js"
                    ]
                },
                options: {
                    watchTask: true,
                    server: {
                        baseDir: "./"
                    }
                }

            }

        }

    });

    grunt.registerTask("css", ["sass"]);
    grunt.registerTask("default", ["browserSync", "watch"]);

};

I have managed to find the solution.我设法找到了解决方案。 Make the following changes to the file:对文件进行以下更改:

"use strict";

module.exports = function (grunt) {

    const sass = require('node-sass'); // add this line

    require("time-grunt")(grunt);

    require("jit-grunt")(grunt);

    grunt.initConfig({
        sass: {
            dist: {
                files: {
                    "css/styles.css": "css/styles.scss"
                }
            }
        },
        watch: {
            files: "css/*.scss", 
            tasks: ["sass"]
        },
        browserSync: {
            dev: {
                bsFiles: {
                    src: [
                        "css/*.css",
                        "*.html",
                        "js/*.js"
                    ]
                },
                options: {
                    implementation: sass, //add this line
                    sourceMap: true,      //add this line
                    watchTask: true,
                    server: {
                        baseDir: "./"
                    }
                }

            }

        }

    });

    grunt.registerTask("css", ["sass"]);
    grunt.registerTask("default", ["browserSync", "watch"]);

};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM