Grunt 0.4 less task : How to not concatenate destination files

后端 未结 2 961
南笙
南笙 2021-01-01 05:11

I want to generate .css partial files from the corresponding .less files

I use the latest versions available from npm, grunt@0.4.0, grunt-contrib-less@0.5.0

相关标签:
2条回答
  • 2021-01-01 05:36

    You'd want to read the Building the files object dynamically section in the docs.

    This would be a direct translation from your current config:

    module.exports = function (grunt) {
        grunt.initConfig({
            less: {
                development: {
                    files: [{
                        expand: true,        // Enable dynamic expansion.
                        cwd: 'htdocs/less',  // Src matches are relative to this path.
                        src: ['*.less'],     // Actual pattern(s) to match.
                        dest: 'htdocs/css',  // Destination path prefix.
                        ext: '.css',         // Dest filepaths will have this extension.
                    }]
                }
            },
        });
    };
    
    0 讨论(0)
  • 2021-01-01 05:37

    Have a look at assemble-less as well. It's based on grunt-contrib-less but is specifically geared towards what you're looking to do. (full disclosure, I'm a maintainer of the project as well).

    For this specific use-case, the advantage that assemble-less has over grunt-contrib-less is that it has a concat: false option that enables you to compiles LESS files individually using any of the src-dest patterns in Grunt. assemble-less also has a require option that will automatically prepend "global" less files (such as variables.less or mixins.less) onto all of the other specified less files, negating the need to actually add @import statements inside each less file.

    So, for example, with assemble-less you would do:

      less: {
        development: {
          options: {
            concat: false
          }
          files: {
            "htdocs/css/": "htdocs/less/*.less"
          }
        }
      }
    
    0 讨论(0)
提交回复
热议问题