用户操作
Opened this issue · 0 comments
juanjuan2wei commented
先本地开一个项目,新建一个文件夹,npm init -y,然后安装babel-cli.
babel-cli
我们可以本地安装它,用它来学习基础知识
npm install --save-dev babel-cli
你马上就可以去编译你的第一个文件
babel my-file.js
这将把编译后的结果直接输入至终端,使用--out-file
或者-o
可以将结果写入指定文件:
babel example.js --out-file compiled.js
# 或
babel example.js -o compiled.js
如果我们像把整个目录编译成一个新的目录,可以使用--out-dir
或者-d
$ babel src --out-dir lib
# 或
$ babel src -d lib
你可以看到,编译后的文件和我们写的源文件是一样的,当然一样,因为这里并没有操作什么。
接下来,我们将运行命令写在package.json
文件中,并用build
字段来标识:
{
"name": "my-project",
"version": "1.0.0",
+ "scripts": {
+ "build": "babel src -d lib"
+ },
"devDependencies": {
"babel-cli": "^6.0.0"
}
}
你现在可以在终端中直接npm run build
了。
上面是运行项目的基础,更多操作: Babel 用户手册
现在所有的准备工作做好了,下一章正式开始babel的学习。