简体   繁体   English

Grunt文件api创建了不需要的文件

[英]Grunt files api created unwanted files

I have the following piece of code in my Gruntfile.js: 我在Gruntfile.js中有以下代码:

    less: {
        dist: {
            options: {
                paths: ['less/**/*.less'],
                cleancss: true,
                strictImports: true,
                strictUnits: true
            },
            expand: true,
            cwd: 'src',
            src: 'less/style.less',
            dest: 'tmp/less.css'
        }
    },

My goal is to parse all less files in /src/less/**/*.less (currently only style.less ) to a css file in tmp/less.css . 我的目标是将/src/less/**/*.less所有较少文件(目前只有style.less )解析为tmp/less.css的css文件。 Instead the file tmp/less.css/less/style.less is created. 而是创建文件tmp/less.css/less/style.less I noticed similar behaviour for other grunt plugins, so I don't think this has anything to do with the less plugin itself. 我注意到其他grunt插件的类似行为,所以我认为这与插件本身没什么关系。 I know I don't have to use expand and cwd , but I'm trying to understand the Grunt files api for a more complex configuration. 我知道我不必使用expandcwd ,但我正在尝试理解Grunt文件api以获得更复杂的配置。 What am I doing wrong? 我究竟做错了什么?

Typically you will only want to output one or two files (to reduce CSS requests) so it makes more sense for LESS to specify the compile targets explicitly. 通常,您只想输出一个或两个文件(以减少CSS请求),因此LESS明确指定编译目标更有意义。 So a simpler setup similar to yours is probably preferable. 因此,与您的设置类似的简单设置可能更可取。

less: {
    dist: {
        files: {
            'src/tmp/less.css': 'src/less/style.less',
            'src/tmp/less2.css': 'src/less/style.less'
        },
        options: {
            cleancss: true,
            strictImports: true,
            strictUnits: true
        }
    }
},

Something like this should take all .less files in a less dir and output them with the same folder structure in a tmp dir: 像这样的东西应该把所有.less文件放在一个less目录中,并在tmp目录中输出相同的文件夹结构:

less: {
    dist: {
        files: [{
            expand: true,
            cwd: 'src',
            src: ['less/**/*.less'],
            dest: 'tmp/',
            ext: '.css'
        }],
        options: {
            cleancss: true,
            strictImports: true,
            strictUnits: true
        },
    }
}

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

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