@tamagui/vite-plugin 1.0.21 → 1.0.23

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.
@@ -0,0 +1,159 @@
1
+ import path from "path";
2
+ import {
3
+ createExtractor,
4
+ extractToClassNames,
5
+ getPragmaOptions
6
+ } from "@tamagui/static";
7
+ import outdent from "outdent";
8
+ import { normalizePath } from "vite";
9
+ const styleUpdateEvent = (fileId) => `tamagui-style-update:${fileId}`;
10
+ const GLOBAL_CSS_VIRTUAL_PATH = "__tamagui_global_css__.css";
11
+ function tamaguiExtractPlugin(options) {
12
+ const disableStatic = options.disable || options.disableDebugAttr && options.disableExtraction;
13
+ if (disableStatic) {
14
+ return {
15
+ name: "tamagui-extract"
16
+ };
17
+ }
18
+ let extractor = null;
19
+ const cssMap = /* @__PURE__ */ new Map();
20
+ let config;
21
+ let server;
22
+ let shouldReturnCSS = true;
23
+ let virtualExt;
24
+ const getAbsoluteVirtualFileId = (filePath) => {
25
+ if (filePath.startsWith(config.root)) {
26
+ return filePath;
27
+ }
28
+ return normalizePath(path.join(config.root, filePath));
29
+ };
30
+ return {
31
+ name: "tamagui-extract",
32
+ enforce: "pre",
33
+ configureServer(_server) {
34
+ server = _server;
35
+ },
36
+ buildEnd() {
37
+ extractor.cleanupBeforeExit();
38
+ },
39
+ writeBundle(options2, bundle) {
40
+ setTimeout(() => {
41
+ console.warn("some sort of dangling process or osmethign, exit for now...");
42
+ process.exit(0);
43
+ }, 100);
44
+ },
45
+ config(_userConfig, env) {
46
+ const include = env.command === "serve" ? ["@tamagui/core/inject-styles"] : [];
47
+ return {
48
+ optimizeDeps: { include }
49
+ };
50
+ },
51
+ async configResolved(resolvedConfig) {
52
+ config = resolvedConfig;
53
+ extractor = createExtractor({
54
+ logger: resolvedConfig.logger
55
+ });
56
+ shouldReturnCSS = true;
57
+ virtualExt = `.tamagui.${shouldReturnCSS ? "css" : "js"}`;
58
+ },
59
+ async resolveId(source) {
60
+ if (source === "tamagui.css") {
61
+ await extractor.loadTamagui(options);
62
+ return GLOBAL_CSS_VIRTUAL_PATH;
63
+ }
64
+ const [validId, query] = source.split("?");
65
+ if (!validId.endsWith(virtualExt)) {
66
+ return;
67
+ }
68
+ const absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(validId);
69
+ if (cssMap.has(absoluteId)) {
70
+ return absoluteId + (query ? `?${query}` : "");
71
+ }
72
+ },
73
+ load(id, options2) {
74
+ const [validId] = id.split("?");
75
+ if (validId === GLOBAL_CSS_VIRTUAL_PATH) {
76
+ return extractor.getTamagui().getCSS();
77
+ }
78
+ if (!cssMap.has(validId)) {
79
+ return;
80
+ }
81
+ const css = cssMap.get(validId);
82
+ if (typeof css !== "string") {
83
+ return;
84
+ }
85
+ if (shouldReturnCSS || !server || server.config.isProduction) {
86
+ return css;
87
+ }
88
+ return outdent`
89
+ import { injectStyles } from '@tamagui/core/inject-styles';
90
+
91
+ const inject = (css) => injectStyles({
92
+ filePath: "${validId}",
93
+ css
94
+ });
95
+
96
+ inject(${JSON.stringify(css)});
97
+
98
+ if (import.meta.hot) {
99
+ import.meta.hot.on('${styleUpdateEvent(validId)}', (css) => {
100
+ inject(css);
101
+ });
102
+ }
103
+ `;
104
+ },
105
+ async transform(code, id, ssrParam) {
106
+ const [validId] = id.split("?");
107
+ if (!validId.endsWith(".tsx")) {
108
+ return;
109
+ }
110
+ const firstCommentIndex = code.indexOf("// ");
111
+ const { shouldDisable, shouldPrintDebug } = getPragmaOptions({
112
+ source: firstCommentIndex >= 0 ? code.slice(firstCommentIndex) : "",
113
+ path: validId
114
+ });
115
+ if (shouldDisable) {
116
+ return;
117
+ }
118
+ const extracted = await extractToClassNames({
119
+ extractor,
120
+ source: code,
121
+ sourcePath: validId,
122
+ options,
123
+ shouldPrintDebug
124
+ });
125
+ if (!extracted) {
126
+ return;
127
+ }
128
+ const rootRelativeId = `${validId}${virtualExt}`;
129
+ const absoluteId = getAbsoluteVirtualFileId(rootRelativeId);
130
+ let source = extracted.js;
131
+ if (extracted.styles) {
132
+ if (server && cssMap.has(absoluteId) && cssMap.get(absoluteId) !== extracted.styles) {
133
+ const { moduleGraph } = server;
134
+ const [module] = Array.from(moduleGraph.getModulesByFile(absoluteId) || []);
135
+ if (module) {
136
+ moduleGraph.invalidateModule(module);
137
+ module.lastHMRTimestamp = module.lastInvalidationTimestamp || Date.now();
138
+ }
139
+ server.ws.send({
140
+ type: "custom",
141
+ event: styleUpdateEvent(absoluteId),
142
+ data: extracted.styles
143
+ });
144
+ }
145
+ source = `${source}
146
+ import "${rootRelativeId}";`;
147
+ cssMap.set(absoluteId, extracted.styles);
148
+ }
149
+ return {
150
+ code: source.toString(),
151
+ map: extracted.map
152
+ };
153
+ }
154
+ };
155
+ }
156
+ export {
157
+ tamaguiExtractPlugin
158
+ };
159
+ //# sourceMappingURL=extract.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/extract.ts"],
4
+ "sourcesContent": ["// fork from https://github.com/seek-oss/vanilla-extract\n\nimport path from 'path'\n\nimport {\n TamaguiOptions,\n createExtractor,\n extractToClassNames,\n getPragmaOptions,\n} from '@tamagui/static'\nimport outdent from 'outdent'\nimport type { Plugin, ResolvedConfig, ViteDevServer } from 'vite'\nimport { normalizePath } from 'vite'\n\nconst styleUpdateEvent = (fileId: string) => `tamagui-style-update:${fileId}`\nconst GLOBAL_CSS_VIRTUAL_PATH = '__tamagui_global_css__.css'\n\nexport function tamaguiExtractPlugin(options: TamaguiOptions): Plugin {\n const disableStatic =\n options.disable || (options.disableDebugAttr && options.disableExtraction)\n\n if (disableStatic) {\n return {\n name: 'tamagui-extract',\n }\n }\n\n let extractor: ReturnType<typeof createExtractor> | null = null\n const cssMap = new Map<string, string>()\n\n let config: ResolvedConfig\n let server: ViteDevServer\n let shouldReturnCSS = true //config.command === 'serve'\n let virtualExt: string\n\n const getAbsoluteVirtualFileId = (filePath: string) => {\n if (filePath.startsWith(config.root)) {\n return filePath\n }\n return normalizePath(path.join(config.root, filePath))\n }\n\n return {\n name: 'tamagui-extract',\n enforce: 'pre',\n\n configureServer(_server) {\n server = _server\n },\n\n buildEnd() {\n extractor!.cleanupBeforeExit()\n },\n\n writeBundle(this, options, bundle) {\n setTimeout(() => {\n // eslint-disable-next-line no-console\n console.warn('some sort of dangling process or osmethign, exit for now...')\n process.exit(0)\n }, 100)\n },\n\n config(_userConfig, env) {\n const include = env.command === 'serve' ? ['@tamagui/core/inject-styles'] : []\n return {\n optimizeDeps: { include },\n }\n },\n\n async configResolved(resolvedConfig) {\n config = resolvedConfig\n extractor = createExtractor({\n logger: resolvedConfig.logger,\n })\n shouldReturnCSS = true\n // TODO postcss work with postcss.config.js\n // packageName = getPackageInfo(config.root).name;\n // if (config.command === 'serve') {\n // postCssConfig = await resolvePostcssConfig(config);\n // }\n virtualExt = `.tamagui.${shouldReturnCSS ? 'css' : 'js'}`\n },\n\n async resolveId(source) {\n if (source === 'tamagui.css') {\n await extractor!.loadTamagui(options)\n return GLOBAL_CSS_VIRTUAL_PATH\n }\n\n const [validId, query] = source.split('?')\n\n if (!validId.endsWith(virtualExt)) {\n return\n }\n\n // Absolute paths seem to occur often in monorepos, where files are\n // imported from outside the config root.\n const absoluteId = source.startsWith(config.root)\n ? source\n : getAbsoluteVirtualFileId(validId)\n\n // There should always be an entry in the `cssMap` here.\n // The only valid scenario for a missing one is if someone had written\n // a file in their app using the .tamagui.js/.tamagui.css extension\n if (cssMap.has(absoluteId)) {\n // Keep the original query string for HMR.\n return absoluteId + (query ? `?${query}` : '')\n }\n },\n\n /**\n * TODO\n *\n * mainFields module:jsx breaks, so lets just have a mapping here\n * where we load() and map it to the jsx path before transform\n *\n */\n\n load(id, options) {\n const [validId] = id.split('?')\n\n if (validId === GLOBAL_CSS_VIRTUAL_PATH) {\n return extractor!.getTamagui()!.getCSS()\n }\n\n if (!cssMap.has(validId)) {\n return\n }\n\n const css = cssMap.get(validId)\n\n if (typeof css !== 'string') {\n return\n }\n\n if (shouldReturnCSS || !server || server.config.isProduction) {\n return css\n }\n\n return outdent`\n import { injectStyles } from '@tamagui/core/inject-styles';\n\n const inject = (css) => injectStyles({\n filePath: \"${validId}\",\n css\n });\n\n inject(${JSON.stringify(css)});\n\n if (import.meta.hot) {\n import.meta.hot.on('${styleUpdateEvent(validId)}', (css) => {\n inject(css);\n });\n }\n `\n },\n\n async transform(code, id, ssrParam) {\n const [validId] = id.split('?')\n\n if (!validId.endsWith('.tsx')) {\n return\n }\n\n // let ssr: boolean | undefined\n // if (typeof ssrParam === 'boolean') {\n // ssr = ssrParam\n // } else {\n // ssr = ssrParam?.ssr\n // }\n\n const firstCommentIndex = code.indexOf('// ')\n const { shouldDisable, shouldPrintDebug } = getPragmaOptions({\n source: firstCommentIndex >= 0 ? code.slice(firstCommentIndex) : '',\n path: validId,\n })\n\n if (shouldDisable) {\n return\n }\n\n const extracted = await extractToClassNames({\n extractor: extractor!,\n source: code,\n sourcePath: validId,\n options,\n shouldPrintDebug,\n })\n\n if (!extracted) {\n return\n }\n\n const rootRelativeId = `${validId}${virtualExt}`\n const absoluteId = getAbsoluteVirtualFileId(rootRelativeId)\n\n let source = extracted.js\n\n if (extracted.styles) {\n if (\n server &&\n cssMap.has(absoluteId) &&\n cssMap.get(absoluteId) !== extracted.styles\n ) {\n const { moduleGraph } = server\n const [module] = Array.from(moduleGraph.getModulesByFile(absoluteId) || [])\n\n if (module) {\n moduleGraph.invalidateModule(module)\n\n // Vite uses this timestamp to add `?t=` query string automatically for HMR.\n module.lastHMRTimestamp =\n (module as any).lastInvalidationTimestamp || Date.now()\n }\n\n server.ws.send({\n type: 'custom',\n event: styleUpdateEvent(absoluteId),\n data: extracted.styles,\n })\n }\n\n source = `${source}\\nimport \"${rootRelativeId}\";`\n cssMap.set(absoluteId, extracted.styles)\n }\n\n return {\n code: source.toString(),\n map: extracted.map,\n }\n\n // if (ssr && !process.env.VITE_RSC_BUILD) {\n // return addFileScope({\n // source: code,\n // filePath: normalizePath(validId),\n // rootPath: config.root,\n // packageName,\n // })\n // }\n\n // const { source, watchFiles } = await compile({\n // filePath: validId,\n // cwd: config.root,\n // esbuildOptions,\n // })\n\n // for (const file of watchFiles) {\n // // In start mode, we need to prevent the file from rewatching itself.\n // // If it's a `build --watch`, it needs to watch everything.\n // if (config.command === 'build' || file !== validId) {\n // this.addWatchFile(file)\n // }\n // }\n },\n }\n}\n"],
5
+ "mappings": "AAEA,OAAO,UAAU;AAEjB;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,OAAO,aAAa;AAEpB,SAAS,qBAAqB;AAE9B,MAAM,mBAAmB,CAAC,WAAmB,wBAAwB;AACrE,MAAM,0BAA0B;AAEzB,SAAS,qBAAqB,SAAiC;AACpE,QAAM,gBACJ,QAAQ,WAAY,QAAQ,oBAAoB,QAAQ;AAE1D,MAAI,eAAe;AACjB,WAAO;AAAA,MACL,MAAM;AAAA,IACR;AAAA,EACF;AAEA,MAAI,YAAuD;AAC3D,QAAM,SAAS,oBAAI,IAAoB;AAEvC,MAAI;AACJ,MAAI;AACJ,MAAI,kBAAkB;AACtB,MAAI;AAEJ,QAAM,2BAA2B,CAAC,aAAqB;AACrD,QAAI,SAAS,WAAW,OAAO,IAAI,GAAG;AACpC,aAAO;AAAA,IACT;AACA,WAAO,cAAc,KAAK,KAAK,OAAO,MAAM,QAAQ,CAAC;AAAA,EACvD;AAEA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IAET,gBAAgB,SAAS;AACvB,eAAS;AAAA,IACX;AAAA,IAEA,WAAW;AACT,gBAAW,kBAAkB;AAAA,IAC/B;AAAA,IAEA,YAAkBA,UAAS,QAAQ;AACjC,iBAAW,MAAM;AAEf,gBAAQ,KAAK,6DAA6D;AAC1E,gBAAQ,KAAK,CAAC;AAAA,MAChB,GAAG,GAAG;AAAA,IACR;AAAA,IAEA,OAAO,aAAa,KAAK;AACvB,YAAM,UAAU,IAAI,YAAY,UAA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
+ "names": ["options"]
7
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./plugin.js";
2
+ export * from "./extract.js";
3
+ export * from "./native.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "sourcesContent": ["export * from './plugin.js'\nexport * from './extract.js'\nexport * from './native.js'\n"],
5
+ "mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;",
6
+ "names": []
7
+ }
@@ -0,0 +1,71 @@
1
+ function replaceScript(html, scriptFilename, scriptCode, removeViteModuleLoader = false) {
2
+ const reScript = new RegExp(
3
+ `<script([^>]*?) src="[./]*${scriptFilename}"([^>]*)><\/script>`
4
+ );
5
+ const preloadMarker = /"__VITE_PRELOAD__"/g;
6
+ const newCode = scriptCode.replace(preloadMarker, "void 0");
7
+ const inlined = html.replace(
8
+ reScript,
9
+ (_, beforeSrc, afterSrc) => `<script${beforeSrc}${afterSrc}>
10
+ ${newCode}
11
+ <\/script>`
12
+ );
13
+ return removeViteModuleLoader ? _removeViteModuleLoader(inlined) : inlined;
14
+ }
15
+ function replaceCss(html, scriptFilename, scriptCode) {
16
+ const reCss = new RegExp(`<link[^>]*? href="[./]*${scriptFilename}"[^>]*?>`);
17
+ const inlined = html.replace(reCss, `<style>
18
+ ${scriptCode}
19
+ </style>`);
20
+ return inlined;
21
+ }
22
+ const warnNotInlined = (filename) => console.warn(`WARNING: asset not inlined: ${filename}`);
23
+ function nativePlugin() {
24
+ return {
25
+ name: "vite:singlefile",
26
+ config: (config) => {
27
+ if (!config.build)
28
+ config.build = {};
29
+ config.build.assetsInlineLimit = 1e8;
30
+ config.build.chunkSizeWarningLimit = 1e8;
31
+ config.build.cssCodeSplit = false;
32
+ config.build.reportCompressedSize = false;
33
+ config.base = void 0;
34
+ if (!config.build.rollupOptions)
35
+ config.build.rollupOptions = {};
36
+ if (!config.build.rollupOptions.output)
37
+ config.build.rollupOptions.output = {};
38
+ const updateOutputOptions = (out) => {
39
+ out.inlineDynamicImports = true;
40
+ console.log("adding manualChunks = undefined");
41
+ out.manualChunks = void 0;
42
+ };
43
+ if (Array.isArray(config.build.rollupOptions.output)) {
44
+ for (const o in config.build.rollupOptions.output)
45
+ updateOutputOptions(o);
46
+ } else {
47
+ updateOutputOptions(config.build.rollupOptions.output);
48
+ }
49
+ },
50
+ enforce: "post",
51
+ generateBundle: (_, bundle) => {
52
+ const inlinePattern = [];
53
+ const jsExtensionTest = /\.[mc]?js$/;
54
+ const htmlFiles = Object.keys(bundle).filter((i) => i.endsWith(".html"));
55
+ const cssAssets = Object.keys(bundle).filter((i) => i.endsWith(".css"));
56
+ const jsAssets = Object.keys(bundle).filter((i) => jsExtensionTest.test(i));
57
+ const bundlesToDelete = [];
58
+ console.log("bundle", bundle);
59
+ }
60
+ };
61
+ }
62
+ const _removeViteModuleLoader = (html) => html.replace(
63
+ /(<script type="module" crossorigin>\s*)\(function\(\)\{[\s\S]*?\}\)\(\);/,
64
+ '<script type="module">\n'
65
+ );
66
+ export {
67
+ nativePlugin,
68
+ replaceCss,
69
+ replaceScript
70
+ };
71
+ //# sourceMappingURL=native.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/native.ts"],
4
+ "sourcesContent": ["// testing single file logic via https://github.com/richardtallent/vite-plugin-singlefile\n\n// helpful:\n// rollup config for react native\n// https://gist.github.com/pritishvaidya/171dcb8e857ec1df186c035c3df6ae16\n\nimport micromatch from 'micromatch'\nimport { OutputAsset, OutputChunk, OutputOptions } from 'rollup'\nimport { Plugin } from 'vite'\n\nexport function replaceScript(\n html: string,\n scriptFilename: string,\n scriptCode: string,\n removeViteModuleLoader = false\n): string {\n const reScript = new RegExp(\n `<script([^>]*?) src=\"[./]*${scriptFilename}\"([^>]*)></script>`\n )\n // we can't use String.prototype.replaceAll since it isn't supported in Node.JS 14\n const preloadMarker = /\"__VITE_PRELOAD__\"/g\n const newCode = scriptCode.replace(preloadMarker, 'void 0')\n const inlined = html.replace(\n reScript,\n (_, beforeSrc, afterSrc) => `<script${beforeSrc}${afterSrc}>\\n${newCode}\\n</script>`\n )\n return removeViteModuleLoader ? _removeViteModuleLoader(inlined) : inlined\n}\n\nexport function replaceCss(\n html: string,\n scriptFilename: string,\n scriptCode: string\n): string {\n const reCss = new RegExp(`<link[^>]*? href=\"[./]*${scriptFilename}\"[^>]*?>`)\n const inlined = html.replace(reCss, `<style>\\n${scriptCode}\\n</style>`)\n return inlined\n}\n\nconst warnNotInlined = (filename: string) =>\n console.warn(`WARNING: asset not inlined: ${filename}`)\n\nexport function nativePlugin(): Plugin {\n return {\n name: 'vite:singlefile',\n config: (config) => {\n if (!config.build) config.build = {}\n // Ensures that even very large assets are inlined in your JavaScript.\n config.build.assetsInlineLimit = 100000000\n // Avoid warnings about large chunks.\n config.build.chunkSizeWarningLimit = 100000000\n // Emit all CSS as a single file, which `vite-plugin-singlefile` can then inline.\n config.build.cssCodeSplit = false\n // Avoids the extra step of testing Brotli compression, which isn't really pertinent to a file served locally.\n config.build.reportCompressedSize = false\n // Subfolder bases are not supported, and shouldn't be needed because we're embedding everything.\n config.base = undefined\n\n if (!config.build.rollupOptions) config.build.rollupOptions = {}\n if (!config.build.rollupOptions.output) config.build.rollupOptions.output = {}\n\n const updateOutputOptions = (out: OutputOptions) => {\n // Ensure that as many resources as possible are inlined.\n out.inlineDynamicImports = true\n\n // added by me (nate):\n console.log('adding manualChunks = undefined')\n out.manualChunks = undefined\n }\n\n if (Array.isArray(config.build.rollupOptions.output)) {\n for (const o in config.build.rollupOptions.output)\n updateOutputOptions(o as OutputOptions)\n } else {\n updateOutputOptions(config.build.rollupOptions.output as OutputOptions)\n }\n },\n\n enforce: 'post',\n\n generateBundle: (_, bundle) => {\n const inlinePattern = []\n const jsExtensionTest = /\\.[mc]?js$/\n const htmlFiles = Object.keys(bundle).filter((i) => i.endsWith('.html'))\n const cssAssets = Object.keys(bundle).filter((i) => i.endsWith('.css'))\n const jsAssets = Object.keys(bundle).filter((i) => jsExtensionTest.test(i))\n const bundlesToDelete = [] as string[]\n\n console.log('bundle', bundle)\n\n // for (const name of htmlFiles) {\n // const htmlChunk = bundle[name] as OutputAsset\n // let replacedHtml = htmlChunk.source as string\n // for (const jsName of jsAssets) {\n // if (!inlinePattern.length || micromatch.isMatch(jsName, inlinePattern)) {\n // const jsChunk = bundle[jsName] as OutputChunk\n // if (jsChunk.code != null) {\n // bundlesToDelete.push(jsName)\n // replacedHtml = replaceScript(\n // replacedHtml,\n // jsChunk.fileName,\n // jsChunk.code,\n // false\n // // removeViteModuleLoader\n // )\n // }\n // } else {\n // warnNotInlined(jsName)\n // }\n // }\n // for (const cssName of cssAssets) {\n // if (!inlinePattern.length || micromatch.isMatch(cssName, inlinePattern)) {\n // const cssChunk = bundle[cssName] as OutputAsset\n // bundlesToDelete.push(cssName)\n // replacedHtml = replaceCss(\n // replacedHtml,\n // cssChunk.fileName,\n // cssChunk.source as string\n // )\n // } else {\n // warnNotInlined(cssName)\n // }\n // }\n // htmlChunk.source = replacedHtml\n // }\n\n // if (deleteInlinedFiles) {\n // for (const name of bundlesToDelete) {\n // delete bundle[name]\n // }\n // }\n\n // for (const name of Object.keys(bundle).filter(\n // (i) => !jsExtensionTest.test(i) && !i.endsWith('.css') && !i.endsWith('.html')\n // )) {\n // warnNotInlined(name)\n // }\n },\n }\n}\n\n// Optionally remove the Vite module loader since it's no longer needed because this plugin has inlined all code.\n// This assumes that the Module Loader is (1) the FIRST function declared in the module, (2) an IIFE, (3) is minified,\n// (4) is within a script with no unexpected attribute values, and (5) that the containing script is the first script\n// tag that matches the above criteria. Changes to the SCRIPT tag especially could break this again in the future.\n// Update example:\n// https://github.com/richardtallent/vite-plugin-singlefile/issues/57#issuecomment-1263950209\nconst _removeViteModuleLoader = (html: string) =>\n html.replace(\n /(<script type=\"module\" crossorigin>\\s*)\\(function\\(\\)\\{[\\s\\S]*?\\}\\)\\(\\);/,\n '<script type=\"module\">\\n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O,MAAM,cAAc,MAAuB;AAAA,MACxE;AAAA,IACF;AAAA,IAEA,SAAS;AAAA,IAET,gBAAgB,CAAC,GAAG,WAAW;AAC7B,YAAM,gBAAgB,CAAC;AACvB,YAAM,kBAAkB;AACxB,YAAM,YAAY,OAAO,KAAK,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,SAAS,OAAO,CAAC;AACvE,YAAM,YAAY,OAAO,KAAK,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,SAAS,MAAM,CAAC;AACtE,YAAM,WAAW,OAAO,KAAK,MAAM,EAAE,OAAO,CAAC,MAAM,gBAAgB,KAAK,CAAC,CAAC;AAC1E,YAAM,kBAAkB,CAAC;AAEzB,cAAQ,IAAI,UAAU,MAAM;AAAA,IAiD9B;AAAA,EACF;AACF;AAQA,MAAM,0BAA0B,CAAC,SAC/B,KAAK;AAAA,EACH;AAAA,EACA;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,85 @@
1
+ function tamaguiPlugin(options) {
2
+ const components = [
3
+ .../* @__PURE__ */ new Set([...options.components, "tamagui", "@tamagui/core"])
4
+ ];
5
+ const noExternalSSR = new RegExp(
6
+ `${components.join("|")}|react-native|expo-linear-gradient`,
7
+ "ig"
8
+ );
9
+ const plugin = {
10
+ name: "tamagui-base",
11
+ enforce: "pre",
12
+ config(userConfig, env) {
13
+ return {
14
+ plugins: [],
15
+ define: {
16
+ "global.__x": {},
17
+ _frameTimestamp: void 0,
18
+ _WORKLET: false,
19
+ ...process.env.NODE_ENV !== "test" && {
20
+ "process.env.TAMAGUI_TARGET": JSON.stringify(
21
+ process.env.TAMAGUI_TARGET || "web"
22
+ ),
23
+ "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || env.mode),
24
+ "process.env.ENABLE_RSC": JSON.stringify(process.env.ENABLE_RSC || ""),
25
+ "process.env.ENABLE_STEPS": JSON.stringify(
26
+ process.env.ENABLE_STEPS || ""
27
+ ),
28
+ "process.env.IS_STATIC": JSON.stringify(false)
29
+ }
30
+ },
31
+ ssr: {
32
+ noExternal: noExternalSSR
33
+ },
34
+ optimizeDeps: {
35
+ include: ["styleq", "react-native-reanimated"],
36
+ esbuildOptions: {
37
+ jsx: "transform",
38
+ resolveExtensions: [
39
+ ".web.js",
40
+ ".web.ts",
41
+ ".web.tsx",
42
+ ".js",
43
+ ".jsx",
44
+ ".json",
45
+ ".ts",
46
+ ".tsx",
47
+ ".mjs"
48
+ ],
49
+ loader: {
50
+ ".js": "jsx"
51
+ }
52
+ }
53
+ },
54
+ resolve: {
55
+ extensions: [
56
+ ".web.js",
57
+ ".web.ts",
58
+ ".web.tsx",
59
+ ".js",
60
+ ".jsx",
61
+ ".json",
62
+ ".ts",
63
+ ".tsx",
64
+ ".mjs"
65
+ ],
66
+ alias: {
67
+ "react-native/Libraries/Renderer/shims/ReactFabric": "@tamagui/proxy-worm",
68
+ "react-native/Libraries/Utilities/codegenNativeComponent": "@tamagui/proxy-worm",
69
+ "react-native-svg": "@tamagui/react-native-svg",
70
+ "react-native": "react-native-web",
71
+ ...options.useReactNativeWebLite && {
72
+ "react-native": "react-native-web-lite",
73
+ "react-native-web": "react-native-web-lite"
74
+ }
75
+ }
76
+ }
77
+ };
78
+ }
79
+ };
80
+ return plugin;
81
+ }
82
+ export {
83
+ tamaguiPlugin
84
+ };
85
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/plugin.ts"],
4
+ "sourcesContent": ["import type { TamaguiOptions } from '@tamagui/static'\nimport type { Plugin } from 'vite'\n\n/**\n * For some reason envPlugin doesnt work for vitest, but process: { env: {} } breaks vitest\n */\n\nexport function tamaguiPlugin(\n options: TamaguiOptions & {\n useReactNativeWebLite?: boolean\n },\n): Plugin {\n const components = [\n ...new Set([...options.components, 'tamagui', '@tamagui/core']),\n ]\n const noExternalSSR = new RegExp(\n `${components.join('|')}|react-native|expo-linear-gradient`,\n 'ig',\n )\n\n const plugin: Plugin = {\n name: 'tamagui-base',\n enforce: 'pre',\n\n config(userConfig, env) {\n return {\n plugins: [\n //\n // envPlugin(['NODE_ENV', 'TAMAGUI_TARGET', 'ENABLE_RSC']),\n // viteCommonjs(),\n ],\n define: {\n // reanimated support\n 'global.__x': {},\n _frameTimestamp: undefined,\n _WORKLET: false,\n ...(process.env.NODE_ENV !== 'test' && {\n 'process.env.TAMAGUI_TARGET': JSON.stringify(\n process.env.TAMAGUI_TARGET || 'web',\n ),\n 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || env.mode),\n 'process.env.ENABLE_RSC': JSON.stringify(process.env.ENABLE_RSC || ''),\n 'process.env.ENABLE_STEPS': JSON.stringify(\n process.env.ENABLE_STEPS || '',\n ),\n 'process.env.IS_STATIC': JSON.stringify(false),\n }),\n },\n // build: {\n // commonjsOptions: {\n // transformMixedEsModules: true,\n // },\n // },\n ssr: {\n noExternal: noExternalSSR,\n },\n optimizeDeps: {\n // disabled: false,\n include: ['styleq', 'react-native-reanimated'],\n esbuildOptions: {\n jsx: 'transform',\n // plugins: [\n // esbuildCommonjs([\n // 'styleq',\n // 'inline-style-prefixer',\n // 'create-react-class',\n // 'copy-to-clipboard',\n // ]),\n // ],\n resolveExtensions: [\n '.web.js',\n '.web.ts',\n '.web.tsx',\n '.js',\n '.jsx',\n '.json',\n '.ts',\n '.tsx',\n '.mjs',\n ],\n loader: {\n '.js': 'jsx',\n },\n },\n },\n resolve: {\n // for once it extracts\n // mainFields: ['module:jsx', 'module', 'jsnext:main', 'jsnext', 'main'],\n extensions: [\n '.web.js',\n '.web.ts',\n '.web.tsx',\n '.js',\n '.jsx',\n '.json',\n '.ts',\n '.tsx',\n '.mjs',\n ],\n alias: {\n 'react-native/Libraries/Renderer/shims/ReactFabric':\n '@tamagui/proxy-worm',\n 'react-native/Libraries/Utilities/codegenNativeComponent':\n '@tamagui/proxy-worm',\n 'react-native-svg': '@tamagui/react-native-svg',\n 'react-native': 'react-native-web',\n ...(options.useReactNativeWebLite && {\n 'react-native': 'react-native-web-lite',\n 'react-native-web': 'react-native-web-lite',\n }),\n },\n },\n }\n },\n }\n\n return plugin\n}\n"],
5
+ "mappings": "AAOO,SAAS,cACd,SAGQ;AACR,QAAM,aAAa;AAAA,IACjB,GAAG,oBAAI,IAAI,CAAC,GAAG,QAAQ,YAAY,WAAW,eAAe,CAAC;AAAA,EAChE;AACA,QAAM,gBAAgB,IAAI;AAAA,IACxB,GAAG,WAAW,KAAK,GAAG;AAAA,IACtB;AAAA,EACF;AAEA,QAAM,SAAiB;AAAA,IACrB,MAAM;AAAA,IACN,SAAS;AAAA,IAET,OAAO,YAAY,KAAK;AACtB,aAAO;AAAA,QACL,SAAS,CAIT;AAAA,QACA,QAAQ;AAAA,UAEN,cAAc,CAAC;AAAA,UACf,iBAAiB;AAAA,UACjB,UAAU;AAAA,UACV,GAAI,QAAQ,IAAI,aAAa,UAAU;AAAA,YACrC,8BAA8B,KAAK;AAAA,cACjC,QAAQ,IAAI,kBAAkB;AAAA,YAChC;AAAA,YACA,wBAAwB,KAAK,UAAU,QAAQ,IAAI,YAAY,IAAI,IAAI;AAAA,YACvE,0BAA0B,KAAK,UAAU,QAAQ,IAAI,cAAc,EAAE;AAAA,YACrE,4BAA4B,KAAK;AAAA,cAC/B,QAAQ,IAAI,gBAAgB;AAAA,YAC9B;AAAA,YACA,yBAAyB,KAAK,UAAU,KAAK;AAAA,UAC/C;AAAA,QACF;AAAA,QAMA,KAAK;AAAA,UACH,YAAY;AAAA,QACd;AAAA,QACA,cAAc;AAAA,UAEZ,SAAS,CAAC,UAAU,yBAAyB;AAAA,UAC7C,gBAAgB;AAAA,YACd,KAAK;AAAA,YASL,mBAAmB;AAAA,cACjB;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,YACF;AAAA,YACA,QAAQ;AAAA,cACN,OAAO;AAAA,YACT;AAAA,UACF;AAAA,QACF;AAAA,QACA,SAAS;AAAA,UAGP,YAAY;AAAA,YACV;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,UACA,OAAO;AAAA,YACL,qDACE;AAAA,YACF,2DACE;AAAA,YACF,oBAAoB;AAAA,YACpB,gBAAgB;AAAA,YAChB,GAAI,QAAQ,yBAAyB;AAAA,cACnC,gBAAgB;AAAA,cAChB,oBAAoB;AAAA,YACtB;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;",
6
+ "names": []
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/vite-plugin",
3
- "version": "1.0.21",
3
+ "version": "1.0.23",
4
4
  "types": "./types/index.d.ts",
5
5
  "main": "dist/cjs",
6
6
  "module": "dist/esm",
@@ -19,16 +19,17 @@
19
19
  "exports": {
20
20
  "./package.json": "./package.json",
21
21
  ".": {
22
+ "types": "./types/index.d.ts",
22
23
  "import": "./dist/esm/index.js",
23
24
  "require": "./dist/cjs/index.js"
24
25
  }
25
26
  },
26
27
  "dependencies": {
27
28
  "@originjs/vite-plugin-commonjs": "^1.0.3",
28
- "@tamagui/fake-react-native": "^1.0.21",
29
- "@tamagui/proxy-worm": "^1.0.21",
30
- "@tamagui/react-native-svg": "^1.0.21",
31
- "@tamagui/static": "^1.0.21",
29
+ "@tamagui/fake-react-native": "^1.0.23",
30
+ "@tamagui/proxy-worm": "^1.0.23",
31
+ "@tamagui/react-native-svg": "^1.0.23",
32
+ "@tamagui/static": "^1.0.23",
32
33
  "fs-extra": "^10.1.0",
33
34
  "lodash": "^4.17.21",
34
35
  "micromatch": ">=4.0.0",
@@ -36,7 +37,7 @@
36
37
  "rollup": ">=3.7.0"
37
38
  },
38
39
  "devDependencies": {
39
- "@tamagui/build": "^1.0.21",
40
+ "@tamagui/build": "^1.0.23",
40
41
  "vite-plugin-environment": "^1.1.3"
41
42
  },
42
43
  "publishConfig": {