带前缀的 JS/TS 非全局导入
我一直在这样做:
import * as math from 'mathjs';
但这会导致我的 Webpack 包中包含整个 MathJS 库,所以我试图停止使用 *< /代码> 导入。
不过,当我调用函数时使用 math
前缀,例如 math.round
或 math.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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论