@tamagui/vite-plugin 1.0.1-beta.141 → 1.0.1-beta.142

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
@@ -3,25 +3,25 @@ import type { TamaguiOptions } from '@tamagui/static'
3
3
  import type { Plugin } from 'vite'
4
4
  import envPlugin from 'vite-plugin-environment'
5
5
 
6
- import { tamaguiExtractPlugin } from './extractPlugin'
7
-
8
6
  /**
9
7
  * For some reason envPlugin doesnt work for vitest, but process: { env: {} } breaks vitest
10
8
  */
11
9
 
12
- export function tamaguiPlugin(options: TamaguiOptions): Plugin {
10
+ export function tamaguiPlugin(
11
+ options: TamaguiOptions & {
12
+ useReactNativeWebLite?: boolean
13
+ }
14
+ ): Plugin {
13
15
  const plugin: Plugin = {
14
- name: 'tamagui',
16
+ name: 'tamagui-base',
15
17
  enforce: 'pre',
16
18
 
17
19
  config(userConfig, env) {
18
20
  return {
19
21
  plugins: [
22
+ //
23
+ // envPlugin(['NODE_ENV', 'TAMAGUI_TARGET', 'ENABLE_RSC']),
20
24
  // viteCommonjs(),
21
- envPlugin(['NODE_ENV', 'TAMAGUI_TARGET']),
22
- // ...(options.disable || (options.disableDebugAttr && options.disableExtraction)
23
- // ? []
24
- // : [tamaguiExtractPlugin(options)]),
25
25
  ],
26
26
  esbuild: {
27
27
  loader: 'tsx',
@@ -32,12 +32,11 @@ export function tamaguiPlugin(options: TamaguiOptions): Plugin {
32
32
  _frameTimestamp: undefined,
33
33
  _WORKLET: false,
34
34
  ...(process.env.NODE_ENV !== 'test' && {
35
- process: {
36
- env: {
37
- TAMAGUI_TARGET: process.env.TAMAGUI_TARGET || 'web',
38
- NODE_ENV: process.env.NODE_ENV || env.mode,
39
- },
40
- },
35
+ 'process.env.TAMAGUI_TARGET': JSON.stringify(process.env.TAMAGUI_TARGET || 'web'),
36
+ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || env.mode),
37
+ 'process.env.ENABLE_RSC': JSON.stringify(process.env.ENABLE_RSC || ''),
38
+ 'process.env.ENABLE_STEPS': JSON.stringify(process.env.ENABLE_STEPS || ''),
39
+ 'process.env.IS_STATIC': JSON.stringify(false),
41
40
  }),
42
41
  },
43
42
  // build: {
@@ -46,15 +45,22 @@ export function tamaguiPlugin(options: TamaguiOptions): Plugin {
46
45
  // },
47
46
  // },
48
47
  ssr: {
49
- noExternal: /tamagui|react-native/,
50
- optimizeDeps: {
51
- // disabled: true,
52
- },
48
+ // noExternal: /^(tamagui|react-native|expo-linear-gradient)$/,
49
+ noExternal: /tamagui|react-native|expo-linear-gradient/,
53
50
  },
54
51
  optimizeDeps: {
55
- // include: [/node_modules/],
52
+ // disabled: false,
53
+ include: ['styleq', 'copy-to-clipboard', 'react-native-reanimated'],
56
54
  esbuildOptions: {
57
- // plugins: [esbuildCommonjs(['fbjs'])],
55
+ jsx: 'transform',
56
+ // plugins: [
57
+ // esbuildCommonjs([
58
+ // 'styleq',
59
+ // 'inline-style-prefixer',
60
+ // 'create-react-class',
61
+ // 'copy-to-clipboard',
62
+ // ]),
63
+ // ],
58
64
  resolveExtensions: [
59
65
  '.web.js',
60
66
  '.web.ts',
@@ -73,7 +79,7 @@ export function tamaguiPlugin(options: TamaguiOptions): Plugin {
73
79
  },
74
80
  resolve: {
75
81
  // for once it extracts
76
- // mainFields: ['module:jsx', 'module', 'jsnext:main', 'jsnext'],
82
+ // mainFields: ['module:jsx', 'module', 'jsnext:main', 'jsnext', 'main'],
77
83
  extensions: [
78
84
  '.web.js',
79
85
  '.web.ts',
@@ -88,8 +94,13 @@ export function tamaguiPlugin(options: TamaguiOptions): Plugin {
88
94
  alias: {
89
95
  'react-native/Libraries/Renderer/shims/ReactFabric': '@tamagui/proxy-worm',
90
96
  'react-native/Libraries/Utilities/codegenNativeComponent': '@tamagui/proxy-worm',
91
- // 'react-native': 'react-native-web-lite',
97
+ 'react-native-svg': 'react-native-svg-web',
92
98
  'react-native': 'react-native-web',
99
+ ...(options.useReactNativeWebLite && {
100
+ '@tamagui/rnw': '@tamagui/rnw-lite',
101
+ 'react-native': 'react-native-web-lite',
102
+ 'react-native-web': 'react-native-web-lite',
103
+ }),
93
104
  },
94
105
  },
95
106
  }
@@ -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
1
  export * from './plugin';
2
+ export * from './extract';
2
3
  //# sourceMappingURL=index.d.ts.map
package/types/plugin.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import type { TamaguiOptions } from '@tamagui/static';
2
2
  import type { Plugin } from 'vite';
3
- export declare function tamaguiPlugin(options: TamaguiOptions): Plugin;
3
+ export declare function tamaguiPlugin(options: TamaguiOptions & {
4
+ useReactNativeWebLite?: boolean;
5
+ }): Plugin;
4
6
  //# sourceMappingURL=plugin.d.ts.map
@@ -1,161 +0,0 @@
1
- // fork from https://github.com/seek-oss/vanilla-extract/blob/master/packages/vite-plugin/src/index.ts
2
-
3
- import path from 'path'
4
-
5
- import type { TamaguiOptions } from '@tamagui/static'
6
- import outdent from 'outdent'
7
- import type { Plugin, ResolvedConfig, ViteDevServer } from 'vite'
8
- import { normalizePath } from 'vite'
9
-
10
- const styleUpdateEvent = (fileId: string) => `tamagui-style-update:${fileId}`
11
-
12
- export function tamaguiExtractPlugin(options: TamaguiOptions): Plugin {
13
- let config: ResolvedConfig
14
- let server: ViteDevServer
15
- const cssMap = new Map<string, string>()
16
- let virtualExt: string
17
- let packageName: string
18
-
19
- const getAbsoluteVirtualFileId = (source: string) => normalizePath(path.join(config.root, source))
20
-
21
- return {
22
- name: 'tamagui-extract',
23
- enforce: 'pre',
24
-
25
- configureServer(_server) {
26
- server = _server
27
- },
28
-
29
- config(_userConfig, env) {
30
- // const include = env.command === 'serve' ? ['@tamagui/css/injectStyles'] : []
31
- // return {
32
- // optimizeDeps: { include },
33
- // ssr: {
34
- // external: ['@tamagui/css', '@tamagui/css/fileScope', '@tamagui/css/adapter'],
35
- // },
36
- // }
37
- },
38
-
39
- async configResolved(resolvedConfig) {
40
- // config = resolvedConfig
41
- // packageName = getPackageInfo(config.root).name
42
- // if (config.command === 'serve') {
43
- // postCssConfig = await resolvePostcssConfig(config)
44
- // }
45
- // virtualExt = `.vanilla.${config.command === 'serve' ? 'js' : 'css'}`
46
- },
47
-
48
- resolveId(source) {
49
- // if (!source.endsWith(virtualExt)) {
50
- // return
51
- // }
52
- // // Absolute paths seem to occur often in monorepos, where files are
53
- // // imported from outside the config root.
54
- // const absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(source)
55
- // // There should always be an entry in the `cssMap` here.
56
- // // The only valid scenario for a missing one is if someone had written
57
- // // a file in their app using the .vanilla.js/.vanilla.css extension
58
- // if (cssMap.has(absoluteId)) {
59
- // return absoluteId
60
- // }
61
- },
62
-
63
- load(id) {
64
- // if (!cssMap.has(id)) {
65
- // return
66
- // }
67
- // const css = cssMap.get(id)
68
- // if (typeof css !== 'string') {
69
- // return
70
- // }
71
- // if (!server || server.config.isProduction) {
72
- // return css
73
- // }
74
- // return outdent`
75
- // import { injectStyles } from '@tamagui/css/injectStyles';
76
- // const inject = (css) => injectStyles({
77
- // fileScope: ${JSON.stringify({ filePath: id })},
78
- // css
79
- // });
80
- // inject(${JSON.stringify(css)});
81
- // import.meta.hot.on('${styleUpdateEvent(id)}', (css) => {
82
- // inject(css);
83
- // });
84
- // `
85
- },
86
-
87
- async transform(code, id, ssrParam) {
88
- // if (!cssFileFilter.test(id)) {
89
- // return null
90
- // }
91
- // let ssr: boolean | undefined
92
- // if (typeof ssrParam === 'boolean') {
93
- // ssr = ssrParam
94
- // } else {
95
- // ssr = ssrParam?.ssr
96
- // }
97
- // const index = id.indexOf('?')
98
- // const validId = index === -1 ? id : id.substring(0, index)
99
- // if (ssr) {
100
- // return addFileScope({
101
- // source: code,
102
- // filePath: normalizePath(validId),
103
- // rootPath: config.root,
104
- // packageName,
105
- // })
106
- // }
107
- // const { source, watchFiles } = await compile({
108
- // filePath: validId,
109
- // cwd: config.root,
110
- // esbuildOptions,
111
- // })
112
- // for (const file of watchFiles) {
113
- // // In start mode, we need to prevent the file from rewatching itself.
114
- // // If it's a `build --watch`, it needs to watch everything.
115
- // if (config.command === 'build' || file !== id) {
116
- // this.addWatchFile(file)
117
- // }
118
- // }
119
- // const output = await processVanillaFile({
120
- // source,
121
- // filePath: validId,
122
- // identOption: identifiers ?? (config.mode === 'production' ? 'short' : 'debug'),
123
- // serializeVirtualCssPath: async ({ fileScope, source }) => {
124
- // const rootRelativeId = `${fileScope.filePath}${virtualExt}`
125
- // const absoluteId = getAbsoluteVirtualFileId(rootRelativeId)
126
- // let cssSource = source
127
- // if (postCssConfig) {
128
- // const postCssResult = await (await import('postcss'))
129
- // .default(postCssConfig.plugins)
130
- // .process(source, {
131
- // ...postCssConfig.options,
132
- // from: undefined,
133
- // map: false,
134
- // })
135
- // cssSource = postCssResult.css
136
- // }
137
- // if (server && cssMap.has(absoluteId) && cssMap.get(absoluteId) !== source) {
138
- // const { moduleGraph } = server
139
- // const module = moduleGraph.getModuleById(absoluteId)
140
- // if (module) {
141
- // moduleGraph.invalidateModule(module)
142
- // }
143
- // server.ws.send({
144
- // type: 'custom',
145
- // event: styleUpdateEvent(absoluteId),
146
- // data: cssSource,
147
- // })
148
- // }
149
- // cssMap.set(absoluteId, cssSource)
150
- // // We use the root relative id here to ensure file contents (content-hashes)
151
- // // are consistent across build machines
152
- // return `import "${rootRelativeId}";`
153
- // },
154
- // })
155
- // return {
156
- // code: output,
157
- // map: { mappings: '' },
158
- // }
159
- },
160
- }
161
- }