不能让grunt-sass来构建,输出空文件?

时间:2021-11-22 20:18:10

So I have a grunt script which worked fine:

所以我有一个很烂的剧本

module.exports = function (grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        sass: {
            dev: {
                options: {
                    sourceMap: false,
                    sourceComments: 'none',
                    errLogToConsole: true,
                    check: false,
                    precision: 1,
                    includePaths: [
                        '../Scripts/lib/bootstrap-sass-official/assets/stylesheets'
                    ],
                    outputStyle: 'nested'
                },
                files: {
                    '../Content/styles/output/ModellingContent.css': '../Content/styles/ModellingContent.scss',
                    '../Content/styles/output/Configure.css': '../Content/styles/Configure.scss'
                }
            },
            build: {
                options: {
                    sourceMap: false,
                    includePaths: [
                        '../Scripts/lib/bootstrap-sass-official/assets/stylesheets'
                    ],
                    outputStyle: 'compressed'
                },
                files: {
                    '../Content/styles/output/ModellingContent.css': '../Content/styles/ModellingContent.scss',
                    '../Content/styles/output/Configure.css': '../Content/styles/Configure.scss'
                }
            }
        },
        watch: {
            css: {
                files: '../Content/styles/**/*.scss',
                tasks: [
                    'sass:dev'
                ],
                options: {
                    spawn: false,
                    livereload: true
                }
            },
            shared_config: {
                files: '../Content/styles/global/_shared-vars.json',
                tasks: [
                    'shared_config',
                    'sass:dev'
                ],
                options: {
                    spawn: false,
                    livereload: true
                }
            }
        },
        shared_config: {
            default: {
                options: {
                    name: "globalStyle",
                    cssFormat: "dash",
                    jsFormat: "dash"
                },
                src: "../Content/styles/global/_shared-vars.json",
                dest: [
                    "../Content/styles/global/_shared-vars.scss",
                    "../Content/styles/global/_shared-vars.js"
                ]
            },
        }
    });

    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-preen');
    grunt.loadNpmTasks('grunt-sass');
    grunt.loadNpmTasks('grunt-shared-config');

    grunt.registerTask('deploy', [
        'preen',
        'build'
    ]);

    grunt.registerTask('build', [
        'shared_config',
        'sass:build'
    ]);

    grunt.registerTask('watch', [
        'default',
        'watch'
    ]);

    grunt.registerTask('default', [
        'shared_config',
        'sass:dev'
    ]);
}

But when I run this, grunt just stops in the sass:dev task and creates empty css files. This is what I get back in the console:

但是当我运行它时,grunt仅仅停留在sass:dev任务中并创建空的css文件。这是我在控制台得到的:

Running "shared_config:default" (shared_config) task
>> File: ../Content/styles/global/_shared-vars.scss created.
>> File: ../Content/styles/global/_shared-vars.js created.

Running "sass:build" (sass) task

I've reinstalled everything several times, but I can't figure out the problem.

我已经重新安装了好几次了,但是我不能解决问题。

2 个解决方案

#1


0  

I don't know if this nesting is absolutely required, but when I use grunt-sass, I put files inside dist. The grunt-sass Usage example does that too.

我不知道是否绝对需要这个嵌套,但是当我使用grunt-sass时,我将文件放到dist中。

So maybe the following sass:build definition would work for you:

所以,也许下面的sass:build definition对你有用:

        build: {
            options: {
                sourceMap: false,
                includePaths: [
                    '../Scripts/lib/bootstrap-sass-official/assets/stylesheets'
                ],
                outputStyle: 'compressed'
            },
            dist: {
                files: {
                    '../Content/styles/output/ModellingContent.css': '../Content/styles/ModellingContent.scss',
                    '../Content/styles/output/Configure.css': '../Content/styles/Configure.scss'
                }
            }
        }

#2


0  

I figured out that I had a variable misconfigured. It was set to $size: $size. That it didn't report the error I suppose is a but, and it made me think it was something more serious.

我发现我有一个可变的错误配置。它被设置为$size: $size。它没有报告错误,我认为是,但是,它使我认为它是更严重的事情。

#1


0  

I don't know if this nesting is absolutely required, but when I use grunt-sass, I put files inside dist. The grunt-sass Usage example does that too.

我不知道是否绝对需要这个嵌套,但是当我使用grunt-sass时,我将文件放到dist中。

So maybe the following sass:build definition would work for you:

所以,也许下面的sass:build definition对你有用:

        build: {
            options: {
                sourceMap: false,
                includePaths: [
                    '../Scripts/lib/bootstrap-sass-official/assets/stylesheets'
                ],
                outputStyle: 'compressed'
            },
            dist: {
                files: {
                    '../Content/styles/output/ModellingContent.css': '../Content/styles/ModellingContent.scss',
                    '../Content/styles/output/Configure.css': '../Content/styles/Configure.scss'
                }
            }
        }

#2


0  

I figured out that I had a variable misconfigured. It was set to $size: $size. That it didn't report the error I suppose is a but, and it made me think it was something more serious.

我发现我有一个可变的错误配置。它被设置为$size: $size。它没有报告错误,我认为是,但是,它使我认为它是更严重的事情。