Group all files in import statements and export statement in ES6

Viewed 227

I have these three files - tabs, routes, urls in a folder called config

Folder structure

config
| - urls 
| - tabs
| - routes

Here's what I tried so far. Created an index.js file in config folder where I could write all the export statements.

export * from './routes'
export * from './urls'
export * from './tabs'

I want to nest all the files like below in import statement and use them wherever needed in other .js files

import {tabs, routes, urls } from '../config'

How do I group all the files in one single import statement. Could anyone please help?

3 Answers

Is this what you're looking for?

config/index.js

export * as routes from './routes'
export * as urls from './urls'
export * as tabs from './tabs'

Use import *

import * from '../config/';

I was able to do it this way. But, is there a better way?

import routes from './routes';
import urls from './urls';
import tabs from './tabs';

export { routes, tabs, urls };

And, I'm calling it like this

import {tabs, routes, urls } from '../config'
Related