@tamagui/vite-plugin 1.0.1-beta.99 → 1.0.1-rc.0

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/src/plugin.ts CHANGED
@@ -1,31 +1,66 @@
1
1
  import type { TamaguiOptions } from '@tamagui/static'
2
2
  import type { Plugin } from 'vite'
3
- import envPlugin from 'vite-plugin-environment'
4
3
 
5
- export function tamaguiPlugin(options?: TamaguiOptions): Plugin {
6
- return {
7
- name: 'tamagui',
4
+ /**
5
+ * For some reason envPlugin doesnt work for vitest, but process: { env: {} } breaks vitest
6
+ */
7
+
8
+ export function tamaguiPlugin(
9
+ options: TamaguiOptions & {
10
+ useReactNativeWebLite?: boolean
11
+ }
12
+ ): Plugin {
13
+ const components = [...new Set([...options.components, 'tamagui', '@tamagui/core'])]
14
+ const noExternalSSR = new RegExp(
15
+ `${components.join('|')}|react-native|expo-linear-gradient`,
16
+ 'ig'
17
+ )
18
+
19
+ const plugin: Plugin = {
20
+ name: 'tamagui-base',
8
21
  enforce: 'pre',
9
22
 
10
23
  config(userConfig, env) {
11
24
  return {
12
- plugins: [envPlugin(['NODE_ENV', 'TAMAGUI_TARGET'])],
13
- esbuild: {
14
- loader: 'tsx',
15
- },
25
+ plugins: [
26
+ //
27
+ // envPlugin(['NODE_ENV', 'TAMAGUI_TARGET', 'ENABLE_RSC']),
28
+ // viteCommonjs(),
29
+ ],
16
30
  define: {
31
+ // reanimated support
17
32
  'global.__x': {},
18
33
  _frameTimestamp: undefined,
19
34
  _WORKLET: false,
20
- process: {
21
- env: {
22
- TAMAGUI_TARGET: process.env.TAMAGUI_TARGET || 'web',
23
- NODE_ENV: process.env.NODE_ENV || env.mode,
24
- },
25
- },
35
+ ...(process.env.NODE_ENV !== 'test' && {
36
+ 'process.env.TAMAGUI_TARGET': JSON.stringify(process.env.TAMAGUI_TARGET || 'web'),
37
+ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || env.mode),
38
+ 'process.env.ENABLE_RSC': JSON.stringify(process.env.ENABLE_RSC || ''),
39
+ 'process.env.ENABLE_STEPS': JSON.stringify(process.env.ENABLE_STEPS || ''),
40
+ 'process.env.IS_STATIC': JSON.stringify(false),
41
+ }),
42
+ },
43
+ // build: {
44
+ // commonjsOptions: {
45
+ // transformMixedEsModules: true,
46
+ // },
47
+ // },
48
+ ssr: {
49
+ noExternal: noExternalSSR,
26
50
  },
27
51
  optimizeDeps: {
52
+ // disabled: false,
53
+ include: ['styleq', 'copy-to-clipboard', 'react-native-reanimated'],
28
54
  esbuildOptions: {
55
+ jsx: 'transform',
56
+ // plugins: [
57
+ // esbuildCommonjs([
58
+ // 'styleq',
59
+ // 'inline-style-prefixer',
60
+ // 'create-react-class',
61
+ // 'copy-to-clipboard',
62
+ // ]),
63
+ // ],
29
64
  resolveExtensions: [
30
65
  '.web.js',
31
66
  '.web.ts',
@@ -44,7 +79,7 @@ export function tamaguiPlugin(options?: TamaguiOptions): Plugin {
44
79
  },
45
80
  resolve: {
46
81
  // for once it extracts
47
- // mainFields: ['module:jsx', 'module', 'jsnext:main', 'jsnext'],
82
+ // mainFields: ['module:jsx', 'module', 'jsnext:main', 'jsnext', 'main'],
48
83
  extensions: [
49
84
  '.web.js',
50
85
  '.web.ts',
@@ -59,199 +94,17 @@ export function tamaguiPlugin(options?: TamaguiOptions): Plugin {
59
94
  alias: {
60
95
  'react-native/Libraries/Renderer/shims/ReactFabric': '@tamagui/proxy-worm',
61
96
  'react-native/Libraries/Utilities/codegenNativeComponent': '@tamagui/proxy-worm',
97
+ 'react-native-svg': '@tamagui/react-native-svg',
62
98
  'react-native': 'react-native-web',
99
+ ...(options.useReactNativeWebLite && {
100
+ 'react-native': 'react-native-web-lite',
101
+ 'react-native-web': 'react-native-web-lite',
102
+ }),
63
103
  },
64
104
  },
65
105
  }
66
106
  },
67
107
  }
68
- }
69
-
70
- // fork from https://github.com/seek-oss/vanilla-extract/blob/master/packages/vite-plugin/src/index.ts
71
-
72
- // import path from 'path'
73
-
74
- // import outdent from 'outdent'
75
- // import type { Plugin, ResolvedConfig, ViteDevServer } from 'vite'
76
- // import { normalizePath } from 'vite'
77
-
78
- // const styleUpdateEvent = (fileId: string) => `tamagui-style-update:${fileId}`
79
-
80
- // interface Options {
81
- // identifiers?: IdentifierOption
82
- // esbuildOptions?: CompileOptions['esbuildOptions']
83
- // }
84
- // export function vanillaExtractPlugin({ identifiers, esbuildOptions }: Options = {}): Plugin {
85
- // let config: ResolvedConfig
86
- // let server: ViteDevServer
87
- // let postCssConfig: PostCSSConfigResult | null
88
- // const cssMap = new Map<string, string>()
89
-
90
- // let virtualExt: string
91
- // let packageName: string
92
-
93
- // const getAbsoluteVirtualFileId = (source: string) => normalizePath(path.join(config.root, source))
94
-
95
- // return {
96
- // name: 'tamagui',
97
- // enforce: 'pre',
98
- // configureServer(_server) {
99
- // server = _server
100
- // },
101
- // config(_userConfig, env) {
102
- // const include = env.command === 'serve' ? ['@tamagui/css/injectStyles'] : []
103
-
104
- // return {
105
- // optimizeDeps: { include },
106
- // ssr: {
107
- // external: ['@tamagui/css', '@tamagui/css/fileScope', '@tamagui/css/adapter'],
108
- // },
109
- // }
110
- // },
111
- // async configResolved(resolvedConfig) {
112
- // config = resolvedConfig
113
- // packageName = getPackageInfo(config.root).name
114
-
115
- // if (config.command === 'serve') {
116
- // postCssConfig = await resolvePostcssConfig(config)
117
- // }
118
-
119
- // virtualExt = `.vanilla.${config.command === 'serve' ? 'js' : 'css'}`
120
- // },
121
- // resolveId(source) {
122
- // if (!source.endsWith(virtualExt)) {
123
- // return
124
- // }
125
-
126
- // // Absolute paths seem to occur often in monorepos, where files are
127
- // // imported from outside the config root.
128
- // const absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(source)
129
-
130
- // // There should always be an entry in the `cssMap` here.
131
- // // The only valid scenario for a missing one is if someone had written
132
- // // a file in their app using the .vanilla.js/.vanilla.css extension
133
- // if (cssMap.has(absoluteId)) {
134
- // return absoluteId
135
- // }
136
- // },
137
- // load(id) {
138
- // if (!cssMap.has(id)) {
139
- // return
140
- // }
141
-
142
- // const css = cssMap.get(id)
143
-
144
- // if (typeof css !== 'string') {
145
- // return
146
- // }
147
108
 
148
- // if (!server || server.config.isProduction) {
149
- // return css
150
- // }
151
-
152
- // return outdent`
153
- // import { injectStyles } from '@tamagui/css/injectStyles';
154
-
155
- // const inject = (css) => injectStyles({
156
- // fileScope: ${JSON.stringify({ filePath: id })},
157
- // css
158
- // });
159
-
160
- // inject(${JSON.stringify(css)});
161
-
162
- // import.meta.hot.on('${styleUpdateEvent(id)}', (css) => {
163
- // inject(css);
164
- // });
165
- // `
166
- // },
167
- // async transform(code, id, ssrParam) {
168
- // if (!cssFileFilter.test(id)) {
169
- // return null
170
- // }
171
-
172
- // let ssr: boolean | undefined
173
-
174
- // if (typeof ssrParam === 'boolean') {
175
- // ssr = ssrParam
176
- // } else {
177
- // ssr = ssrParam?.ssr
178
- // }
179
-
180
- // const index = id.indexOf('?')
181
- // const validId = index === -1 ? id : id.substring(0, index)
182
-
183
- // if (ssr) {
184
- // return addFileScope({
185
- // source: code,
186
- // filePath: normalizePath(validId),
187
- // rootPath: config.root,
188
- // packageName,
189
- // })
190
- // }
191
-
192
- // const { source, watchFiles } = await compile({
193
- // filePath: validId,
194
- // cwd: config.root,
195
- // esbuildOptions,
196
- // })
197
-
198
- // for (const file of watchFiles) {
199
- // // In start mode, we need to prevent the file from rewatching itself.
200
- // // If it's a `build --watch`, it needs to watch everything.
201
- // if (config.command === 'build' || file !== id) {
202
- // this.addWatchFile(file)
203
- // }
204
- // }
205
-
206
- // const output = await processVanillaFile({
207
- // source,
208
- // filePath: validId,
209
- // identOption: identifiers ?? (config.mode === 'production' ? 'short' : 'debug'),
210
- // serializeVirtualCssPath: async ({ fileScope, source }) => {
211
- // const rootRelativeId = `${fileScope.filePath}${virtualExt}`
212
- // const absoluteId = getAbsoluteVirtualFileId(rootRelativeId)
213
-
214
- // let cssSource = source
215
-
216
- // if (postCssConfig) {
217
- // const postCssResult = await (await import('postcss'))
218
- // .default(postCssConfig.plugins)
219
- // .process(source, {
220
- // ...postCssConfig.options,
221
- // from: undefined,
222
- // map: false,
223
- // })
224
-
225
- // cssSource = postCssResult.css
226
- // }
227
-
228
- // if (server && cssMap.has(absoluteId) && cssMap.get(absoluteId) !== source) {
229
- // const { moduleGraph } = server
230
- // const module = moduleGraph.getModuleById(absoluteId)
231
-
232
- // if (module) {
233
- // moduleGraph.invalidateModule(module)
234
- // }
235
-
236
- // server.ws.send({
237
- // type: 'custom',
238
- // event: styleUpdateEvent(absoluteId),
239
- // data: cssSource,
240
- // })
241
- // }
242
-
243
- // cssMap.set(absoluteId, cssSource)
244
-
245
- // // We use the root relative id here to ensure file contents (content-hashes)
246
- // // are consistent across build machines
247
- // return `import "${rootRelativeId}";`
248
- // },
249
- // })
250
-
251
- // return {
252
- // code: output,
253
- // map: { mappings: '' },
254
- // }
255
- // },
256
- // }
257
- // }
109
+ return plugin
110
+ }
@@ -0,0 +1,4 @@
1
+ import { TamaguiOptions } from '@tamagui/static';
2
+ import type { Plugin } from 'vite';
3
+ export declare function tamaguiExtractPlugin(options: TamaguiOptions): Plugin;
4
+ //# sourceMappingURL=extract.d.ts.map
package/types/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- export * from './plugin';
1
+ export * from './plugin.js';
2
+ export * from './extract.js';
2
3
  //# sourceMappingURL=index.d.ts.map
package/types/plugin.d.ts CHANGED
@@ -1,4 +1,9 @@
1
1
  import type { TamaguiOptions } from '@tamagui/static';
2
2
  import type { Plugin } from 'vite';
3
- export declare function tamaguiPlugin(options?: TamaguiOptions): Plugin;
3
+ /**
4
+ * For some reason envPlugin doesnt work for vitest, but process: { env: {} } breaks vitest
5
+ */
6
+ export declare function tamaguiPlugin(options: TamaguiOptions & {
7
+ useReactNativeWebLite?: boolean;
8
+ }): Plugin;
4
9
  //# sourceMappingURL=plugin.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA"}
@@ -1 +0,0 @@
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;AAGlC,wBAAgB,aAAa,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,MAAM,CA+D9D"}