简体   繁体   English

在 tsconfig、commonjs、umd 或 es6 模块中使用什么?

[英]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 年,您可能会以ES5ES6 (这是默认值)为目标。

(You can ignore CommonJS because it relate to ES3 which is 99% chance irrelevant to you) (您可以忽略CommonJS因为它与 ES3 相关,而 99% 的机会与您无关)

some article 一些文章


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.

相关问题 支持ES6模块语法和CommonJS - Support ES6 module syntax along with CommonJS 是否可以在 Node.JS 命令行程序中同时使用 CommonJS 和 ES6 模块? - Is it possible to use both CommonJS and ES6 module in a Node.JS command-line program? 如何在 ES6 模块节点应用程序中包含 commonjs 模块? - How to include commonjs module in ES6 module node app? 如何按照 ES6 标准而不是 commonJS 导入配置模块 - How to import config module following ES6 standard not commonJS 在commonjs项目中使用es模块包? - Use an es module package in a commonjs project? 如何将我的CommonJS模块转换为UMD? - How to convert my CommonJS module to UMD? 如何判断一个特定模块是 CommonJS 模块还是 ES6 模块? - How can I tell if a particular module is a CommonJS module or an ES6 module? 我该如何解决 --> File 是一个 CommonJS 模块; 它可以转换为 ES6 模块 - how can i fix --> File is a CommonJS module; it may be converted to an ES6 module “语法错误:不能在模块外使用导入语句”但 tsconfig.json `module` 已经 `commonjs` - "SyntaxError: Cannot use import statement outside a module" but tsconfig.json `module` already `commonjs` 该插件文件同时使用CommonJS和ES6模块系统,我们不支持 - This plugin file is using both CommonJS and ES6 module systems together which we don't support
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM