fix @tamagui/vite-plugin import

This commit is contained in:
Pavel Prichodko 2023-01-13 15:51:21 +01:00
parent 2a1cf9b3e9
commit 351e5fa750
No known key found for this signature in database
GPG Key ID: 0EB8D75C775AB6F1
2 changed files with 7 additions and 126 deletions

View File

@ -1,12 +1,9 @@
// eslint-disable-next-line import/default import { tamaguiPlugin } from '@tamagui/vite-plugin'
import tamagui from '@tamagui/vite-plugin'
import react from '@vitejs/plugin-react-swc' import react from '@vitejs/plugin-react-swc'
import { defineConfig } from 'vite' import { defineConfig } from 'vite'
import type { PluginOption } from 'vite' import type { PluginOption } from 'vite'
const { tamaguiPlugin } = tamagui
process.env.TAMAGUI_TARGET = 'web' process.env.TAMAGUI_TARGET = 'web'
process.env.TAMAGUI_DISABLE_WARN_DYNAMIC_LOAD = '1' process.env.TAMAGUI_DISABLE_WARN_DYNAMIC_LOAD = '1'

View File

@ -1,139 +1,23 @@
// import tamagui from '@tamagui/vite-plugin' import { tamaguiPlugin } from '@tamagui/vite-plugin'
import react from '@vitejs/plugin-react-swc' import react from '@vitejs/plugin-react-swc'
import { defineConfig } from 'vite' import { defineConfig } from 'vite'
// console.log('tamagui', tamagui) import type { PluginOption } from 'vite'
// 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'
const tamaguiConfig = { const tamaguiConfig = {
components: [], components: [],
config: './src/tamagui.config.ts' config: './src/tamagui.config.ts',
// useReactNativeWebLite: true, // useReactNativeWebLite: true,
} }
// https://vitejs.dev/config // https://vitejs.dev/config
export default defineConfig({ export default defineConfig({
define: { define: {
TAMAGUI_TARGET: JSON.stringify('web') TAMAGUI_TARGET: JSON.stringify('web'),
}, },
plugins: [ plugins: [
react(), react(),
tamaguiPlugin(tamaguiConfig) tamaguiPlugin(tamaguiConfig) as PluginOption,
// tamaguiExtractPlugin(tamaguiConfig) // tamaguiExtractPlugin(tamaguiConfig)
] ],
}) })