Babel-入门
时间:2020-02-23 14:37:40 来源:igfitidea点击:
在本教程中,我们将学习使用Babel JavaScript编译器。
先决条件
NodeJS和NPM
为了在我们的项目中使用Babel,我们将需要安装NodeJS和NPM。
NPM是一个节点软件包管理器,我们将使用它来安装Babel。
安装Node和NPM之后,您可以使用以下命令检查版本。
$node -v
这将给出节点版本。
$npm -v
这将给出npm版本。
建立项目
创建一个新项目并为其命名,例如babel-project。
$mkdir babel-project
创建package.json文件
现在在项目文件夹中,运行以下命令npm init以创建package.json文件并填写所需的详细信息。
注意!如果要使用默认值,则可以使用npm init -y命令。
示例输出:
$npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.
See `npm help json` for definitive documentation on these fields
and exactly what they do.
Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
package name: (babel-project)
version: (1.0.0)
description: This is a sample Babel project.
entry point: (index.js) index.html
test command:
git repository:
keywords: babel, javascript
author: Yusuf Shakeel
license: (ISC) MIT
About to write to /Users/yusufshakeel/Desktop/babel-project/package.json:
{
"name": "babel-project",
"version": "1.0.0",
"description": "This is a sample Babel project.",
"main": "index.html",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"babel",
"javascript"
],
"author": "Yusuf Shakeel",
"license": "MIT"
}
Is this OK? (yes) yes
现在,我们准备在我们的项目中设置Babel。

