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

标签 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

非常感谢

最佳答案

使用展平属性:

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

关于javascript - 使用 grunt 编译时保持文件夹结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26474502/

相关文章:

javascript - 为什么我的 Cordova Android 应用程序在使用类声明定义对象时抛出 "reserved word"错误?

javascript - jquery focus 表现奇怪,只在第一次工作

javascript - 找不到 Npm 模块 ""。安装了吗?

node.js - 如何在 Gulp-Jade 中设置默认文档类型

javascript - 隐藏文本区域时无法复制到剪贴板

javascript - 如何从 javascript 中的 location.href 获取请求 uri?

javascript - 使用 pug-html-loader 将数据传递给哈巴狗(无法读取未定义的属性)

node.js - 输入是自动关闭的,不应有内容 Jade-Lang 问题

javascript - 硫化 polymer 一次性绑定(bind) src 属性

javascript - 编译到 wwwroot 中的 Typescript 给出 "Duplicate identifier"错误