配置 babel-loader 接下来,我们要告诉 babel-loader 编译 react-native-paper 和 react-native-vector-icons。我们还希望禁用读取 babel 配置文件以防止任何冲突。
首先安装所需的依赖项:
yarn add --dev babel-loader @babel/preset-env @babel/preset-react @babel/preset-flow @babel/preset-typescript @babel/plugin-proposal-class-properties @babel/plugin-proposal-object-rest-spread
现在,在 webpack 配置的 module.rules 数组中添加以下内容:
{
test: /\.js$/,
exclude: /node_modules[/\\](?!react-native-vector-icons|react-native-safe-area-view)/,
use: {
loader: 'babel-loader',
options: {
// Disable reading babel configuration
babelrc: false,
configFile: false,
// The configuration for compilation
presets: [
['@babel/preset-env', { useBuiltIns: 'usage' }],
'@babel/preset-react',
'@babel/preset-flow',
"@babel/preset-typescript"
],
plugins: [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-object-rest-spread'
],
},
},
},