@tamagui/vite-plugin 3.0.0-beta.922.1 → 3.0.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/loadTamagui.cjs +55 -9
- package/dist/cjs/plugin.cjs +75 -18
- package/dist/cjs/zeroRuntime.cjs +0 -1
- package/dist/esm/loadTamagui.mjs +54 -9
- package/dist/esm/loadTamagui.mjs.map +1 -1
- package/dist/esm/plugin.mjs +77 -20
- package/dist/esm/plugin.mjs.map +1 -1
- package/dist/esm/zeroRuntime.mjs +0 -1
- package/dist/esm/zeroRuntime.mjs.map +1 -1
- package/package.json +10 -9
- package/src/loadTamagui.ts +90 -14
- package/src/plugin.ts +160 -33
- package/src/zeroRuntime.ts +2 -2
- package/types/loadTamagui.d.ts +17 -1
- package/types/loadTamagui.d.ts.map +1 -1
- package/types/plugin.d.ts +1 -1
- package/types/plugin.d.ts.map +1 -1
- package/types/zeroRuntime.d.ts +1 -1
package/dist/esm/plugin.mjs
CHANGED
|
@@ -6,8 +6,8 @@ import { readFile } from "node:fs/promises";
|
|
|
6
6
|
import { createRequire } from "node:module";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
9
|
-
import { createFilter, createIdResolver, createRunnableDevEnvironment, defaultClientConditions, defaultClientMainFields,
|
|
10
|
-
import { TAMAGUI_EVALUATION_ENVIRONMENT, createViteTamaguiLoader } from "./loadTamagui.mjs";
|
|
9
|
+
import { createFilter, createIdResolver, createRunnableDevEnvironment, defaultClientConditions, defaultClientMainFields, resolveConfig } from "vite";
|
|
10
|
+
import { TAMAGUI_EVALUATION_ENVIRONMENT, createViteTamaguiLoader, viteBuildConfigLoader } from "./loadTamagui.mjs";
|
|
11
11
|
import { createCompilerStatsReport, formatCompilerStatsReport } from "./compilerStats.mjs";
|
|
12
12
|
import { ZERO_CSS_FILENAME, ZERO_ISLAND_DIRNAME, assertZeroGraph, buildIsland, createZeroRuntimeController, finalizeZeroCSS, zeroModuleKey } from "./zeroRuntime.mjs";
|
|
13
13
|
|
|
@@ -165,6 +165,7 @@ async function createOwnedEvaluationConfig(config, configuredEvaluationPackages)
|
|
|
165
165
|
const plugins = environment.plugins.filter(isEvaluationUserPlugin).map((plugin) => createEvaluationPluginFacade(plugin));
|
|
166
166
|
const resolve2 = getEvaluationResolve(environment.resolve, config.root, plugins.some((plugin) => plugin.name === oneTsconfigPathsPluginName), configuredEvaluationPackages);
|
|
167
167
|
const { createEnvironment: _createEnvironment, ...dev } = environment.dev;
|
|
168
|
+
const { esbuildOptions: _esbuildOptions, ...optimizeDeps } = environment.optimizeDeps;
|
|
168
169
|
return resolveConfig({
|
|
169
170
|
configFile: false,
|
|
170
171
|
root: config.root,
|
|
@@ -178,7 +179,7 @@ async function createOwnedEvaluationConfig(config, configuredEvaluationPackages)
|
|
|
178
179
|
keepProcessEnv: environment.keepProcessEnv,
|
|
179
180
|
define: environment.define,
|
|
180
181
|
resolve: resolve2,
|
|
181
|
-
optimizeDeps
|
|
182
|
+
optimizeDeps,
|
|
182
183
|
dev: {
|
|
183
184
|
...dev,
|
|
184
185
|
moduleRunnerTransform: true
|
|
@@ -219,12 +220,34 @@ function addIfInstalled(userConf, projectRoot, ids) {
|
|
|
219
220
|
userConf.optimizeDeps.include ||= [];
|
|
220
221
|
for (const id of ids) if (!userConf.optimizeDeps.include.includes(id) && isInstalled(root, id)) userConf.optimizeDeps.include.push(id);
|
|
221
222
|
}
|
|
223
|
+
function svgWebEntry() {
|
|
224
|
+
return normalizePath(path.join(path.dirname(resolve("@tamagui/react-native-svg/package.json")), "dist/esm/index.mjs"));
|
|
225
|
+
}
|
|
226
|
+
function resolveSvgWeb(source) {
|
|
227
|
+
if (source === "react-native-svg" || source === "@tamagui/react-native-svg") return svgWebEntry();
|
|
228
|
+
}
|
|
229
|
+
const svgOptimizerPlugin = {
|
|
230
|
+
name: "tamagui-svg-optimizer",
|
|
231
|
+
enforce: "pre",
|
|
232
|
+
resolveId: {
|
|
233
|
+
filter: { id: /^(?:react-native-svg|@tamagui\/react-native-svg)$/ },
|
|
234
|
+
handler(source) {
|
|
235
|
+
return resolveSvgWeb(source);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
};
|
|
222
239
|
function tamaguiAliases(options = {}) {
|
|
223
240
|
const aliases = [];
|
|
224
|
-
if (options.svg)
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
241
|
+
if (options.svg) {
|
|
242
|
+
const svg = svgWebEntry();
|
|
243
|
+
aliases.push({
|
|
244
|
+
find: "react-native-svg",
|
|
245
|
+
replacement: svg
|
|
246
|
+
}, {
|
|
247
|
+
find: "@tamagui/react-native-svg",
|
|
248
|
+
replacement: svg
|
|
249
|
+
});
|
|
250
|
+
}
|
|
228
251
|
if (options.rnwLite) {
|
|
229
252
|
const rnwlBase = path.dirname(resolve("@tamagui/react-native-web-lite/package.json"));
|
|
230
253
|
const rnwl = normalizePath(path.join(rnwlBase, options.rnwLite === "without-animated" ? "dist/esm/without-animated.mjs" : "dist/esm/index.mjs"));
|
|
@@ -267,7 +290,7 @@ function createTamaguiNativePlugin(tamaguiOptionsIn, nativeContext) {
|
|
|
267
290
|
root,
|
|
268
291
|
platform: "native",
|
|
269
292
|
outputCSS: void 0
|
|
270
|
-
});
|
|
293
|
+
}, viteBuildConfigLoader);
|
|
271
294
|
const options = {
|
|
272
295
|
...loadedOptions,
|
|
273
296
|
root,
|
|
@@ -464,12 +487,14 @@ function createTamaguiPlugins({ disableResolveConfig, wrapExtractedCSS = (css) =
|
|
|
464
487
|
},
|
|
465
488
|
dev: {
|
|
466
489
|
createEnvironment(name, resolved) {
|
|
467
|
-
|
|
490
|
+
const environment = createRunnableDevEnvironment(name, createServeEvaluationConfig(resolved, configuredEvaluationPackages), { hot: false });
|
|
491
|
+
tamaguiLoader.setEnvironment(environment);
|
|
492
|
+
return environment;
|
|
468
493
|
},
|
|
469
494
|
moduleRunnerTransform: true
|
|
470
495
|
}
|
|
471
496
|
});
|
|
472
|
-
tamaguiLoader.loadTamaguiBuildConfig();
|
|
497
|
+
tamaguiLoader.loadTamaguiBuildConfig().catch(() => {});
|
|
473
498
|
const ensureLoaded = async () => {
|
|
474
499
|
const promise = tamaguiLoader.getLoadPromise();
|
|
475
500
|
if (promise) await promise;
|
|
@@ -482,6 +507,7 @@ function createTamaguiPlugins({ disableResolveConfig, wrapExtractedCSS = (css) =
|
|
|
482
507
|
const transformedModuleIds = /* @__PURE__ */ new Set();
|
|
483
508
|
const compilerHotUpdateSignatures = /* @__PURE__ */ new Map();
|
|
484
509
|
const compilerHotReloadSignatures = /* @__PURE__ */ new Map();
|
|
510
|
+
let watchedDependencies = /* @__PURE__ */ new Set();
|
|
485
511
|
let config;
|
|
486
512
|
let server;
|
|
487
513
|
let zero = null;
|
|
@@ -505,6 +531,7 @@ function createTamaguiPlugins({ disableResolveConfig, wrapExtractedCSS = (css) =
|
|
|
505
531
|
function isNotClient(environment) {
|
|
506
532
|
return environment?.name && environment.name !== "client";
|
|
507
533
|
}
|
|
534
|
+
const isDevEnvironment = (environment) => environment.mode === "dev";
|
|
508
535
|
function isNative(environment) {
|
|
509
536
|
return environment?.name && (environment.name === "ios" || environment.name === "android");
|
|
510
537
|
}
|
|
@@ -527,11 +554,13 @@ function createTamaguiPlugins({ disableResolveConfig, wrapExtractedCSS = (css) =
|
|
|
527
554
|
{
|
|
528
555
|
name: "tamagui",
|
|
529
556
|
enforce: "pre",
|
|
557
|
+
resolveId(source) {
|
|
558
|
+
if (disableResolveConfig || tamaguiOptionsIn.platform === "native" || isNative(this.environment)) return;
|
|
559
|
+
return resolveSvgWeb(source);
|
|
560
|
+
},
|
|
530
561
|
configureServer(_server) {
|
|
531
562
|
server = _server;
|
|
532
|
-
|
|
533
|
-
if (!isRunnableDevEnvironment(evaluationEnvironment)) throw new Error(`The ${TAMAGUI_EVALUATION_ENVIRONMENT} Vite environment must support ModuleRunner evaluation`);
|
|
534
|
-
tamaguiLoader.setEnvironment(evaluationEnvironment);
|
|
563
|
+
watchedDependencies = /* @__PURE__ */ new Set();
|
|
535
564
|
},
|
|
536
565
|
async buildEnd() {
|
|
537
566
|
await releaseBuildEnvironment(this.environment);
|
|
@@ -560,7 +589,7 @@ function createTamaguiPlugins({ disableResolveConfig, wrapExtractedCSS = (css) =
|
|
|
560
589
|
[TAMAGUI_EVALUATION_ENVIRONMENT]: getEvaluationEnvironmentOptions(resolvedRoot, userConfig.environments?.[TAMAGUI_EVALUATION_ENVIRONMENT]?.resolve?.noExternal)
|
|
561
590
|
},
|
|
562
591
|
define: {
|
|
563
|
-
"process.env.TAMAGUI_RUNTIME": JSON.stringify("full"),
|
|
592
|
+
"process.env.TAMAGUI_RUNTIME": JSON.stringify(zeroIslandBuild ? "island" : "full"),
|
|
564
593
|
_frameTimestamp: void 0,
|
|
565
594
|
_WORKLET: false,
|
|
566
595
|
__DEV__: `${env.mode === "development"}`,
|
|
@@ -575,7 +604,6 @@ function createTamaguiPlugins({ disableResolveConfig, wrapExtractedCSS = (css) =
|
|
|
575
604
|
alias: { ...options.platform !== "native" && {
|
|
576
605
|
"react-native/Libraries/Renderer/shims/ReactFabric": resolve("@tamagui/proxy-worm"),
|
|
577
606
|
"react-native/Libraries/Utilities/codegenNativeComponent": resolve("@tamagui/proxy-worm"),
|
|
578
|
-
"react-native-svg": resolve("@tamagui/react-native-svg"),
|
|
579
607
|
...!useReactNativeWebLite && { "react-native": resolve("react-native-web") }
|
|
580
608
|
} }
|
|
581
609
|
}
|
|
@@ -614,6 +642,11 @@ function createTamaguiPlugins({ disableResolveConfig, wrapExtractedCSS = (css) =
|
|
|
614
642
|
await ensureLoaded();
|
|
615
643
|
userConf.optimizeDeps ||= {};
|
|
616
644
|
userConf.optimizeDeps.include ||= [];
|
|
645
|
+
if (!disableResolveConfig && tamaguiOptionsIn.platform !== "native") {
|
|
646
|
+
userConf.optimizeDeps.rolldownOptions ||= {};
|
|
647
|
+
const existingPlugins = userConf.optimizeDeps.rolldownOptions.plugins;
|
|
648
|
+
userConf.optimizeDeps.rolldownOptions.plugins = [svgOptimizerPlugin, ...Array.isArray(existingPlugins) ? existingPlugins : existingPlugins ? [existingPlugins] : []];
|
|
649
|
+
}
|
|
617
650
|
userConf.optimizeDeps.include.push("inline-style-prefixer");
|
|
618
651
|
addIfInstalled(userConf, userConf.root, ["@react-native/normalize-color"]);
|
|
619
652
|
addIfInstalled(userConf, userConf.root, [
|
|
@@ -647,7 +680,13 @@ function createTamaguiPlugins({ disableResolveConfig, wrapExtractedCSS = (css) =
|
|
|
647
680
|
},
|
|
648
681
|
async buildStart() {
|
|
649
682
|
const buildConfig = this.environment.getTopLevelConfig();
|
|
650
|
-
if (buildConfig.command !== "build")
|
|
683
|
+
if (buildConfig.command !== "build") {
|
|
684
|
+
if (this.environment.name === "client") {
|
|
685
|
+
const dependencies = await tamaguiLoader.ensureFullConfigLoaded();
|
|
686
|
+
for (const dependency of dependencies) this.addWatchFile(dependency);
|
|
687
|
+
}
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
651
690
|
const pendingCleanup = buildCleanupPromise;
|
|
652
691
|
if (pendingCleanup) await pendingCleanup;
|
|
653
692
|
const buildEnvironment = this.environment;
|
|
@@ -678,13 +717,18 @@ function createTamaguiPlugins({ disableResolveConfig, wrapExtractedCSS = (css) =
|
|
|
678
717
|
if (!tamaguiLoader.isEvaluationDependency(options.file)) {
|
|
679
718
|
if (this.environment.name !== "client") return;
|
|
680
719
|
const compilerFrontend = getCompilerFrontend(this.environment);
|
|
681
|
-
|
|
720
|
+
let source = null;
|
|
721
|
+
if (options.type !== "delete") try {
|
|
722
|
+
source = await options.read();
|
|
723
|
+
} catch (error) {
|
|
724
|
+
if (!(error instanceof Error && "code" in error && error.code === "ENOENT")) throw error;
|
|
725
|
+
}
|
|
682
726
|
const affectedModules = /* @__PURE__ */ new Set();
|
|
683
727
|
const compilerHmrRoots = new Set(compilerFrontend.dependentsOf(options.file));
|
|
684
728
|
if (compilerHmrRoots.size || compilerFrontend.has(options.file)) compilerHmrRoots.add(options.file);
|
|
685
729
|
if (compilerFrontend.has(options.file) || compilerHmrRoots.size > 0) {
|
|
686
730
|
if (!(await ensureLoaded())?.disable) {
|
|
687
|
-
const invalidatedIds =
|
|
731
|
+
const invalidatedIds = source === null ? (await compilerFrontend.remove(options.file)).invalidatedIds : await compilerFrontend.update({
|
|
688
732
|
id: options.file,
|
|
689
733
|
source,
|
|
690
734
|
root: config.root,
|
|
@@ -718,7 +762,10 @@ function createTamaguiPlugins({ disableResolveConfig, wrapExtractedCSS = (css) =
|
|
|
718
762
|
}
|
|
719
763
|
const cssId = getAbsoluteVirtualFileId(`${invalidatedId}${virtualExt}`);
|
|
720
764
|
const cssModule = this.environment.moduleGraph.getModuleById(cssId);
|
|
721
|
-
if (cssModule)
|
|
765
|
+
if (cssModule) {
|
|
766
|
+
this.environment.moduleGraph.invalidateModule(cssModule);
|
|
767
|
+
affectedModules.add(cssModule);
|
|
768
|
+
}
|
|
722
769
|
}
|
|
723
770
|
}
|
|
724
771
|
}
|
|
@@ -737,6 +784,11 @@ function createTamaguiPlugins({ disableResolveConfig, wrapExtractedCSS = (css) =
|
|
|
737
784
|
tamaguiLoader.invalidate(options.file);
|
|
738
785
|
invalidateCompilerModules();
|
|
739
786
|
}
|
|
787
|
+
const unwatched = (await tamaguiLoader.ensureFullConfigLoaded()).filter((file) => !watchedDependencies.has(file));
|
|
788
|
+
if (unwatched.length) {
|
|
789
|
+
for (const file of unwatched) watchedDependencies.add(file);
|
|
790
|
+
server.watcher.add(unwatched);
|
|
791
|
+
}
|
|
740
792
|
if (this.environment.name === "client" && compilerHotReloadSignatures.get(options.file) !== signature) {
|
|
741
793
|
compilerHotReloadSignatures.set(options.file, signature);
|
|
742
794
|
this.environment.hot.send({
|
|
@@ -770,6 +822,11 @@ function createTamaguiPlugins({ disableResolveConfig, wrapExtractedCSS = (css) =
|
|
|
770
822
|
if (isNotClient(this.environment)) return;
|
|
771
823
|
if (!shouldExtract) return;
|
|
772
824
|
const [validId] = id.split("?");
|
|
825
|
+
if (!validId.endsWith(virtualExt)) return;
|
|
826
|
+
if (isDevEnvironment(this.environment)) {
|
|
827
|
+
const importer = this.environment.moduleGraph.getModuleById(validId.slice(0, -virtualExt.length));
|
|
828
|
+
if (importer && importer.transformResult == null) await this.environment.transformRequest(importer.url);
|
|
829
|
+
}
|
|
773
830
|
return cssMap.get(validId);
|
|
774
831
|
}
|
|
775
832
|
},
|
|
@@ -866,7 +923,7 @@ function createTamaguiPlugins({ disableResolveConfig, wrapExtractedCSS = (css) =
|
|
|
866
923
|
}
|
|
867
924
|
if (zero.isEnforcing) {
|
|
868
925
|
Static.mergeIslandBridges(zero.bridges, zeroResult.bridges);
|
|
869
|
-
const moduleCSS = [wrapExtractedCSS(result.plan.css), ...
|
|
926
|
+
const moduleCSS = [wrapExtractedCSS(result.plan.css), ...zeroResult.bridgeCSS.values()].filter(Boolean).join("\n");
|
|
870
927
|
if (config.command !== "build") {
|
|
871
928
|
let cssImport2 = "";
|
|
872
929
|
if (moduleCSS) {
|