参考Using Node.js require vs. ES6 import/export ,node
Keep in mind that there is no JavaScript engine yet that natively supports ES6 modules. You said yourself that you are using Babel. Babel converts import and export declaration to CommonJS (require/module.exports) by default anyway. So even if you use ES6 module syntax, you will be using CommonJS under the hood if you run the code in Node.es6
There are technical difference between CommonJS and ES6 modules, e.g. CommonJS allows you to load modules dynamically. ES6 doesn't allow this, but there is an API in development for that.浏览器
这二者的区别async
- es6 import为静态引入,require能够动态引入。
- 有时候须要动态引入组件的时候就须要require了。
- 浏览器不支持es6 模块化,因此 es6 import最后会被转为require 实现
第二个回答也基本上说明了这一点ide
There are several usage / capabilities you might want to consider:模块化
- Require:
- You can have dynamic loading where the loaded module name isn't predefined /static, or where you conditionally load a module only if it's "truly required" (depending on certain code flow).
- Loading is synchronous. That means if you have multiple requires, they are loaded and processed one by one.
- ES6 Imports:
- You can use named imports to selectively load only the pieces you need. That can save memory. Import can be asynchronous (and in current ES6 Module Loader, it in fact is) and can perform a little better.
- Also, the Require module system isn't standard based. It's is highly unlikely to become standard now that ES6 modules exist. In the future there will be native support for ES6 Modules in various implementations which will be advantageous in terms of performance.