有没有办法将每个配置文件放在config Directory中,而不是root Node Project中?

发布于 2025-01-18 04:17:54 字数 625 浏览 0 评论 0原文

最近,我一直在创建一个 chrome 扩展,为此,我使用了一堆需要配置文件的工具和捆绑器 - 通常以点开头。在根目录中,一切看起来都那么混乱,我花了几秒钟才在根目录中找到一个文件。

-----
|__ src/
|__ static/
|__ .prettierc
|__ .prettierignore
|__ .gitignore
|__ .parcelrc
|__ README.md
|__ manifest.json
|__ popup.html

我想要做的是将每个配置文件放入名为 config/ 的目录中,如我在此处所示。

-----
|__ src/
|__ static/
|-- config/
|   |__ .prettierc
|   |__ .prettierignore
|   |__ .gitignore
|   |__ .parcelrc
|
|__ README.md
|__ manifest.json
|__ popup.html

如何在不破坏正常功能的情况下实现这一目标?谢谢!

我知道有些工具可以让您在任何地方定义配置文件。然而,其中一些是严格的,你甚至不能重命名它们。我查找了我使用的工具,但找不到有关此问题的任何信息。

Lately, I've been creating a chrome extension and for that, I use a bunch of tools and bundlers that requires a config file-usually starting with a dot. In the root directory, everything looks so cluttered, and it takes a few seconds for me to find a file in the root.

-----
|__ src/
|__ static/
|__ .prettierc
|__ .prettierignore
|__ .gitignore
|__ .parcelrc
|__ README.md
|__ manifest.json
|__ popup.html

What I want to do is to put every config file into a directory named config/ as I show here.

-----
|__ src/
|__ static/
|-- config/
|   |__ .prettierc
|   |__ .prettierignore
|   |__ .gitignore
|   |__ .parcelrc
|
|__ README.md
|__ manifest.json
|__ popup.html

How can I achieve this without breaking the normal functionality? Thanks!

I know that some tools lets you define your config file anywhere you want. However, some of them are strict and you can't even rename them. I looked up for the tools I used but I cannot find any information about this issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若有似无的小暗淡 2025-01-25 04:17:54

1。使用IDE设置隐藏配置文件

我建议您将其保留在其默认位置,因为这是这样做的常见约定。取而代之的是,您可以隐藏它们,这是我在大多数时候要保持项目结构清洁的操作。

如果使用VS代码,则可以添加.vscode/settings.json,然后隐藏您不想在Explorer选项卡中看到的文件。您可以在需要检查或编辑任何内容时将其重新切换。

.vscode/settings.json您的情况的文件内容:

{
  "files.exclude": {
    ".prettierrc": true,
    ".prettierignore": true,
    ".gitignore": true,
    ".parcelrc": true
  }
}

同样,如果您使用JetBrains IDES,请转到file>设置>编辑>文件类型>忽略文件和文件夹,并附加要隐藏的文件列表。您的导航器会更干净。

2。使用VS代码扩展名nest Files

{
  // keep other settings as they are, and add the following at the bottom:
  "explorer.experimental.fileNesting.patterns": {
    "configs": ".gitignore, .prettierrc, .prettierignore, .parcelrc"
  }
}
  • 添加一个名为configs的空文件您的项目。
    最后,您必须拥有类似的东西,这可能是您要寻找的东西:

”在此处输入图像描述”

3。将标志添加到您运行的命令中,以使用配置文件的其他路径

如果您仍然想更改其位置,这可能对您有所帮助。.

运行Prettier命令时,添加以下内容标志:

prettier --config [.prettierrc path] --ignore-path [.prettierignore path]

1. Use IDE settings to hide config files

I recommend that you keep them in their default location since it is a common conventation to do so. Instead, you can just hide them and this is what I do most of the time to keep my project structure clean.

If you use VS Code, you can add a .vscode/settings.json and hide the files you don't want to see in the explorer tab. You can toggle them back when you need to check or edit any.

.vscode/settings.json file content for your case:

{
  "files.exclude": {
    ".prettierrc": true,
    ".prettierignore": true,
    ".gitignore": true,
    ".parcelrc": true
  }
}

Similarly, if you use JetBrains IDEs, go to File > Settings > Editor > File Types > Ignore files and folders and append the list of files that you want to hide. Your navigator will be much cleaner.

2. Use a VS Code extension to nest files

{
  // keep other settings as they are, and add the following at the bottom:
  "explorer.experimental.fileNesting.patterns": {
    "configs": ".gitignore, .prettierrc, .prettierignore, .parcelrc"
  }
}
  • Add an empty file named configs in the root of your project.
    Finally, you must have something like this which is probably what you are looking for:

enter image description here

3. Add flags to commands you run to use a different path for config files

If you still want to change their location, this might be helpful for you..

When running prettier command, add the following flags:

prettier --config [.prettierrc path] --ignore-path [.prettierignore path]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文