【问题标题】:grunt-contrib-less won't import .css filesgrunt-contrib-less 不会导入 .css 文件
【发布时间】:2015-10-18 12:31:03
【问题描述】:

我的主less文件@private/less/app.less

@import 'a.less';
@import 'b.css';

正在导入:
私人/少/a.less
& private/less/b.css

我的咕噜声文件:

module.exports = function(grunt) {

    grunt.initConfig({
        less: {
            development: {
                options: {
                    paths: ["/css"],
                    yuicompress: true
                },
                files: {
                    "public/css/app.css": "private/less/app.less"
                }
            },
        },

        // running `grunt watch` will watch for changes
        watch: {
            less: {
                files: ['private/less/**/*.less'],
                tasks: ['less'],
                options: {
                    spawn: false
                }
            }
        }
    });

    grunt.loadNpmTasks('grunt-contrib-less');
    grunt.loadNpmTasks('grunt-contrib-watch');

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

};

我的翡翠文件有一个导入语句:

link(rel='stylesheet' href='css/app.css')

CSS 输出@public/css/app.css

// all the a.less styles ....
@import 'b.css';

这给了我找不到文件的错误,因为它使用了 css @import 方法。

有人对在使用 grunt-contrib-less 编译的 .less 文件中导入 .css 文件的方法有任何建议吗?

【问题讨论】:

    标签: gruntjs grunt-contrib-less


    【解决方案1】:

    您可以使用@import (less) 强制lesscss 文件导入为less 文件,而不管扩展名如何

    @import 'a.less';
    @import (less) 'b.css';
    

    导致

    // all the a.less styles ....
    // all the b.css styles .... 
    

    参考:import options: less

    使用@import (less) 将导入的文件视为 Less,无论文件扩展名如何。

    【讨论】:

    • 这解决了这个问题。谢谢!!
    猜你喜欢
    • 1970-01-01
    • 2016-02-02
    • 1970-01-01
    • 1970-01-01
    • 2014-08-31
    • 2015-01-02
    • 2015-07-31
    • 2014-03-07
    • 2015-10-29
    相关资源
    最近更新 更多