带前缀的 JS/TS 非全局导入

发布于 2025-01-14 15:20:16 字数 396 浏览 3 评论 0原文

我一直在这样做:

import * as math from 'mathjs';

但这会导致我的 Webpack 包中包含整个 MathJS 库,所以我试图停止使用 *< /代码> 导入。

不过,当我调用函数时使用 math 前缀,例如 math.roundmath.add ,这非常好。它有助于区分一堆通用函数名称。

我可以同时拥有命名(非全局)导入和来自同一包的所有函数的前缀吗?

我尝试过

import { add,divide,parse,simple,round}as math from 'maths';

但没有运气。

I have been doing this all over:

import * as math from 'mathjs';

But that leads to the whole MathJS library in my Webpack bundle, so I'm trying to stop using * imports.

It is very nice, though, having the math prefix when I call a function, e.g. math.round or math.add. It helps distinguish a bunch of generic function names.

Can I have both named (non-glob) imports, and a prefix for all the functions coming from the same package?

I've tried

import { add, divide, parse, simplify, round } as math from 'maths';

But no luck.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文