66

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?

joerideg
  • 1,818
  • 1
  • 15
  • 18

1 Answers1

72

After playing around for a while I did get a better understanding of things, also thanks to @Andy for the blog by 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).

However if you want to use those in your browser you still need to load and wire those modules with some module loader library because browsers still do not support that. For that you could use a module loader like RequireJS, Browserify, SystemJS or es6-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.

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

joerideg
  • 1,818
  • 1
  • 15
  • 18
  • 3
    even though I prefer RequireJS, don't forget about Webpack. Like SystemJS, Webpack is also agnostic about whether to use AMD, CommonJS or ES6 as a module system. – Alexander Mills Sep 19 '15 at 03:52
  • 1
    [closure and jspm generate code that's faster than Webpack](https://github.com/samccone/The-cost-of-transpiling-es2015-in-2016#the-cost-of-transpiling-es2015-in-2016). – Dan Dascalescu Sep 06 '16 at 19:13
  • [Loading CommonJS modules is not currently supported in this loader and likely won't be](https://github.com/systemjs/systemjs#3-system-nodecjs-loader). It seems that systemjs supports cjs only in nodejs environment. – jeiea Jun 24 '23 at 09:04