From 67ceb25c4340c85c3dda9b1d45067e61657d8e91 Mon Sep 17 00:00:00 2001 From: Pavel Prichodko <14926950+prichodko@users.noreply.github.com> Date: Fri, 13 Jan 2023 15:51:21 +0100 Subject: [PATCH] fix @tamagui/vite-plugin import --- apps/vite/vite.config.ts | 5 +- packages/components/vite.config.ts | 128 ++--------------------------- 2 files changed, 7 insertions(+), 126 deletions(-) diff --git a/apps/vite/vite.config.ts b/apps/vite/vite.config.ts index 4c70dbb8..1f686c43 100644 --- a/apps/vite/vite.config.ts +++ b/apps/vite/vite.config.ts @@ -1,12 +1,9 @@ -// eslint-disable-next-line import/default -import tamagui from '@tamagui/vite-plugin' +import { tamaguiPlugin } from '@tamagui/vite-plugin' import react from '@vitejs/plugin-react-swc' import { defineConfig } from 'vite' import type { PluginOption } from 'vite' -const { tamaguiPlugin } = tamagui - process.env.TAMAGUI_TARGET = 'web' process.env.TAMAGUI_DISABLE_WARN_DYNAMIC_LOAD = '1' diff --git a/packages/components/vite.config.ts b/packages/components/vite.config.ts index 738b3041..111602e0 100644 --- a/packages/components/vite.config.ts +++ b/packages/components/vite.config.ts @@ -1,139 +1,23 @@ -// import tamagui from '@tamagui/vite-plugin' +import { tamaguiPlugin } from '@tamagui/vite-plugin' import react from '@vitejs/plugin-react-swc' import { defineConfig } from 'vite' -// console.log('tamagui', tamagui) -// const { tamaguiPlugin, tamaguiExtractPlugin } = tamagui - -// Tamagui exports incorrectly this plugin -function tamaguiPlugin(options): any { - const components = [ - ...new Set([...options.components, 'tamagui', '@tamagui/core']) - ] - const noExternalSSR = new RegExp( - `${components.join('|')}|react-native|expo-linear-gradient`, - 'ig' - ) - - const plugin: any = { - name: 'tamagui-base', - enforce: 'pre', - - config(userConfig, env) { - return { - plugins: [ - // - // envPlugin(['NODE_ENV', 'TAMAGUI_TARGET', 'ENABLE_RSC']), - // viteCommonjs(), - ], - define: { - // reanimated support - 'global.__x': {}, - _frameTimestamp: undefined, - _WORKLET: false, - ...(process.env.NODE_ENV !== 'test' && { - 'process.env.TAMAGUI_TARGET': JSON.stringify( - process.env.TAMAGUI_TARGET || 'web' - ), - 'process.env.NODE_ENV': JSON.stringify( - process.env.NODE_ENV || env.mode - ), - 'process.env.ENABLE_RSC': JSON.stringify( - process.env.ENABLE_RSC || '' - ), - 'process.env.ENABLE_STEPS': JSON.stringify( - process.env.ENABLE_STEPS || '' - ), - 'process.env.IS_STATIC': JSON.stringify(false) - }) - }, - // build: { - // commonjsOptions: { - // transformMixedEsModules: true, - // }, - // }, - ssr: { - noExternal: noExternalSSR - }, - optimizeDeps: { - // disabled: false, - include: ['styleq', 'react-native-reanimated'], - esbuildOptions: { - jsx: 'transform', - // plugins: [ - // esbuildCommonjs([ - // 'styleq', - // 'inline-style-prefixer', - // 'create-react-class', - // 'copy-to-clipboard', - // ]), - // ], - resolveExtensions: [ - '.web.js', - '.web.ts', - '.web.tsx', - '.js', - '.jsx', - '.json', - '.ts', - '.tsx', - '.mjs' - ], - loader: { - '.js': 'jsx' - } - } - }, - resolve: { - // for once it extracts - // mainFields: ['module:jsx', 'module', 'jsnext:main', 'jsnext', 'main'], - extensions: [ - '.web.js', - '.web.ts', - '.web.tsx', - '.js', - '.jsx', - '.json', - '.ts', - '.tsx', - '.mjs' - ], - alias: { - 'react-native/Libraries/Renderer/shims/ReactFabric': - '@tamagui/proxy-worm', - 'react-native/Libraries/Utilities/codegenNativeComponent': - '@tamagui/proxy-worm', - 'react-native-svg': '@tamagui/react-native-svg', - 'react-native': 'react-native-web', - ...(options.useReactNativeWebLite && { - 'react-native': 'react-native-web-lite', - 'react-native-web': 'react-native-web-lite' - }) - } - } - } - } - } - - return plugin -} - -// process.env.TAMAGUI_TARGET = 'web' +import type { PluginOption } from 'vite' const tamaguiConfig = { components: [], - config: './src/tamagui.config.ts' + config: './src/tamagui.config.ts', // useReactNativeWebLite: true, } // https://vitejs.dev/config export default defineConfig({ define: { - TAMAGUI_TARGET: JSON.stringify('web') + TAMAGUI_TARGET: JSON.stringify('web'), }, plugins: [ react(), - tamaguiPlugin(tamaguiConfig) + tamaguiPlugin(tamaguiConfig) as PluginOption, // tamaguiExtractPlugin(tamaguiConfig) - ] + ], })