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

Keep folders structure while compiling with grunt

本文关键字:文件夹 结构 grunt 编译 使用      更新时间:2023-09-26

我正在使用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

非常感谢

使用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',
  }]