Grunt动态文件映射会生成过多的路径

时间:2015-01-13 10:39:12

标签: css gruntjs less

我使用以下内容:

var path = require('path');

module.exports = function(grunt) {

  grunt.initConfig({
    less: {
      options: {
        paths: '/',
        yuicompress: false,
        ieCompat: true,
        compress: false,
        sourceMap: true,
        sourceMapFilename: 'alice/public/local/less/intfarm.css.map',
        require: [
          'alice/public/local/less/intfarm.less'
        ]
      },
      src: {
        expand: true,
        src: ['alice/public/local/less/*.less'],
        ext: '.css',
        dest: 'alice/public/local/css/local/compiled/',
      }
    },
  });

  grunt.loadNpmTasks('grunt-contrib-less');
  grunt.registerTask('default', ['less']);
}

我不明白为什么'src'路径也为'dest'路径生成..:

/alice/public/local/css/local/compiled/alice/public/local/less/account.css

我在期待:

/alice/public/local/css/local/compiled/account.css

1 个答案:

答案 0 :(得分:0)

这是因为您没有使用cwd选项。 src选项包含matching patterns,它解析为相对于cwd路径的路径。简单来说,src中匹配的所有文件路径都位于dest结果中。

所以你需要以下配置来解决你的问题。

src: {
    expand: true,
    cwd: 'alice/public/local/less/',
    src: ['*.less'],
    ext: '.css',
    dest: 'alice/public/local/css/local/compiled/',
  }