问题描述
我刚开始使用grunt-init。我有一切工作。
我想知道是否有办法根据以前提示的答案来提示条件复制根文件。
道具应该是要复制/不复制的文件的路径,并且该值可以是带有条件的模板字符串。例如,假设您有两个不同的 main.js
文件,其中一个是空的,另一个是您想要重复使用的代码:
{
app / js / main-empty.js:{%if(empty){%} app / js / main.js {% }},
app / js / main-skeleton.js:{%if(!empty){%} app / js / main.js {%}%}
}
destpath
检查 props.empty
变量来自 template.js
文件,正确复制并重命名。
以下是,显示例如,template.js
和 rename.js
。
I've just started using grunt-init. I have everything working.And I was wondering if there is a way to do conditional copy root files based on prompts which based on answers to previous prompts.
You can make use of the rename.json
file via the docs.
The prop should be the path to the file you want to copy/not copy, and the value can be a template string with a conditional. For example, let's say you had two different main.js
files, one empty and one with code you tend to re-use:
{
"app/js/main-empty.js": "{% if (empty) { %}app/js/main.js{% } %}",
"app/js/main-skeleton.js": "{% if (!empty) { %}app/js/main.js{% } %}"
}
The destpath
checks the value of the props.empty
variable from your template.js
file, copies and renames correctly.
Here is a link to a gist showing the template.js
and rename.js
for that example.
这篇关于grunt-init模板条件拷贝文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!