【发布时间】:2012-12-14 22:10:05
【问题描述】:
对于我正在开发的单页应用程序,我有以下结构:
- 分布
- 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 任务来编译和复制翡翠文件。我想将它们复制到 dist,因为我不想将编译后的 html 文件添加到源代码管理中。但是现在这并不可行,因为您必须指定每个玉文件(现在只有几个,但会增加):
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']
}
}
}
【问题讨论】:
-
你试过“文件数组格式”described here吗?该示例(使用 concat 任务)将
dest属性设置为一个目录:files: [{src: ['src/bb.js', 'src/bbb.js'], dest: 'dest/b/'}]。jade-contrib任务很可能也支持这种格式。 -
没用。它将所有文件复制到一个名为 '.html' 的文件中:) 尝试了 'files: grunt.file.expandMapping(['**/.jade'], 'dist', {cwd: 'src /views'})' 在同一页面上描述,但我得到 expandMapping 未定义。
标签: node.js build-automation pug npm gruntjs