简体   繁体   English

在 ES6 中对 import 语句和 export 语句中的所有文件进行分组

[英]Group all files in import statements and export statement in ES6

I have these three files - tabs , routes , urls in a folder called config我在一个名为config的文件夹中有这三个文件 - tabsroutesurls

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.config文件夹中创建了一个index.js文件,我可以在其中编写所有导出语句。

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语句中嵌套如下所有文件,并在其他.js文件中需要时使用它们

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

How do I group all the files in one single import statement.如何将所有文件分组到一个导入语句中。 Could anyone please help?有人可以帮忙吗?

Is this what you're looking for?这是你要找的吗?

config/index.js配置/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'

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

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