/convert-CommonJS-to-ES-Modules-by-Babel

Converting the CommonJS-formatted scripts to ES2015 Modules syntax

Primary LanguageJavaScript

Converting the CommonJS-formatted scripts to ES2015 Modules syntax

首先,我们使用 Yarn 安装 babel:

yarn add --dev @babel/core @babel/preset-env @babel/node

然后在项目根目录中添加 .babelrc 文件:

{
  "presets": ["@babel/preset-env"]
}

编辑 index.js

import os from 'os';
console.log(os.cpus());

运行

yarn babel-node index.js