简体   繁体   English

模块 CommonJS 与模块 ES6 Node.js

[英]Modules CommonJS vs modules ES6 Node.js

I am new to node.js and I have a choice of CommonJS modules or ES6 modules.What to choose and why?我是 node.js 的新手,我可以选择 CommonJS 模块或 ES6 模块。选择什么,为什么?

The answer depends on what your project setup is.答案取决于您的项目设置。 If you are using a tool such as Webpack, it would make sense to use the ES6 modules as they will provide you with a range of nice features such as arrow functions and classes.如果您正在使用 Webpack 之类的工具,那么使用 ES6 模块会很有意义,因为它们将为您提供一系列不错的功能,例如箭头函数和类。 If your project is using React, you will need these features.如果您的项目使用 React,您将需要这些功能。 In short, the best practice would be to use ES6 modules in your project.简而言之,最佳实践是在您的项目中使用 ES6 模块。

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

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