node.js - 如何使用 grunt 将编译好的 Jade 文件复制到目标文件夹

标签 node.js build-automation pug npm gruntjs

对于我正在开发的单页应用程序,我有以下结构:

  • 分布
    • css
    • js
    • 部分
    • index.html
  • 源代码
    • css
    • js
    • 观看次数
      • 部分
      • index.jade

目录 dist 将被 express 服务器用于为项目提供服务。我有一些琐碎的任务(使用 grunt-contrib-cleangrunt-contrib-copy)来清理 dist 和复制 src/csssrc/jssrc/libdist

问题在于 src/views。该目录包含需要编译成html文件的jade文件。编译后,我希望它们在 dist 中(dist 根目录中的 index.html,部分作为子目录)。

目前我正在使用 grunt-contrib-jade 任务来编译和复制 Jade 文件。我想将它们复制到 dist,因为我不想将编译后的 html 文件添加到源代码管理中。但是现在这并不可行,因为您必须指定每个 Jade 文件(现在只有几个,但会增加):

   jade: {
        compile: {
            options: {
                pretty: true
            },
            files: {
                // TODO make one line
                'dist/index.html': ['src/views/index.jade'],
                'dist/partials/banner.html': ['src/views/partials/banner.jade'],
                'dist/partials/dashboard.html': ['src/views/partials/dashboard.jade'],
                'dist/partials/navbar.html': ['src/views/partials/navbar.jade'],
                'dist/partials/transfer.html': ['src/views/partials/transfer.jade']
            }
        }
    },

有什么方法可以使用带有目录过滤器的 grunt-contrib-jade 任务(或其他任务)? 像这样:

   jade: {
        compile: {
            options: {
                pretty: true
            },
            dir: {
                'dist': ['src/views']
            }
        }
    }

最佳答案

Grunt wiki - expand mapping 的一点澄清:

grunt.file.expandMapping(patterns, dest [, options])

Note that while this method may be used to programmatically generate a files array for a multi task, the declarative syntax for doing this described in the "Building the files object dynamically" section of the Configuring tasks guide is preferred.

假设如上,配置将如下所示:

files: [ { 
  expand: true, 
  src: "**/*.jade", 
  dest: "dist/", 
  cwd: "src/views", 
  ext: '.html'
} ];

声明式配置的结果相同。

关于node.js - 如何使用 grunt 将编译好的 Jade 文件复制到目标文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14089921/

相关文章:

powershell - PSake 扩展?

linux - Gradle 1.3 : build. gradle 不构建类

javascript - 如何更改谷歌地图API可拖动标记的颜色?

javascript - 修改req.body和res。 Node.Js/Express 应用程序中的参数

javascript - 与 Q.all(promises) 同步解决 promise

node.js - 在 Node.js 上的 Express 中扩展 View 类

javascript - 使用纯 JavaScript 提交表单后重定向

java - 一步构建 Java Web 应用程序

javascript - Node.js Jade : Using conditionals within JavaScript

javascript - 用于 python 和 javascript 的类似 Jade 的模板语言