简体   繁体   中英

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. Also if you have a better approach I would be happy to know 😊

For example (/config):

firebase.js

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

const firebaseConfig = {
 // ...
}

firebase.initializeApp(firebaseConfig)

material-ui.js

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

You get the idea

Create an index file inside config, and import every config file there. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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