简体   繁体   English

在全局安装时,Yeoman生成器找不到.yo-rc.json文件

[英]Yeoman generator can't find .yo-rc.json file when installed globally

I have a simple yeoman generator that is all pretty much ready to go. 我有一个简单的yeoman生成器,几乎可以使用了。 However, it is heavily dependent on the .yo-rc.json file, as I read important configurations from it every time I run the generator. 但是,它在很大程度上依赖于.yo-rc.json文件,因为每次运行生成器时都会从中读取重要的配置。

This works fine if I am running it from the project's directory (by project I mean the generator's project itself), but it won't find it when I am attempting to run it from another project, even with all the steps including npm link . 如果我从项目目录中运行它,则效果很好(按项目,我是指生成器的项目本身),但是当我尝试从另一个项目中运行它时,即使包括npm link在内的所有步骤都找不到它。

I feel like I missed something important here, but can't seem to find it in the documentation. 我觉得我在这里错过了一些重要的事情,但是似乎无法在文档中找到它。 Am I supposed to somehow set up a global .yo-rc.json file when my generator is installed globally? 在全局安装生成器时,是否应该以某种方式设置全局.yo-rc.json文件? Is there a step or configuration I missed? 有没有我错过的步骤或配置?

I doubt this is relevant, but in case it is, this is being developed run on Windows 7. 我怀疑这是否相关,但如果确实如此,它正在Windows 7上运行。

Thanks! 谢谢!

.yo-rc.json is only used for local project configuration. .yo-rc.json仅用于本地项目配置。 It is not meant to be used for global configuration. 它不打算用于全局配置。

For global configuration, you can use the store: true option for each prompts you want to remember with this.prompt() . 对于全局配置,您可以使用this.prompt()对每个要记住的提示使用store: true选项。

The reason behind this is that a user creating a new project doesn't necessarily want his previous choices applied. 其背后的原因是,创建新项目的用户不一定要应用以前的选择。 So the configuration is kept local to a project, so the generator can know the choices user made in the past for the current project; 因此,配置保留在项目本地,这样生成器就可以知道用户过去对当前项目所做的选择。 but not globally applied to all the other project they might created. 但不会全局应用于他们可能创建的所有其他项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM