在 TS 中,我有 class.ts 的 Class1,helper.ts 的一些函数,variables 的一些变量。 ts:
例如,variables.ts 看起来像这样:
export const test1 = 'test1';
export const test2 = 0;
export const test3 = 'test3';
export const test4 = 'test4';
然后使用 Webpack,我将 api.ts 作为构建模块的入口。
api.ts
export { Class1 } from './class1';
export { helper1, helper2 } from './helper';
import * as variables from './utils/common-variables';
export { variables };
当我需要 variables.ts 的所有变量时,一切都很好。 我可以在我的 file.js 中执行此操作:
import { variables } from 'api';
然而,有时,我只需要一个变量。所以,我想知道是否可以导入这样的东西:
import { variables.test1 as test } from 'api';
最佳答案
不,那个特定的语法是 not possible – an ImportSpecifier
can only really be a name ,而不是像您那样的属性访问表达式。
不过,您可以直接从 api/utils/common-variables
导入它们,而无需重新导出。
关于javascript - 以特定方式在JS中导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56774616/