【问题标题】:Grunt "watch.sass.files" missing咕噜声“watch.sass.files”丢失
【发布时间】:2014-02-26 02:11:12
【问题描述】:

从 Grunt 开始,我喜欢它,但由于我的 sass 实现不断出错,所以无法让它工作。我收到以下警报:

Danis-MacBook-Pro:020 DanielRamirez$ grunt
Running "concat:dist" (concat) task
File "js/build/production.js" created.

Running "uglify:build" (uglify) task
File js/build/production.min.js created.
>> No "sass" targets found.
Warning: Task "sass" failed. Use --force to continue.

Aborted due to warnings.
Danis-MacBook-Pro:020 DanielRamirez$ 

如果我--force 我得到以下信息:

Danis-MacBook-Pro:020 DanielRamirez$ grunt
Running "concat:dist" (concat) task
File "js/build/production.js" created.

Running "uglify:build" (uglify) task
File js/build/production.min.js created.
>> No "sass" targets found.
Warning: Task "sass" failed. Use --force to continue.

Aborted due to warnings.
Danis-MacBook-Pro:020 DanielRamirez$ 

这是我的 Gruntfile.js:

module.exports = function(grunt) {

    // 1. All configuration goes here
    grunt.initConfig({

        pkg: grunt.file.readJSON('package.json'),

        // 2. Configuration for concatinating files goes here.

        // Concatonate various files into one
        concat: {
            dist: {
                src: [
                    'js/vendor/*.js', // All JS in the libs folder
                    'js/plugin.js', // All JS in the libs folder
                    'js/global.js'  // This specific file
                ],
                dest: 'js/build/production.js',
            }
        },

        // Creates a minified version of the javascript files of the project
        uglify: {
            build: {
                src: ['js/vendor/*.js', 'js/plugin.js', 'js/global.js'],
                dest: 'js/build/production.min.js'
            }
        },

         // Minifies automatically the images of the project
        // imagemin: {
        //     dynamic: {
        //         files: [{
        //             expand: true,
        //             cwd: 'images/',
        //             src: ['**/*.{png,jpg,gif}'],
        //             dest: 'images/build/'
        //         }]
        //     }
        // },

        // Watches for changes done on the project and builds the commands if neccesary
        watch: {

             options: {
                livereload: true,
            },

            scripts: {
                files: ['js/*.js'],
                tasks: ['concat', 'uglify'],
                options: {
                    spawn: false,
                },
            },

            sass: {
                dist: {
                    options: {
                        style: 'compressed'
                    },
                    files: {
                        'css/build/style.css': 'sass/style.scss'
                    }
                }
            },

            css: {
                files: ['css/*.scss'],
                tasks: ['sass'],
                options: {
                    spawn: false,
                }
            }
        }

    });

    // 3. Where we tell Grunt we plan to use this plug-in.
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    // grunt.loadNpmTasks('grunt-contrib-imagemin');
    grunt.loadNpmTasks('grunt-contrib-sass');
    grunt.loadNpmTasks('grunt-contrib-compass');
    grunt.loadNpmTasks('grunt-contrib-watch');

    // 4. Where we tell Grunt what to do when we type "grunt" into the terminal.
    grunt.registerTask('default', ['concat', 'uglify', 'sass', 'compass', 'watch']);

};

有什么想法吗?

【问题讨论】:

    标签: terminal sass gruntjs watch


    【解决方案1】:

    是的,您所做的就是将整个 Sass 配置放入 watch 配置中。 Grunt 不能以这种方式工作。相反,将您的配置更改为以下内容:

    module.exports = function(grunt) {
    
        // 1. All configuration goes here
        grunt.initConfig({
    
            pkg: grunt.file.readJSON('package.json'),
    
            // 2. Configuration for concatinating files goes here.
    
            // Concatonate various files into one
            concat: {
                dist: {
                    src: [
                        'js/vendor/*.js', // All JS in the libs folder
                        'js/plugin.js', // All JS in the libs folder
                        'js/global.js'  // This specific file
                    ],
                    dest: 'js/build/production.js',
                }
            },
    
            // Creates a minified version of the javascript files of the project
            uglify: {
                build: {
                    src: ['js/vendor/*.js', 'js/plugin.js', 'js/global.js'],
                    dest: 'js/build/production.min.js'
                }
            },
            // Compile sass to css
            sass: {
                dist: {
                    options: {
                        style: 'compressed'
                    },
                    files: {
                        'css/build/style.css': 'sass/style.scss'
                    }
                }
            },
    
             // Minifies automatically the images of the project
            // imagemin: {
            //     dynamic: {
            //         files: [{
            //             expand: true,
            //             cwd: 'images/',
            //             src: ['**/*.{png,jpg,gif}'],
            //             dest: 'images/build/'
            //         }]
            //     }
            // },
    
            // Watches for changes done on the project and builds the commands if neccesary
            watch: {
    
                 options: {
                    livereload: true,
                },
    
                scripts: {
                    files: ['js/*.js'],
                    tasks: ['concat', 'uglify'],
                    options: {
                        spawn: false,
                    },
                },
    
                css: {
                    files: ['css/*.scss'],
                    tasks: ['sass'],
                    options: {
                        spawn: false,
                    }
                }
            }
    
        });
    
        // 3. Where we tell Grunt we plan to use this plug-in.
        grunt.loadNpmTasks('grunt-contrib-concat');
        grunt.loadNpmTasks('grunt-contrib-uglify');
        // grunt.loadNpmTasks('grunt-contrib-imagemin');
        grunt.loadNpmTasks('grunt-contrib-sass');
        grunt.loadNpmTasks('grunt-contrib-compass');
        grunt.loadNpmTasks('grunt-contrib-watch');
    
        // 4. Where we tell Grunt what to do when we type "grunt" into the terminal.
        grunt.registerTask('default', ['concat', 'uglify', 'sass', 'compass', 'watch']);
    
    };
    

    【讨论】:

    • 嘿!有效!你在写。它可以编译,但我收到一个错误:语法错误:找不到要导入的文件或不可读:compass/css3。加载路径: /Users/DanielRamirez/Sites/020 /Users/DanielRamirez/Sites/020/sass 位于 sass/_base.scss 的第 86 行,来自 sass/style.scss 的第 7 行 使用 --trace 进行回溯。警告:退出并显示错误代码 1 使用 --force 继续。
    • 如何在 Gruntfile.js 中实现这一点?我在上面的示例中不是已经添加了 grunt-contrib-compass 吗?或者它是不同的东西?很抱歉造成混乱
    • 我会说使用任何一个,但要保持一致;不要同时使用!您始终可以将sass 目标更改为compass。 compass 和 sass 插件彼此不知道,所以要么使用 sass 的 compass 选项,要么只使用 compass 插件。我有一种感觉,如果您经常使用该工具包,指南针插件会更好。
    • 我认为 SASS 是您在编辑时拥有 SASS 功能所必需的。因此,指南针插件也会创建压缩样式文件吗?谢谢你的帮助……真的很有帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-17
    相关资源
    最近更新 更多