th3rdwave / react-native-safe-area-context

A flexible way to handle safe area insets in JS. Also works on Android and Web!
MIT License
2.14k stars 197 forks source link

How to use with react-native-web and Vite? #430

Closed stereobooster closed 1 year ago

stereobooster commented 1 year ago

This is my vite.config

import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { esbuildFlowPlugin } from "@bunchtogether/vite-plugin-flow";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  resolve: {
    alias: {
      "react-native": "react-native-web",
      "react-native-safe-area-context":
        "react-native-safe-area-context/lib/module/index.js",
    },
  },
  optimizeDeps: {
    esbuildOptions: {
      plugins: [
        esbuildFlowPlugin(/\.(flow|jsx?)$/, (path) =>
          /\.jsx$/.test(path) ? "jsx" : "jsx"
        ),
      ],
    },
  },
});

I tried to alias react-native-safe-area-context to react-native-safe-area-context/lib/module/index.js and to react-native-safe-area-context/lib/commonjs/index.js. Both resulting in this error

 import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';

react-native-web itself works fine with Vite.

Related https://github.com/necolas/react-native-web/issues/2292.

I'm new to this subject, but shouldn't there be specific distribution for web?

stereobooster commented 1 year ago

Sorry for posting duplicate. Just found the answer https://github.com/th3rdwave/react-native-safe-area-context/issues/202#issuecomment-1204474830