Watch 1 Star 1 Fork 0

刘勇 / liuyongotherApache-2.0

Create your Gitee Account
Explore and code with more than 5 million developers,Free private repositories !:)
Sign up
Clone or download
babel.txt 1.36 KB
Copy Edit Web IDE Raw Blame History
liuyong-byte authored 2020-04-19 10:52 . babel

npm install --save-dev @babel/core @babel/cli @babel/preset-env
npm install --save @babel/polyfill
2.在根目录下新建babel.config.js文件,并添加以下代码
const presets = [
["@babel/env"]
];
module.exports = { presets };
3.在package.json文件中配置如下命令(将项目下src文件夹下面的script文件打包到build文件夹下)
...
"scripts": {
"babel-build": "babel src/script -d build/script"
},
...
使用
然后再src/script文件夹下新建index.js和until.js文件随便添加点es6的代码:
src/script/index.js添加如下代码:
import {add} from './until'
console(add(2,3));
src/script/until.js添加如下代码:
export const add = (x,y) => {
return x+y;
}
运行命令:npm run babel-build,在build/script下,就会看到下面的代码
然后我们再试试编译下react
1.安装@babel/preset-react
npm install --save-dev @babel/preset-react
2.babel.config.js文件里面新增如下代码
const presets = [
...
[
"@babel/preset-react",
{
"pragma": "dom", // default pragma is React.createElement
"pragmaFrag": "DomFrag", // default is React.Fragment
"throwIfNamespace": false // defaults to true
}
]
...
]
module.exports = { presets};
————————————————

Comment ( 0 )

Sign in for post a comment

other
1
https://gitee.com/liuyong-byte/liuyong.git
git@gitee.com:liuyong-byte/liuyong.git
liuyong-byte
liuyong
liuyong
master

Search