react native web, __DEV__未定义。

问题描述 投票:0回答:1

如果你想在RN和RN-web之间共享代码。__DEV__ 也应该在这两个平台上提供。

但是我不能添加 DEV 使用 const __DEV__ = process.env.NODE_ENV !== 'production'; new webpack.DefinePlugin({__DEV__})

我可以设置 window.__DEV__ 好,但RN代码使用 __DEV__

我也试过加入 module:metro-react-native-babel-preset

我见过 React Native - __DEV__没有定义。

/* global __DEV__ */ 工作,但希望有办法在不修改所有使用了 __DEV__

reactjs react-native react-native-web
1个回答
0
投票

的方式添加DEV。webpack.config.js,加上这个。

  plugins: [
    // `process.env.NODE_ENV === 'production'` must be `true` for production
    // builds to eliminate development checks and reduce build size. You may
    // wish to include additional optimizations.
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
      __DEV__: process.env.NODE_ENV === 'production' || true,
    }),
  ],

https:/medium.com@alexander.forseliusexperiment-combining-native-web-ios-android-and-macos-development-in-rectnative-part-1-ecd5887e9cfc

© www.soinside.com 2019 - 2024. All rights reserved.