简体   繁体   English

对CommonJS模式和TypeScript模块以及ES6的使用感到困惑

[英]Confuse about CommonJS pattern and TypeScript module and ES6 usage

All: 所有:

I wonder if anyone could give me a simple comparison of development flow between CommonJS, Typescript and ES6 with perspective to Module import system( like require(), import "xx", export ), compiler( babel, tsc ) and how to use in Browser(browserify or what?)? 我想知道是否有人可以简单地比较CommonJS,Typescript和ES6之间的开发流程,以及对模块导入系统(如require(),import“ xx”,export),编译器(babel,tsc)的看法以及如何在其中使用浏览器(浏览器还是什么?)?

There are a lot of similarity which confuse me so much, especialy when I need to mix them! 有很多相似之处使我非常困惑,尤其是当我需要混合它们时!

Thanks 谢谢

Here is a simple way to go about things... 这是处理事情的简单方法...

Import all your modules with the ES6 style syntax: 使用ES6样式语法导入所有模块:

import {SpecificBit} from './moduleName';
import * as Everything from './otherModule';

In modules that your write, export members that you want to expose... 在您编写的模块中,导出要公开的成员...

export class SomeClass { //...

export class SomeOtherClass { //...

Or replace the module with a member... 或将模块替换为成员...

export = SomeClass;

Now your development flow is the same everywhere, because the TypeScript compiler will transpile your code based on the module kind switch, which allows you to use ES6 (ie no transformation), UMD (works with AMD and CommonJS), System (as used by SystemJS), or simply AMD, or CommonJS (although UMD covers both of these with the same output). 现在您的开发流程到处都是一样的,因为TypeScript编译器将基于模块种类开关来转换您的代码,这使您可以使用ES6(即,不进行转换),UMD(与AMD和CommonJS一起使用),System(用于SystemJS),或者只是AMD或CommonJS(尽管UMD以相同的输出覆盖了这两种方法)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM