@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/dist/cjs/extract.js +185 -0
- package/dist/cjs/extract.js.map +7 -0
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/plugin.js +27 -16
- package/dist/cjs/plugin.js.map +2 -2
- package/dist/esm/extract.js +159 -0
- package/dist/esm/extract.js.map +7 -0
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/plugin.js +26 -13
- package/dist/esm/plugin.js.map +2 -2
- package/dist/jsx/extract.js +159 -0
- package/dist/jsx/extract.js.map +7 -0
- package/dist/jsx/index.js +2 -1
- package/dist/jsx/index.js.map +2 -2
- package/dist/jsx/plugin.js +26 -13
- package/dist/jsx/plugin.js.map +2 -2
- package/package.json +10 -6
- package/src/extract.ts +248 -0
- package/src/index.ts +2 -1
- package/src/plugin.ts +57 -204
- package/types/extract.d.ts +4 -0
- package/types/index.d.ts +2 -1
- package/types/plugin.d.ts +6 -1
- package/types/index.d.ts.map +0 -1
- package/types/plugin.d.ts.map +0 -1
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var extract_exports = {};
|
|
26
|
+
__export(extract_exports, {
|
|
27
|
+
tamaguiExtractPlugin: () => tamaguiExtractPlugin
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(extract_exports);
|
|
30
|
+
var import_path = __toESM(require("path"));
|
|
31
|
+
var import_static = require("@tamagui/static");
|
|
32
|
+
var import_outdent = __toESM(require("outdent"));
|
|
33
|
+
var import_vite = require("vite");
|
|
34
|
+
const styleUpdateEvent = (fileId) => `tamagui-style-update:${fileId}`;
|
|
35
|
+
const GLOBAL_CSS_VIRTUAL_PATH = "__tamagui_global_css__.css";
|
|
36
|
+
function tamaguiExtractPlugin(options) {
|
|
37
|
+
const disableStatic = options.disable || options.disableDebugAttr && options.disableExtraction;
|
|
38
|
+
if (disableStatic) {
|
|
39
|
+
return {
|
|
40
|
+
name: "tamagui-extract"
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
let extractor = null;
|
|
44
|
+
const cssMap = /* @__PURE__ */ new Map();
|
|
45
|
+
let config;
|
|
46
|
+
let server;
|
|
47
|
+
let shouldReturnCSS = true;
|
|
48
|
+
let virtualExt;
|
|
49
|
+
const getAbsoluteVirtualFileId = (filePath) => {
|
|
50
|
+
if (filePath.startsWith(config.root)) {
|
|
51
|
+
return filePath;
|
|
52
|
+
}
|
|
53
|
+
return (0, import_vite.normalizePath)(import_path.default.join(config.root, filePath));
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
name: "tamagui-extract",
|
|
57
|
+
enforce: "pre",
|
|
58
|
+
configureServer(_server) {
|
|
59
|
+
server = _server;
|
|
60
|
+
},
|
|
61
|
+
buildEnd() {
|
|
62
|
+
extractor.cleanupBeforeExit();
|
|
63
|
+
},
|
|
64
|
+
writeBundle(options2, bundle) {
|
|
65
|
+
setTimeout(() => {
|
|
66
|
+
console.warn("some sort of dangling process or osmethign, exit for now...");
|
|
67
|
+
process.exit(0);
|
|
68
|
+
}, 100);
|
|
69
|
+
},
|
|
70
|
+
config(_userConfig, env) {
|
|
71
|
+
const include = env.command === "serve" ? ["@tamagui/core/inject-styles"] : [];
|
|
72
|
+
return {
|
|
73
|
+
optimizeDeps: { include }
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
async configResolved(resolvedConfig) {
|
|
77
|
+
config = resolvedConfig;
|
|
78
|
+
extractor = (0, import_static.createExtractor)({
|
|
79
|
+
logger: resolvedConfig.logger
|
|
80
|
+
});
|
|
81
|
+
shouldReturnCSS = true;
|
|
82
|
+
virtualExt = `.tamagui.${shouldReturnCSS ? "css" : "js"}`;
|
|
83
|
+
},
|
|
84
|
+
async resolveId(source) {
|
|
85
|
+
if (source === "tamagui.css") {
|
|
86
|
+
await extractor.loadTamagui(options);
|
|
87
|
+
return GLOBAL_CSS_VIRTUAL_PATH;
|
|
88
|
+
}
|
|
89
|
+
const [validId, query] = source.split("?");
|
|
90
|
+
if (!validId.endsWith(virtualExt)) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(validId);
|
|
94
|
+
if (cssMap.has(absoluteId)) {
|
|
95
|
+
return absoluteId + (query ? `?${query}` : "");
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
load(id, options2) {
|
|
99
|
+
const [validId] = id.split("?");
|
|
100
|
+
if (validId === GLOBAL_CSS_VIRTUAL_PATH) {
|
|
101
|
+
return extractor.getTamagui().getCSS();
|
|
102
|
+
}
|
|
103
|
+
if (!cssMap.has(validId)) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const css = cssMap.get(validId);
|
|
107
|
+
if (typeof css !== "string") {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (shouldReturnCSS || !server || server.config.isProduction) {
|
|
111
|
+
return css;
|
|
112
|
+
}
|
|
113
|
+
return import_outdent.default`
|
|
114
|
+
import { injectStyles } from '@tamagui/core/inject-styles';
|
|
115
|
+
|
|
116
|
+
const inject = (css) => injectStyles({
|
|
117
|
+
filePath: "${validId}",
|
|
118
|
+
css
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
inject(${JSON.stringify(css)});
|
|
122
|
+
|
|
123
|
+
if (import.meta.hot) {
|
|
124
|
+
import.meta.hot.on('${styleUpdateEvent(validId)}', (css) => {
|
|
125
|
+
inject(css);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
`;
|
|
129
|
+
},
|
|
130
|
+
async transform(code, id, ssrParam) {
|
|
131
|
+
const [validId] = id.split("?");
|
|
132
|
+
if (!validId.endsWith(".tsx")) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const firstCommentIndex = code.indexOf("// ");
|
|
136
|
+
const { shouldDisable, shouldPrintDebug } = (0, import_static.getPragmaOptions)({
|
|
137
|
+
source: firstCommentIndex >= 0 ? code.slice(firstCommentIndex) : "",
|
|
138
|
+
path: validId
|
|
139
|
+
});
|
|
140
|
+
if (shouldDisable) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const extracted = await (0, import_static.extractToClassNames)({
|
|
144
|
+
extractor,
|
|
145
|
+
source: code,
|
|
146
|
+
sourcePath: validId,
|
|
147
|
+
options,
|
|
148
|
+
shouldPrintDebug
|
|
149
|
+
});
|
|
150
|
+
if (!extracted) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const rootRelativeId = `${validId}${virtualExt}`;
|
|
154
|
+
const absoluteId = getAbsoluteVirtualFileId(rootRelativeId);
|
|
155
|
+
let source = extracted.js;
|
|
156
|
+
if (extracted.styles) {
|
|
157
|
+
if (server && cssMap.has(absoluteId) && cssMap.get(absoluteId) !== extracted.styles) {
|
|
158
|
+
const { moduleGraph } = server;
|
|
159
|
+
const [module2] = Array.from(moduleGraph.getModulesByFile(absoluteId) || []);
|
|
160
|
+
if (module2) {
|
|
161
|
+
moduleGraph.invalidateModule(module2);
|
|
162
|
+
module2.lastHMRTimestamp = module2.lastInvalidationTimestamp || Date.now();
|
|
163
|
+
}
|
|
164
|
+
server.ws.send({
|
|
165
|
+
type: "custom",
|
|
166
|
+
event: styleUpdateEvent(absoluteId),
|
|
167
|
+
data: extracted.styles
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
source = `${source}
|
|
171
|
+
import "${rootRelativeId}";`;
|
|
172
|
+
cssMap.set(absoluteId, extracted.styles);
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
code: source.toString(),
|
|
176
|
+
map: extracted.map
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
182
|
+
0 && (module.exports = {
|
|
183
|
+
tamaguiExtractPlugin
|
|
184
|
+
});
|
|
185
|
+
//# 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 = 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) ? source : 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 (server && cssMap.has(absoluteId) && cssMap.get(absoluteId) !== extracted.styles) {\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 = (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": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,kBAAiB;AAEjB,oBAKO;AACP,qBAAoB;AAEpB,kBAA8B;AAE9B,MAAM,mBAAmB,CAAC,WAAmB,wBAAwB;AACrE,MAAM,0BAA0B;AAEzB,SAAS,qBAAqB,SAAiC;AACpE,QAAM,gBAAgB,QAAQ,WAAY,QAAQ,oBAAoB,QAAQ;AAE9E,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,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,KAAK,CAAC,CAAC;AAE1E,cAAIA,SAAQ;AACV,wBAAY,iBAAiBA,OAAM;AAGnC,YAAAA,QAAO,mBAAoBA,QAAe,6BAA6B,KAAK,IAAI;AAAA,UAClF;AAEA,iBAAO,GAAG,KAAK;AAAA,YACb,MAAM;AAAA,YACN,OAAO,iBAAiB,UAAU;AAAA,YAClC,MAAM,UAAU;AAAA,UAClB,CAAC;AAAA,QACH;AAEA,iBAAS,GAAG;AAAA,UAAmB;AAC/B,eAAO,IAAI,YAAY,UAAU,MAAM;AAAA,MACzC;AAEA,aAAO;AAAA,QACL,MAAM,OAAO,SAAS;AAAA,QACtB,KAAK,UAAU;AAAA,MACjB;AAAA,IAwBF;AAAA,EACF;AACF;",
|
|
6
|
+
"names": ["path", "options", "outdent", "module"]
|
|
7
|
+
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -14,5 +15,6 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
|
|
|
14
15
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
16
|
var src_exports = {};
|
|
16
17
|
module.exports = __toCommonJS(src_exports);
|
|
17
|
-
__reExport(src_exports, require("./plugin"), module.exports);
|
|
18
|
+
__reExport(src_exports, require("./plugin.js"), module.exports);
|
|
19
|
+
__reExport(src_exports, require("./extract.js"), module.exports);
|
|
18
20
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["export * from './plugin'\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["export * from './plugin.js'\nexport * from './extract.js'\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,wBAAd;AACA,wBAAc,yBADd;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
6
|
var __export = (target, all) => {
|
|
8
7
|
for (var name in all)
|
|
@@ -16,37 +15,43 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
15
|
}
|
|
17
16
|
return to;
|
|
18
17
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
20
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
19
|
var plugin_exports = {};
|
|
22
20
|
__export(plugin_exports, {
|
|
23
21
|
tamaguiPlugin: () => tamaguiPlugin
|
|
24
22
|
});
|
|
25
23
|
module.exports = __toCommonJS(plugin_exports);
|
|
26
|
-
var import_vite_plugin_environment = __toESM(require("vite-plugin-environment"));
|
|
27
24
|
function tamaguiPlugin(options) {
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
const components = [.../* @__PURE__ */ new Set([...options.components, "tamagui", "@tamagui/core"])];
|
|
26
|
+
const noExternalSSR = new RegExp(
|
|
27
|
+
`${components.join("|")}|react-native|expo-linear-gradient`,
|
|
28
|
+
"ig"
|
|
29
|
+
);
|
|
30
|
+
const plugin = {
|
|
31
|
+
name: "tamagui-base",
|
|
30
32
|
enforce: "pre",
|
|
31
33
|
config(userConfig, env) {
|
|
32
34
|
return {
|
|
33
|
-
plugins: [
|
|
34
|
-
esbuild: {
|
|
35
|
-
loader: "tsx"
|
|
36
|
-
},
|
|
35
|
+
plugins: [],
|
|
37
36
|
define: {
|
|
38
37
|
"global.__x": {},
|
|
39
38
|
_frameTimestamp: void 0,
|
|
40
39
|
_WORKLET: false,
|
|
41
|
-
process
|
|
42
|
-
env:
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
...process.env.NODE_ENV !== "test" && {
|
|
41
|
+
"process.env.TAMAGUI_TARGET": JSON.stringify(process.env.TAMAGUI_TARGET || "web"),
|
|
42
|
+
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || env.mode),
|
|
43
|
+
"process.env.ENABLE_RSC": JSON.stringify(process.env.ENABLE_RSC || ""),
|
|
44
|
+
"process.env.ENABLE_STEPS": JSON.stringify(process.env.ENABLE_STEPS || ""),
|
|
45
|
+
"process.env.IS_STATIC": JSON.stringify(false)
|
|
46
46
|
}
|
|
47
47
|
},
|
|
48
|
+
ssr: {
|
|
49
|
+
noExternal: noExternalSSR
|
|
50
|
+
},
|
|
48
51
|
optimizeDeps: {
|
|
52
|
+
include: ["styleq", "copy-to-clipboard", "react-native-reanimated"],
|
|
49
53
|
esbuildOptions: {
|
|
54
|
+
jsx: "transform",
|
|
50
55
|
resolveExtensions: [
|
|
51
56
|
".web.js",
|
|
52
57
|
".web.ts",
|
|
@@ -78,12 +83,18 @@ function tamaguiPlugin(options) {
|
|
|
78
83
|
alias: {
|
|
79
84
|
"react-native/Libraries/Renderer/shims/ReactFabric": "@tamagui/proxy-worm",
|
|
80
85
|
"react-native/Libraries/Utilities/codegenNativeComponent": "@tamagui/proxy-worm",
|
|
81
|
-
"react-native": "react-native-
|
|
86
|
+
"react-native-svg": "@tamagui/react-native-svg",
|
|
87
|
+
"react-native": "react-native-web",
|
|
88
|
+
...options.useReactNativeWebLite && {
|
|
89
|
+
"react-native": "react-native-web-lite",
|
|
90
|
+
"react-native-web": "react-native-web-lite"
|
|
91
|
+
}
|
|
82
92
|
}
|
|
83
93
|
}
|
|
84
94
|
};
|
|
85
95
|
}
|
|
86
96
|
};
|
|
97
|
+
return plugin;
|
|
87
98
|
}
|
|
88
99
|
// Annotate the CommonJS export names for ESM import in node:
|
|
89
100
|
0 && (module.exports = {
|
package/dist/cjs/plugin.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/plugin.ts"],
|
|
4
|
-
"sourcesContent": ["import type { TamaguiOptions } from '@tamagui/static'\nimport type { Plugin } from 'vite'\
|
|
5
|
-
"mappings": "
|
|
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 = [...new Set([...options.components, 'tamagui', '@tamagui/core'])]\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(process.env.TAMAGUI_TARGET || 'web'),\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(process.env.ENABLE_STEPS || ''),\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', 'copy-to-clipboard', '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': '@tamagui/proxy-worm',\n 'react-native/Libraries/Utilities/codegenNativeComponent': '@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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOO,SAAS,cACd,SAGQ;AACR,QAAM,aAAa,CAAC,GAAG,oBAAI,IAAI,CAAC,GAAG,QAAQ,YAAY,WAAW,eAAe,CAAC,CAAC;AACnF,QAAM,gBAAgB,IAAI;AAAA,IACxB,GAAG,WAAW,KAAK,GAAG;AAAA,IACtB;AAAA,EACF;AAEA,QAAM,SAAiB;AAAA,IACrB,MAAM;AAAA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A,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -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 = 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) ? source : 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 (server && cssMap.has(absoluteId) && cssMap.get(absoluteId) !== extracted.styles) {\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 = (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,gBAAgB,QAAQ,WAAY,QAAQ,oBAAoB,QAAQ;AAE9E,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,UAAU,CAAC,6BAA6B,IAAI,CAAC;AAC7E,aAAO;AAAA,QACL,cAAc,EAAE,QAAQ;AAAA,MAC1B;AAAA,IACF;AAAA,IAEA,MAAM,eAAe,gB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|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["export * from './plugin'\n"],
|
|
5
|
-
"mappings": "AAAA;",
|
|
4
|
+
"sourcesContent": ["export * from './plugin.js'\nexport * from './extract.js'\n"],
|
|
5
|
+
"mappings": "AAAA,cAAc;AACd,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/plugin.js
CHANGED
|
@@ -1,27 +1,34 @@
|
|
|
1
|
-
import envPlugin from "vite-plugin-environment";
|
|
2
1
|
function tamaguiPlugin(options) {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
const components = [.../* @__PURE__ */ new Set([...options.components, "tamagui", "@tamagui/core"])];
|
|
3
|
+
const noExternalSSR = new RegExp(
|
|
4
|
+
`${components.join("|")}|react-native|expo-linear-gradient`,
|
|
5
|
+
"ig"
|
|
6
|
+
);
|
|
7
|
+
const plugin = {
|
|
8
|
+
name: "tamagui-base",
|
|
5
9
|
enforce: "pre",
|
|
6
10
|
config(userConfig, env) {
|
|
7
11
|
return {
|
|
8
|
-
plugins: [
|
|
9
|
-
esbuild: {
|
|
10
|
-
loader: "tsx"
|
|
11
|
-
},
|
|
12
|
+
plugins: [],
|
|
12
13
|
define: {
|
|
13
14
|
"global.__x": {},
|
|
14
15
|
_frameTimestamp: void 0,
|
|
15
16
|
_WORKLET: false,
|
|
16
|
-
process
|
|
17
|
-
env:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
...process.env.NODE_ENV !== "test" && {
|
|
18
|
+
"process.env.TAMAGUI_TARGET": JSON.stringify(process.env.TAMAGUI_TARGET || "web"),
|
|
19
|
+
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || env.mode),
|
|
20
|
+
"process.env.ENABLE_RSC": JSON.stringify(process.env.ENABLE_RSC || ""),
|
|
21
|
+
"process.env.ENABLE_STEPS": JSON.stringify(process.env.ENABLE_STEPS || ""),
|
|
22
|
+
"process.env.IS_STATIC": JSON.stringify(false)
|
|
21
23
|
}
|
|
22
24
|
},
|
|
25
|
+
ssr: {
|
|
26
|
+
noExternal: noExternalSSR
|
|
27
|
+
},
|
|
23
28
|
optimizeDeps: {
|
|
29
|
+
include: ["styleq", "copy-to-clipboard", "react-native-reanimated"],
|
|
24
30
|
esbuildOptions: {
|
|
31
|
+
jsx: "transform",
|
|
25
32
|
resolveExtensions: [
|
|
26
33
|
".web.js",
|
|
27
34
|
".web.ts",
|
|
@@ -53,12 +60,18 @@ function tamaguiPlugin(options) {
|
|
|
53
60
|
alias: {
|
|
54
61
|
"react-native/Libraries/Renderer/shims/ReactFabric": "@tamagui/proxy-worm",
|
|
55
62
|
"react-native/Libraries/Utilities/codegenNativeComponent": "@tamagui/proxy-worm",
|
|
56
|
-
"react-native": "react-native-
|
|
63
|
+
"react-native-svg": "@tamagui/react-native-svg",
|
|
64
|
+
"react-native": "react-native-web",
|
|
65
|
+
...options.useReactNativeWebLite && {
|
|
66
|
+
"react-native": "react-native-web-lite",
|
|
67
|
+
"react-native-web": "react-native-web-lite"
|
|
68
|
+
}
|
|
57
69
|
}
|
|
58
70
|
}
|
|
59
71
|
};
|
|
60
72
|
}
|
|
61
73
|
};
|
|
74
|
+
return plugin;
|
|
62
75
|
}
|
|
63
76
|
export {
|
|
64
77
|
tamaguiPlugin
|