Javascript browserify/requirejs 模块和 ES6 模块有什么区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28674652/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 02:13:26  来源:igfitidea点击:

What is the difference between browserify/requirejs modules and ES6 modules

javascriptmodulerequirejsbrowserifyecmascript-6

提问by joerideg

I'm still new to ES6 and module loaders and I'm currently looking at combining a browserify setup with ES6. I was wondering if I would still need browserify/requirejs if I'm using ES6 modules. Seems like both allow you to define modules and export them? What is the difference between browserify/requirejs modules and ES6 modules?

我还是 ES6 和模块加载器的新手,我目前正在考虑将 browserify 设置与 ES6 结合起来。我想知道如果我使用 ES6 模块,我是否还需要 browserify/requirejs。似乎两者都允许您定义模块并导出它们?browserify/requirejs 模块和 ES6 模块有什么区别?

回答by joerideg

After playing around for a while I did get a better understanding of things, also thanks to @Andy for the blog by Addy Osmani.

玩了一段时间后,我确实对事情有了更好的理解,还要感谢 @Andy 为Addy Osmani撰写的博客

There are different module systems: AMD (RequireJS), CommonJS (Node) and the new ES6 module syntax (and the old ES5 Global system of course).

有不同的模块系统:AMD(RequireJS)、CommonJS(Node)和新的 ES6 模块语法(当然还有旧的 ES5 全局系统)。

However if you want to use those in your browser you still need to load and wire those modules with some module loader librarybecause browsers still do not support that. For that you could use a module loader like RequireJS, Browserify, SystemJSor es6-module-loader.

但是,如果您想在浏览器中使用它们,您仍然需要使用某些模块加载器库加载和连接这些模块,因为浏览器仍然不支持。为此,您可以使用模块加载器,如RequireJSBrowserifySystemJSes6-module-loader

SystemJS is my personal favorite because it allows you to load any module system (AMD, CommonJS, ES6) and even use them interchangably in 1 app.

SystemJS 是我个人的最爱,因为它允许您加载任何模块系统(AMD、CommonJS、ES6),甚至可以在 1 个应用程序中互换使用它们。

Update: In the mean time Webpackhas become available and should be considered as a module loader as well.

更新:与此同时,Webpack已经可用,也应该被视为模块加载器。