grunt-init template conditional copy files

两盒软妹~` 提交于 2019-12-11 03:16:13

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/19784736/grunt-init-template-conditional-copy-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!