将许多模块导入到另一个文件中供其他文件使用(Import many modules in a separate file to be used by another file)

编程入门 行业动态 更新时间:2024-10-14 18:14:07
将许多模块导入到另一个文件中供其他文件使用(Import many modules in a separate file to be used by another file)

我从许多文件中导入很多模块。 有没有办法将所有导入文件放在单独的文件中? 我正在使用模块类型:es2015示例:

import {...} from '....1'; import {...} from '....2'; import {...} from '....'; import {...} from '....300';

然后我将这个文件导入到需要导入模块的文件中,如下所示:

import * as IMPORTS from '...'

不用说这些参考资料没有被发现。

我也尝试了这个stackoverlow线程中的建议方式, 但没有运气。


以下是我迄今为止所做的:

在一个单独的文件中有所有的导入文件。 在另一个文件中有/// <reference path='path to file above' />和从'上面'导出*。 在我想要使用所有这些导入的文件中,从'来自步骤2的文件'具有import * as ...。

我在我试图导入的任何模块上都找不到错误。

I'm importing many modules from many files. Is there a way to have all the import files in a separate file? I'm using module type: es2015 example:

import {...} from '....1'; import {...} from '....2'; import {...} from '....'; import {...} from '....300';

I then import this file in the file that I need the imported modules like so:

import * as IMPORTS from '...'

Needless to say the references are not being found.

I also have tried the suggested way in this stackoverlow thread with no luck.


Here's what I did so far:

In a separate file have all the import files. In another file have ///<reference path='path to file above' /> and export * from 'above'. In the file I want to use all those imports, have import * as ... from 'file from step 2'.

I get a not found error on any of those modules that I try to import.

最满意答案

我最终用出口替换了第1步中创建的文件中的所有导入 。 这样就不需要额外的中间文件(步骤2)。 尽管我现在从第一个文件导入,但第三步从顶部开始是一样的。

I ended up replacing all imports in the file created in step 1 with exports. This way there is no need for an extra intermediary file (step 2). Step three from the top is the same though I'm importing from the first file now.

更多推荐

本文发布于:2023-08-05 20:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1437905.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   模块   导入到   Import   separate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!