如果是 react-native 项目,需要处理 flow 语法,安装@babel/preset-flow
安装
yarn add -D babel-loader @babel/core @babel/preset-env
.babelrc
{
"presets": [
"@babel/preset-env"
]
}
webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.(js|jsx|ts|tsx)$/,
use: ['babel-loader'],
}
],
}
}
安装
yarn add -D babel-loader @babel/core @babel/preset-env @babel/preset-typescript
.babelrc
{
"presets": [
"@babel/preset-env",
"@babel/preset-typescript"
]
}
webpack.config.js 同上
上述补充安装
yarn add -D @babel/preset-react
.babelrc
{
"presets": [
"@babel/preset-env",
"@babel/preset-typescript",
"@babel/preset-react"
]
}
webpack.config.js 同上
上述补充安装
yarn add -D @babel/preset-flow
.babelrc
{
"presets": [
"@babel/preset-env",
"@babel/preset-typescript",
"@babel/preset-react",
"@babel/preset-flow"
]
}
webpack.config.js 同上