使用grunt编译时保留文件夹结构

时间:2014-10-20 20:38:31

标签: javascript gruntjs pug

我正在使用grunt将一些jade文件编译成html文件。

我的文件如下:

index.jade
|--partials/
           view1.jade
           view2.jade

我使用grunt-contrib-jade使用以下代码编译它们:

    jade: {
  compile: {
    options: {
      data: {
        debug: true
      }
    },
    files:
      [{
        expand: true,
        cwd: 'src/',
        src: ['*.jade', '*/*.jade'],
        dest: 'dist/views',
        ext: '.html',
      }]
  }
},

它运行正常,所有文件都已编译但是它会破坏文件结构,将所有文件放在dist/views

有没有办法保持结构,即得到这样的东西?

dist/views
|--------- index.html
|---------/partials/
                   / all other files

非常感谢

1 个答案:

答案 0 :(得分:2)

使用flatten属性:

files:
  [{
    expand: true,
    flatten: false, // <---- don't flatten the folder structure
    cwd: 'src/',
    src: ['**/*.jade'], // <---- also update your glob to grab all the .jade files at once
    dest: 'dist/views',
    ext: '.html',
  }]
相关问题