有没有办法将每个配置文件放在 config 目录而不是 Node 项目的根目录中?

Can*_*mus 8 javascript configuration node.js reactjs webpack

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

-----
|__ src/
|__ static/
|__ .prettierc
|__ .prettierignore
|__ .gitignore
|__ .parcelrc
|__ README.md
|__ manifest.json
|__ popup.html
Run Code Online (Sandbox Code Playgroud)

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

-----
|__ src/
|__ static/
|-- config/
|   |__ .prettierc
|   |__ .prettierignore
|   |__ .gitignore
|   |__ .parcelrc
|
|__ README.md
|__ manifest.json
|__ popup.html
Run Code Online (Sandbox Code Playgroud)

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

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

Tar*_*ami 9

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

我建议您将它们保留在默认位置,因为这是常见的做法。相反,您可以隐藏它们,这就是我大部分时间为保持项目结构整洁所做的事情。

如果您使用 VS Code,您可以添加.vscode/settings.json并隐藏您不想在资源管理器选项卡中看到的文件。当您需要检查或编辑任何内容时,可以将它们切换回来。

.vscode/settings.json您的案例的文件内容:

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

Run Code Online (Sandbox Code Playgroud)

同样,如果您使用 JetBrains IDE,请转至File > Settings > Editor > File Types > Ignore files and folders并附加要隐藏的文件列表。您的导航器将会更加干净。

2.使用VS Code扩展来嵌套文件

{
  // keep other settings as they are, and add the following at the bottom:
  "explorer.experimental.fileNesting.patterns": {
    "configs": ".gitignore, .prettierrc, .prettierignore, .parcelrc"
  }
}
Run Code Online (Sandbox Code Playgroud)
  • 添加一个configs在项目根目录中命名的空文件。
    最后,你必须有这样的东西,这可能就是你正在寻找的东西:

在此输入图像描述

3. 向您运行的命令添加标志以使用不同的配置文件路径

如果您仍然想更改他们的位置,这可能对您有帮助。

运行prettier命令时,添加以下标志:

prettier --config [.prettierrc path] --ignore-path [.prettierignore path]
Run Code Online (Sandbox Code Playgroud)