简体   繁体   English

运行目录中的所有文件

[英]Run all files in a directory

I want to have a config directory, with every config in a file.我想要一个配置目录,每个配置都在一个文件中。 So at the start of my react app, everything in the config folder runs.所以在我的 React 应用程序开始时,config 文件夹中的所有内容都会运行。 Also if you have a better approach I would be happy to know 😊另外,如果您有更好的方法,我很高兴知道😊

For example (/config):例如(/配置):

firebase.js firebase.js

import * as firebase from 'firebase'
import 'firebase/auth'
import 'firebase/firestore'

const firebaseConfig = {
 // ...
}

firebase.initializeApp(firebaseConfig)

material-ui.js材料-ui.js

import coolThings from 'whatever'
// ...
export theme

You get the idea你明白了

Create an index file inside config, and import every config file there.在 config 中创建一个索引文件,并在那里导入每个配置文件。 Then import the config directory inside the main app.然后在主应用程序中导入配置目录。 That way the imported directory will run the index.js (config/index.js), this will run every config file inside the config folder.这样导入的目录将运行 index.js (config/index.js),这将运行 config 文件夹中的每个配置文件。

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

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