0

所以我有一个运行良好的 grunt 脚本:

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'
    ]);
}

但是当我运行它时,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

我已经重新安装了几次,但我无法找出问题所在。

4

2 回答 2

0

我不知道这种嵌套是否是绝对需要的,但是当我使用 grunt-sass 时,我filesdist. grunt-sass 用法示例也是这样做的。

所以也许下面的sass:build定义对你有用:

        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'
                }
            }
        }
于 2014-10-14T15:22:12.487 回答
0

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

于 2014-10-15T16:16:33.083 回答