@tamagui/vite-plugin 1.112.12 → 1.112.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/vite-plugin",
3
- "version": "1.112.12",
3
+ "version": "1.112.13",
4
4
  "types": "./types/index.d.ts",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "type": "module",
@@ -33,19 +33,24 @@
33
33
  }
34
34
  },
35
35
  "dependencies": {
36
- "@tamagui/fake-react-native": "1.112.12",
37
- "@tamagui/proxy-worm": "1.112.12",
38
- "@tamagui/react-native-svg": "1.112.12",
39
- "@tamagui/static": "1.112.12",
36
+ "@tamagui/fake-react-native": "1.112.13",
37
+ "@tamagui/proxy-worm": "1.112.13",
38
+ "@tamagui/react-native-svg": "1.112.13",
39
+ "@tamagui/react-native-web-lite": "1.112.13",
40
+ "@tamagui/static": "1.112.13",
40
41
  "esm-resolve": "^1.0.8",
41
42
  "fs-extra": "^11.2.0",
42
43
  "outdent": "^0.8.0",
43
44
  "react-native-web": "^0.19.12"
44
45
  },
45
46
  "devDependencies": {
46
- "@tamagui/build": "1.112.12"
47
+ "@tamagui/build": "1.112.13",
48
+ "vite": "6.0.0-beta.1"
47
49
  },
48
50
  "publishConfig": {
49
51
  "access": "public"
52
+ },
53
+ "peerDependencies": {
54
+ "vite": "*"
50
55
  }
51
56
  }
package/src/plugin.ts CHANGED
@@ -1,34 +1,26 @@
1
1
  import type { TamaguiOptions } from '@tamagui/static'
2
- import type { Plugin } from 'vite'
2
+ import { version } from 'vite'
3
+ import type { Plugin, UserConfig } from 'vite'
3
4
  import { transformWithEsbuild } from 'vite'
4
- import { tamaguiOptions, Static, loadTamaguiBuildConfig } from './loadTamagui'
5
5
  import { tamaguiExtractPlugin } from './extract'
6
+ import { Static, loadTamaguiBuildConfig, tamaguiOptions } from './loadTamagui'
6
7
 
8
+ const isVite6 = version.startsWith('6.')
7
9
  const resolve = (name: string) => import.meta.resolve?.(name).replace('file://', '')
8
10
 
9
- export function tamaguiPlugin(
10
- tamaguiOptionsIn: TamaguiOptions & { optimize?: boolean } = {}
11
- ): Plugin | Plugin[] {
12
- const shouldAddCompiler = !!tamaguiOptionsIn?.optimize
11
+ export function tamaguiPlugin({
12
+ optimize,
13
+ disableResolveConfig,
14
+ ...tamaguiOptionsIn
15
+ }: TamaguiOptions & { optimize?: boolean; disableResolveConfig?: boolean } = {}):
16
+ | Plugin
17
+ | Plugin[] {
18
+ const shouldAddCompiler = !!optimize
13
19
  let watcher
14
20
  let loaded = false
15
21
 
16
- const extensions = [
17
- `.web.mjs`,
18
- `.web.js`,
19
- `.web.jsx`,
20
- `.web.ts`,
21
- `.web.tsx`,
22
- '.mjs',
23
- '.js',
24
- '.mts',
25
- '.ts',
26
- '.jsx',
27
- '.tsx',
28
- '.json',
29
- ]
30
-
31
- let noExternalSSR = /react-native|expo-linear-gradient/gi
22
+ // TODO temporary fix
23
+ const enableNativeEnv = !!globalThis.__vxrnEnableNativeEnv
32
24
 
33
25
  async function load() {
34
26
  if (loaded) return
@@ -51,15 +43,6 @@ export function tamaguiPlugin(
51
43
  }).catch((err) => {
52
44
  console.error(` [Tamagui] Error watching config: ${err}`)
53
45
  })
54
-
55
- const components = [
56
- ...new Set([...(tamaguiOptions!.components || []), 'tamagui', '@tamagui/core']),
57
- ]
58
-
59
- noExternalSSR = new RegExp(
60
- `${components.join('|')}|react-native|expo-linear-gradient`,
61
- 'ig'
62
- )
63
46
  }
64
47
 
65
48
  const compatPlugins = [
@@ -83,6 +66,29 @@ export function tamaguiPlugin(
83
66
  }
84
67
  },
85
68
 
69
+ resolveId(id) {
70
+ if (disableResolveConfig || enableNativeEnv) {
71
+ return
72
+ }
73
+ if (!tamaguiOptions) {
74
+ throw new Error(`No options loaded`)
75
+ }
76
+ if (tamaguiOptions.platform !== 'native') {
77
+ return
78
+ }
79
+ if (
80
+ id === 'react-native/Libraries/Renderer/shims/ReactFabric' ||
81
+ id === 'react-native/Libraries/Utilities/codegenNativeComponent'
82
+ ) {
83
+ return resolve('@tamagui/proxy-worm')
84
+ }
85
+ if (!tamaguiOptions?.useReactNativeWebLite) {
86
+ if (id === 'react-native') {
87
+ return resolve('react-native-web')
88
+ }
89
+ }
90
+ },
91
+
86
92
  async config(_, env) {
87
93
  await load()
88
94
 
@@ -90,84 +96,105 @@ export function tamaguiPlugin(
90
96
  throw new Error(`No options loaded`)
91
97
  }
92
98
 
93
- return {
94
- environments: {
95
- client: {
96
- define: {
97
- 'process.env.TAMAGUI_IS_CLIENT': JSON.stringify(true),
99
+ const reactNativeResolve: UserConfig['resolve'] =
100
+ disableResolveConfig || enableNativeEnv
101
+ ? {}
102
+ : {
103
+ extensions: [
104
+ `.web.mjs`,
105
+ `.web.js`,
106
+ `.web.jsx`,
107
+ `.web.ts`,
108
+ `.web.tsx`,
109
+ '.mjs',
110
+ '.js',
111
+ '.mts',
112
+ '.ts',
113
+ '.jsx',
114
+ '.tsx',
115
+ '.json',
116
+ ],
117
+ }
118
+
119
+ const serverAndClientDefine: UserConfig['define'] = {
120
+ // reanimated support
121
+ _frameTimestamp: undefined,
122
+ _WORKLET: false,
123
+ __DEV__: `${env.mode === 'development'}`,
124
+ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || env.mode),
125
+ 'process.env.IS_STATIC': JSON.stringify(false),
126
+ ...(env.mode === 'production' && {
127
+ 'process.env.TAMAGUI_OPTIMIZE_THEMES': JSON.stringify(true),
128
+ }),
129
+ }
130
+
131
+ if (isVite6) {
132
+ return {
133
+ resolve: reactNativeResolve,
134
+ environments: {
135
+ client: {
136
+ define: {
137
+ 'process.env.TAMAGUI_IS_CLIENT': JSON.stringify(true),
138
+ ...serverAndClientDefine,
139
+ },
140
+ },
141
+
142
+ ssr: {
143
+ define: serverAndClientDefine,
98
144
  },
99
145
  },
100
- },
146
+ // vite 5 + 6 compat
147
+ } as any
148
+ }
149
+
150
+ return {
151
+ define: serverAndClientDefine,
152
+ resolve: reactNativeResolve,
101
153
 
102
- define: {
103
- // reanimated support
104
- _frameTimestamp: undefined,
105
- _WORKLET: false,
106
- __DEV__: `${env.mode === 'development'}`,
107
- 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || env.mode),
108
- 'process.env.ENABLE_RSC': JSON.stringify(process.env.ENABLE_RSC || ''),
109
- 'process.env.ENABLE_STEPS': JSON.stringify(process.env.ENABLE_STEPS || ''),
110
- 'process.env.IS_STATIC': JSON.stringify(false),
111
- ...(env.mode === 'production' && {
112
- 'process.env.TAMAGUI_OPTIMIZE_THEMES': JSON.stringify(true),
113
- }),
114
- },
115
154
  ssr: {
116
- noExternal: noExternalSSR,
117
- },
118
- resolve: {
119
- extensions: extensions,
120
- alias: {
121
- ...(tamaguiOptions.platform !== 'native' && {
122
- 'react-native/Libraries/Renderer/shims/ReactFabric':
123
- resolve('@tamagui/proxy-worm'),
124
- 'react-native/Libraries/Utilities/codegenNativeComponent':
125
- resolve('@tamagui/proxy-worm'),
126
- 'react-native-svg': resolve('@tamagui/react-native-svg'),
127
- ...(!tamaguiOptions?.useReactNativeWebLite && {
128
- 'react-native': resolve('react-native-web'),
129
- }),
130
- }),
155
+ optimizeDeps: {
156
+ include: [
157
+ 'tamagui',
158
+ '@tamagui/core',
159
+ '@tamagui/web',
160
+ '@react-native/normalize-color',
161
+ 'react',
162
+ 'react/jsx-runtime',
163
+ ],
131
164
  },
132
165
  },
133
166
  }
134
167
  },
135
168
  },
169
+
136
170
  {
137
171
  name: 'tamagui-rnw-lite',
138
- config() {
172
+
173
+ resolveId(id) {
174
+ const envName = this['environment']?.name as any // vite 5 + 6 compat
175
+
176
+ if (isVite6 && (envName === 'client' || envName === 'ssr')) {
177
+ return
178
+ }
179
+
139
180
  if (tamaguiOptions?.useReactNativeWebLite) {
140
- const rnwl = resolve('@tamagui/react-native-web-lite')
141
- const rnwlSS = resolve(
142
- '@tamagui/react-native-web-lite/dist/exports/StyleSheet/compiler/createReactDOMStyle'
143
- )
181
+ if (
182
+ /react-native.*\/dist\/exports\/StyleSheet\/compiler\/createReactDOMStyle/.test(
183
+ id
184
+ )
185
+ ) {
186
+ return resolve(
187
+ '@tamagui/react-native-web-lite/dist/exports/StyleSheet/compiler/createReactDOMStyle'
188
+ )
189
+ }
144
190
 
145
- return {
146
- resolve: {
147
- alias: [
148
- // fix reanimated issue not finding this
149
- {
150
- find: /react-native.*\/dist\/exports\/StyleSheet\/compiler\/createReactDOMStyle/,
151
- replacement: rnwlSS,
152
- },
153
- {
154
- find: /^react-native$/,
155
- replacement: rnwl,
156
- },
157
- {
158
- find: /^react-native\/(.*)$/,
159
- replacement: rnwl,
160
- },
161
- {
162
- find: /^react-native-web$/,
163
- replacement: rnwl,
164
- },
165
- {
166
- find: /^react-native-web\/(.*)$/,
167
- replacement: rnwl,
168
- },
169
- ],
170
- },
191
+ if (
192
+ /^react-native$/.test(id) ||
193
+ /^react-native\/(.*)$/.test(id) ||
194
+ /^react-native-web$/.test(id) ||
195
+ /^react-native-web\/(.*)$/.test(id)
196
+ ) {
197
+ return resolve('@tamagui/react-native-web-lite')
171
198
  }
172
199
  }
173
200
  },
package/types/plugin.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { TamaguiOptions } from '@tamagui/static';
2
2
  import type { Plugin } from 'vite';
3
- export declare function tamaguiPlugin(tamaguiOptionsIn?: TamaguiOptions & {
3
+ export declare function tamaguiPlugin({ optimize, disableResolveConfig, ...tamaguiOptionsIn }?: TamaguiOptions & {
4
4
  optimize?: boolean;
5
+ disableResolveConfig?: boolean;
5
6
  }): Plugin | Plugin[];
6
7
  //# sourceMappingURL=plugin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAOlC,wBAAgB,aAAa,CAC3B,gBAAgB,GAAE,cAAc,GAAG;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAO,GAC7D,MAAM,GAAG,MAAM,EAAE,CA2KnB"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAErD,OAAO,KAAK,EAAE,MAAM,EAAc,MAAM,MAAM,CAAA;AAQ9C,wBAAgB,aAAa,CAAC,EAC5B,QAAQ,EACR,oBAAoB,EACpB,GAAG,gBAAgB,EACpB,GAAE,cAAc,GAAG;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAAO,GAC3E,MAAM,GACN,MAAM,EAAE,CAgMX"}