[英]What to use in tsconfig, commonjs, umd, or es6 module?
What module
to use in tsconfig
, commonjs or es6?在
tsconfig
、 commonjs 或 es6 中使用什么module
?
How to make desicion?如何做决定? I need that output module will work in client/back sides.
我需要输出模块在客户端/后端工作。
So here we are talking about the module option that will be used by typescript to determine what is the name of the module that will compile your code to the targeted version of javascript you specified with the option target
.因此,这里我们讨论的是 typescript 将使用的模块选项,以确定将您的代码编译为您使用选项
target
指定的 JavaScript 目标版本的模块的名称。
So the underlying question you are asking is, what is my target ?所以你问的根本问题是,我的目标是什么? Should I target ES3, ES5, ES6, ES7, ES8 or ... ES42 ?
我应该针对 ES3, ES5, ES6, ES7, ES8 还是 ... ES42 ?
Answer : the compatibility .答:兼容性。
In 2020 you propably target ES5
or ES6
(which is the default value).在 2020 年,您可能会以
ES5
或ES6
(这是默认值)为目标。
(You can ignore CommonJS
because it relate to ES3 which is 99% chance irrelevant to you) (您可以忽略
CommonJS
因为它与 ES3 相关,而 99% 的机会与您无关)
If your code is made to be executed on browsers, I would recommand you to look which is the latest version supported by all your targeted browser and take the one that is supported by all.如果您的代码要在浏览器上执行,我建议您查看所有目标浏览器支持的最新版本,并选择所有浏览器都支持的版本。
Ex: Safari ES6, Firefox ES8, Chrome ES8 : so you choose ES6 as target so your code works on every targeted browser.例如:Safari ES6、Firefox ES8、Chrome ES8:所以你选择 ES6 作为目标,这样你的代码就可以在每个目标浏览器上运行。
The website caniuse.com is usefull to know which features are supported and which are not网站caniuse.com有助于了解支持哪些功能,哪些不支持
If your code is made to run on backend (node.js), look at which version of node.js is running.如果您的代码要在后端 (node.js) 上运行,请查看正在运行的 node.js 版本。 Every version of node have different capabilities.
每个版本的节点都有不同的功能。
You can have a look here你可以看看这里
Additionnal materials :附加材料:
What version of Javascript is supported in node.js node.js 支持什么版本的 Javascript
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.