简体   繁体   English

我应该在 React 项目中将本地 JSON 文件放在哪里?

[英]Where should I put local JSON file in React project?

I have created one JSON configuration file in react project.我在 react 项目中创建了一个 JSON 配置文件。 Following is the project structure where I kept userProvisions.json file ->以下是我保存userProvisions.json文件的项目结构->

.
└── /config
└── /public
└── /src
    └── /utils
        ├── userProvisions.json

Question: Is it a good practice to keep configuration file ( userProvisions.json ) in src folder?问题:将配置文件( userProvisions.json )保存在src文件夹中是一种好习惯吗?

It all depends on the purpose of the file, if it is a simple file and you don't have any problem with anyone accessing that file, you can store it where-ever you want, however, on the other hand if it contains crucial data, you can't prevent others from seeing that file.这完全取决于文件的用途,如果它是一个简单的文件,并且您对访问该文件的任何人都没有任何问题,您可以将它存储在任何您想要的地方,但是,另一方面,如果它包含关键数据,您不能阻止其他人看到该文件。 You should use a database to store and process that data.您应该使用数据库来存储和处理该数据。

Seeing your folder structure it is a good idea to store the "JSON configuration file" in./config/... -> it's totally up to you.查看您的文件夹结构,将“JSON 配置文件”存储在 ./config/... 中是个好主意 -> 这完全取决于您。

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

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