对于我正在开发的单页应用程序,我有以下结构:
- 分布
- css
- js
- 库
- 部分
- index.html
- 源代码
- css
- js
- 库
- 观看次数
- 部分
- index.jade
目录 dist 将被 express 服务器用于为项目提供服务。我有一些琐碎的任务(使用 grunt-contrib-clean、grunt-contrib-copy)来清理 dist 和复制 src/css、src/js、src/lib 到 dist。
问题在于 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/