简体   繁体   English

React-App- Rewired 不会添加 Babel 插件

[英]React-App- Rewired won't add Babel Plugin

So I am trying to run react-native using react-native-web.所以我正在尝试使用 react-native-web 运行 react-native。 It requires some babel plugins to be added.它需要添加一些 babel 插件。

My app was created using react-app-rewired.我的应用程序是使用 react-app-rewired 创建的。 I have tried several ways to add the babel plugin, however, with no success.我尝试了几种方法来添加 babel 插件,但是都没有成功。

I am using a config-overrides.js file that looks like this:我正在使用如下所示的config-overrides.js文件:

const { override, addBabelPlugins, addDecoratorsLegacy, fixBabelImports } = require('customize-cra');

const addHandleBarsLoader = config => {
    // add handlebars-loader so that handlebars templates in
    // webpack-dev-server's served html files are parsed
    // (specifically the meta tags)
    config.module.rules.push({ test: /\.html$/, loader: 'handlebars-loader' });
    return config;
}


module.exports = override(
    addHandleBarsLoader,
    fixBabelImports('import', {
        libraryName: 'antd',
        libraryDirectory: 'es',
        style: true,
      }),addBabelPlugins('@babel/plugin-proposal-class-properties'),
);

I know the other config override works, however the babel keeps ignoring the new plugin (which is installed, as well as everything else).我知道其他配置覆盖有效,但是 babel 一直忽略新插件(已安装,以及其他所有内容)。

Also, I am building the app through the react-app-rewired build.此外,我正在通过 react-app-rewired 构建构建应用程序。

That is the error message I get while it tries to build这是我在尝试构建时收到的错误消息

./node_modules/rn-bottom-drawer/src/BottomDrawer.js
SyntaxError: /Users/admin/Documents/Meirim/Workspace/meirim/node_modules/rn-bottom-drawer/src/BottomDrawer.js: Support for the experimental syntax 'classProperties' isn't currently enabled (13:20):

  11 |
  12 | export default class BottomDrawer extends Component{
> 13 |   static propTypes = {
     |                    ^
  14 |     /**
  15 |      * Height of the drawer.
  16 |      */

Add @babel/plugin-proposal-class-properties (https://git.io/vb4SL) to the 'plugins' section of your Babel configto enable transformation.

Many thanks(:非常感谢(:

Gal加尔

找到解决方案,只需使用名为addExternalBabelPlugin的函数代替

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM