defuss-ssg 0.6.1 → 0.6.2
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/cli.mjs +3 -2
- package/dist/index.cjs +2 -1
- package/dist/index.mjs +3 -2
- package/dist/runtime.cjs +26 -4
- package/dist/runtime.mjs +26 -4
- package/dist/{serve-DIW2gbz_.mjs → serve-CTYzPwKQ.mjs} +1 -1
- package/dist/{vite-DlnPNJYO.cjs → vite-CkpguLfK.cjs} +66 -2
- package/dist/{vite-DLXcqaZX.mjs → vite-DdJcWQGP.mjs} +67 -3
- package/dist/vite.cjs +2 -1
- package/dist/vite.mjs +2 -1
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { v as validateProjectDir, b as build } from './vite-
|
|
3
|
-
import { d as dev, s as serve } from './serve-
|
|
2
|
+
import { v as validateProjectDir, b as build } from './vite-DdJcWQGP.mjs';
|
|
3
|
+
import { d as dev, s as serve } from './serve-CTYzPwKQ.mjs';
|
|
4
4
|
import { join, dirname, resolve } from 'node:path';
|
|
5
5
|
import { existsSync, readFileSync } from 'node:fs';
|
|
6
6
|
import { spawn } from 'node:child_process';
|
|
@@ -11,6 +11,7 @@ import 'node:crypto';
|
|
|
11
11
|
import '@mdx-js/rollup';
|
|
12
12
|
import 'vite';
|
|
13
13
|
import 'defuss-vite';
|
|
14
|
+
import 'node:module';
|
|
14
15
|
import 'node:url';
|
|
15
16
|
import 'node:os';
|
|
16
17
|
import 'esbuild';
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var vite = require('./vite-
|
|
3
|
+
var vite = require('./vite-CkpguLfK.cjs');
|
|
4
4
|
var mdx = require('@mdx-js/rollup');
|
|
5
5
|
var vite$1 = require('vite');
|
|
6
6
|
var defuss = require('defuss-vite');
|
|
@@ -11,6 +11,7 @@ require('fast-glob');
|
|
|
11
11
|
require('node:fs/promises');
|
|
12
12
|
require('defuss/server');
|
|
13
13
|
require('node:crypto');
|
|
14
|
+
require('node:module');
|
|
14
15
|
require('node:url');
|
|
15
16
|
require('node:os');
|
|
16
17
|
require('esbuild');
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { H as HTTP_METHODS, b as build, a as buildEndpoints, c as compileEndpoints, d as compileRpcModule, e as configDefaults, f as defussSsg, g as discoverEndpointSourceFiles, h as discoverRpcFile, i as endpointFileToRoute, j as handleEndpointRoute, k as handleRpcRequest, l as initializeRpc, m as loadEndpointModule, n as matchRoutePattern, r as readConfig, o as registerEndpoints, p as resolveEndpoints, q as routeToExpressPattern } from './vite-
|
|
2
|
-
export { d as dev, s as serve } from './serve-
|
|
1
|
+
export { H as HTTP_METHODS, b as build, a as buildEndpoints, c as compileEndpoints, d as compileRpcModule, e as configDefaults, f as defussSsg, g as discoverEndpointSourceFiles, h as discoverRpcFile, i as endpointFileToRoute, j as handleEndpointRoute, k as handleRpcRequest, l as initializeRpc, m as loadEndpointModule, n as matchRoutePattern, r as readConfig, o as registerEndpoints, p as resolveEndpoints, q as routeToExpressPattern } from './vite-DdJcWQGP.mjs';
|
|
2
|
+
export { d as dev, s as serve } from './serve-CTYzPwKQ.mjs';
|
|
3
3
|
import 'fast-glob';
|
|
4
4
|
import 'node:fs';
|
|
5
5
|
import 'node:fs/promises';
|
|
@@ -9,6 +9,7 @@ import 'node:crypto';
|
|
|
9
9
|
import '@mdx-js/rollup';
|
|
10
10
|
import 'vite';
|
|
11
11
|
import 'defuss-vite';
|
|
12
|
+
import 'node:module';
|
|
12
13
|
import 'node:url';
|
|
13
14
|
import 'node:os';
|
|
14
15
|
import 'esbuild';
|
package/dist/runtime.cjs
CHANGED
|
@@ -7,6 +7,22 @@ const setupLiveReload = () => {
|
|
|
7
7
|
};
|
|
8
8
|
const runtimeWindow = window;
|
|
9
9
|
const pageCache = runtimeWindow.__defuss_pageCache ?? /* @__PURE__ */ new Map();
|
|
10
|
+
const isHydratableComponent = (value) => typeof value === "function";
|
|
11
|
+
const pickHydrationComponent = (moduleExports, preferredExportName) => {
|
|
12
|
+
if (isHydratableComponent(moduleExports.default)) {
|
|
13
|
+
return moduleExports.default;
|
|
14
|
+
}
|
|
15
|
+
if (preferredExportName && isHydratableComponent(moduleExports[preferredExportName])) {
|
|
16
|
+
return moduleExports[preferredExportName];
|
|
17
|
+
}
|
|
18
|
+
const functionExports = Object.entries(moduleExports).filter(
|
|
19
|
+
([key, value]) => key !== "default" && isHydratableComponent(value)
|
|
20
|
+
);
|
|
21
|
+
if (functionExports.length === 1) {
|
|
22
|
+
return functionExports[0][1];
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
};
|
|
10
26
|
const HYDRATION_ATTRIBUTE_NAMES = [
|
|
11
27
|
"data-hydrate-id",
|
|
12
28
|
"data-hydrate",
|
|
@@ -514,6 +530,7 @@ const hydrateBoundary = async (boundary, options = {}) => {
|
|
|
514
530
|
return;
|
|
515
531
|
}
|
|
516
532
|
const id = boundary.getAttribute("data-hydrate-id");
|
|
533
|
+
const exportName = boundary.getAttribute("data-hydrate-export");
|
|
517
534
|
const src = boundary.getAttribute("data-hydrate-src");
|
|
518
535
|
const propsStr = boundary.getAttribute("data-hydrate-props");
|
|
519
536
|
const runtimeUrl = boundary.getAttribute("data-hydrate-runtime");
|
|
@@ -530,15 +547,20 @@ const hydrateBoundary = async (boundary, options = {}) => {
|
|
|
530
547
|
/* @vite-ignore */
|
|
531
548
|
`${runtimeUrl}${cacheBust}`
|
|
532
549
|
);
|
|
533
|
-
const
|
|
550
|
+
const moduleExports = await import(
|
|
534
551
|
/* @vite-ignore */
|
|
535
552
|
`${src}${cacheBust}`
|
|
536
553
|
);
|
|
537
|
-
|
|
538
|
-
|
|
554
|
+
const Component = pickHydrationComponent(
|
|
555
|
+
moduleExports,
|
|
556
|
+
exportName
|
|
557
|
+
);
|
|
558
|
+
if (!Component) {
|
|
559
|
+
console.error(
|
|
560
|
+
`[hydrate:${id}] No hydratable export in ${src}${exportName ? ` (expected ${exportName})` : ""}`
|
|
561
|
+
);
|
|
539
562
|
return;
|
|
540
563
|
}
|
|
541
|
-
const Component = exports$1.default;
|
|
542
564
|
const props = JSON.parse(propsStr);
|
|
543
565
|
console.log(
|
|
544
566
|
`[hydrate:${id}] Rendering component ${Component.name || "(anon)"} with props:`,
|
package/dist/runtime.mjs
CHANGED
|
@@ -5,6 +5,22 @@ const setupLiveReload = () => {
|
|
|
5
5
|
};
|
|
6
6
|
const runtimeWindow = window;
|
|
7
7
|
const pageCache = runtimeWindow.__defuss_pageCache ?? /* @__PURE__ */ new Map();
|
|
8
|
+
const isHydratableComponent = (value) => typeof value === "function";
|
|
9
|
+
const pickHydrationComponent = (moduleExports, preferredExportName) => {
|
|
10
|
+
if (isHydratableComponent(moduleExports.default)) {
|
|
11
|
+
return moduleExports.default;
|
|
12
|
+
}
|
|
13
|
+
if (preferredExportName && isHydratableComponent(moduleExports[preferredExportName])) {
|
|
14
|
+
return moduleExports[preferredExportName];
|
|
15
|
+
}
|
|
16
|
+
const functionExports = Object.entries(moduleExports).filter(
|
|
17
|
+
([key, value]) => key !== "default" && isHydratableComponent(value)
|
|
18
|
+
);
|
|
19
|
+
if (functionExports.length === 1) {
|
|
20
|
+
return functionExports[0][1];
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
};
|
|
8
24
|
const HYDRATION_ATTRIBUTE_NAMES = [
|
|
9
25
|
"data-hydrate-id",
|
|
10
26
|
"data-hydrate",
|
|
@@ -512,6 +528,7 @@ const hydrateBoundary = async (boundary, options = {}) => {
|
|
|
512
528
|
return;
|
|
513
529
|
}
|
|
514
530
|
const id = boundary.getAttribute("data-hydrate-id");
|
|
531
|
+
const exportName = boundary.getAttribute("data-hydrate-export");
|
|
515
532
|
const src = boundary.getAttribute("data-hydrate-src");
|
|
516
533
|
const propsStr = boundary.getAttribute("data-hydrate-props");
|
|
517
534
|
const runtimeUrl = boundary.getAttribute("data-hydrate-runtime");
|
|
@@ -528,15 +545,20 @@ const hydrateBoundary = async (boundary, options = {}) => {
|
|
|
528
545
|
/* @vite-ignore */
|
|
529
546
|
`${runtimeUrl}${cacheBust}`
|
|
530
547
|
);
|
|
531
|
-
const
|
|
548
|
+
const moduleExports = await import(
|
|
532
549
|
/* @vite-ignore */
|
|
533
550
|
`${src}${cacheBust}`
|
|
534
551
|
);
|
|
535
|
-
|
|
536
|
-
|
|
552
|
+
const Component = pickHydrationComponent(
|
|
553
|
+
moduleExports,
|
|
554
|
+
exportName
|
|
555
|
+
);
|
|
556
|
+
if (!Component) {
|
|
557
|
+
console.error(
|
|
558
|
+
`[hydrate:${id}] No hydratable export in ${src}${exportName ? ` (expected ${exportName})` : ""}`
|
|
559
|
+
);
|
|
537
560
|
return;
|
|
538
561
|
}
|
|
539
|
-
const Component = exports$1.default;
|
|
540
562
|
const props = JSON.parse(propsStr);
|
|
541
563
|
console.log(
|
|
542
564
|
`[hydrate:${id}] Rendering component ${Component.name || "(anon)"} with props:`,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import mdx from '@mdx-js/rollup';
|
|
2
2
|
import { createServer } from 'vite';
|
|
3
3
|
import defuss from 'defuss-vite';
|
|
4
|
-
import { v as validateProjectDir, r as readConfig, f as defussSsg, o as registerEndpoints, l as initializeRpc, s as readIncomingBody, t as createWebRequest, k as handleRpcRequest, u as sendWebResponse } from './vite-
|
|
4
|
+
import { v as validateProjectDir, r as readConfig, f as defussSsg, o as registerEndpoints, l as initializeRpc, s as readIncomingBody, t as createWebRequest, k as handleRpcRequest, u as sendWebResponse } from './vite-DdJcWQGP.mjs';
|
|
5
5
|
import { existsSync } from 'node:fs';
|
|
6
6
|
import { join } from 'node:path';
|
|
7
7
|
import { express, startServer } from 'defuss-express';
|
|
@@ -9,6 +9,7 @@ var node_crypto = require('node:crypto');
|
|
|
9
9
|
var mdx = require('@mdx-js/rollup');
|
|
10
10
|
var vite = require('vite');
|
|
11
11
|
var defuss = require('defuss-vite');
|
|
12
|
+
var node_module = require('node:module');
|
|
12
13
|
var node_url = require('node:url');
|
|
13
14
|
var node_os = require('node:os');
|
|
14
15
|
var esbuild = require('esbuild');
|
|
@@ -78,6 +79,13 @@ const toStableHydrateId = (seed) => {
|
|
|
78
79
|
const digest = node_crypto.createHash("sha1").update(seed).digest("hex").slice(0, 12);
|
|
79
80
|
return `dh_${digest}`;
|
|
80
81
|
};
|
|
82
|
+
const toPascalCase = (value) => value.split(/[^A-Za-z0-9]+/).filter(Boolean).map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1)).join("");
|
|
83
|
+
const toComponentExportName = (componentFilePath) => {
|
|
84
|
+
const extension = node_path.extname(componentFilePath);
|
|
85
|
+
const fileStem = node_path.basename(componentFilePath, extension);
|
|
86
|
+
const exportBaseName = fileStem.toLowerCase() === "index" ? node_path.basename(node_path.dirname(componentFilePath)) : fileStem;
|
|
87
|
+
return toPascalCase(exportBaseName);
|
|
88
|
+
};
|
|
81
89
|
function applyAutoHydrate(vdom, componentsDir, componentsPublicPrefix, relativeOutputHtmlFilePath) {
|
|
82
90
|
const componentsRoot = node_path.resolve(componentsDir);
|
|
83
91
|
let hydrateIndex = 0;
|
|
@@ -93,6 +101,9 @@ function applyAutoHydrate(vdom, componentsDir, componentsPublicPrefix, relativeO
|
|
|
93
101
|
if (vnode.sourceInfo && typeof vnode.sourceInfo === "object" && typeof vnode.sourceInfo.fileName === "string" && vnode.sourceInfo.fileName.includes(componentsDir) && vnode.type !== "script" && vnode.type !== "head" && vnode.type !== "link" && vnode.type !== "meta" && vnode.type !== "title") {
|
|
94
102
|
const sourceFile = node_path.resolve(vnode.sourceInfo.fileName);
|
|
95
103
|
const relativeComponentPath = node_path.relative(componentsRoot, sourceFile);
|
|
104
|
+
const componentExportName = toComponentExportName(
|
|
105
|
+
relativeComponentPath
|
|
106
|
+
);
|
|
96
107
|
if (relativeComponentPath.startsWith("..") || relativeComponentPath.length === 0) {
|
|
97
108
|
throw new Error(
|
|
98
109
|
`[auto-hydrate] Component source file is outside the components directory: ${sourceFile}`
|
|
@@ -126,6 +137,7 @@ function applyAutoHydrate(vdom, componentsDir, componentsPublicPrefix, relativeO
|
|
|
126
137
|
attributes: {
|
|
127
138
|
"data-hydrate-id": id,
|
|
128
139
|
"data-hydrate": "true",
|
|
140
|
+
"data-hydrate-export": componentExportName,
|
|
129
141
|
"data-hydrate-src": clientSrcFile,
|
|
130
142
|
"data-hydrate-props": JSON.stringify(componentProps),
|
|
131
143
|
"data-hydrate-runtime": `/${componentsPublicPrefix}/runtime.js`
|
|
@@ -643,7 +655,7 @@ const registerEndpoints = async (registrar, projectDir, _config, debug = false)
|
|
|
643
655
|
}
|
|
644
656
|
};
|
|
645
657
|
|
|
646
|
-
const __filename$1 = node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite-
|
|
658
|
+
const __filename$1 = node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite-CkpguLfK.cjs', document.baseURI).href)));
|
|
647
659
|
const __dirname$1 = node_path.dirname(__filename$1);
|
|
648
660
|
const isHtmlLikePageSource = (filePath) => {
|
|
649
661
|
const extension = node_path.extname(filePath).toLowerCase();
|
|
@@ -669,6 +681,30 @@ const resolveLocalHelperFile = (sourceRelativePath, builtRelativePath) => {
|
|
|
669
681
|
}
|
|
670
682
|
return node_path.resolve(__dirname$1, builtRelativePath);
|
|
671
683
|
};
|
|
684
|
+
const loadProjectTailwindVitePlugins = async (projectDir, debug) => {
|
|
685
|
+
const requireFromBuild = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite-CkpguLfK.cjs', document.baseURI).href)));
|
|
686
|
+
try {
|
|
687
|
+
const resolvedPluginPath = requireFromBuild.resolve("@tailwindcss/vite", {
|
|
688
|
+
paths: [projectDir]
|
|
689
|
+
});
|
|
690
|
+
const tailwindModule = await import(node_url.pathToFileURL(resolvedPluginPath).href);
|
|
691
|
+
if (typeof tailwindModule.default !== "function") {
|
|
692
|
+
return [];
|
|
693
|
+
}
|
|
694
|
+
const plugin = tailwindModule.default();
|
|
695
|
+
if (!plugin) {
|
|
696
|
+
return [];
|
|
697
|
+
}
|
|
698
|
+
return Array.isArray(plugin) ? plugin : [plugin];
|
|
699
|
+
} catch (error) {
|
|
700
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
701
|
+
const isMissingPlugin = message.includes("@tailwindcss/vite");
|
|
702
|
+
if (!isMissingPlugin && debug) {
|
|
703
|
+
console.warn("[build] Failed to load @tailwindcss/vite from project:", error);
|
|
704
|
+
}
|
|
705
|
+
return [];
|
|
706
|
+
}
|
|
707
|
+
};
|
|
672
708
|
const injectStylesheetLinks$1 = (html, hrefs) => {
|
|
673
709
|
const missingHrefs = hrefs.filter((href) => !html.includes(`href="${href}"`));
|
|
674
710
|
if (missingHrefs.length === 0) {
|
|
@@ -680,6 +716,29 @@ const injectStylesheetLinks$1 = (html, hrefs) => {
|
|
|
680
716
|
}
|
|
681
717
|
return `${linkTags}${html}`;
|
|
682
718
|
};
|
|
719
|
+
const normalizeComponentStylesheet = (css) => {
|
|
720
|
+
const compiledTailwindBanner = "/*! tailwindcss";
|
|
721
|
+
const compiledTailwindIndex = css.indexOf(compiledTailwindBanner);
|
|
722
|
+
if (compiledTailwindIndex <= 0) {
|
|
723
|
+
return css;
|
|
724
|
+
}
|
|
725
|
+
const prefix = css.slice(0, compiledTailwindIndex).trimStart();
|
|
726
|
+
const hasRawTailwindPrelude = prefix.startsWith("@layer theme, base, components, utilities;") && prefix.includes("@theme default");
|
|
727
|
+
if (!hasRawTailwindPrelude) {
|
|
728
|
+
return css;
|
|
729
|
+
}
|
|
730
|
+
return css.slice(compiledTailwindIndex);
|
|
731
|
+
};
|
|
732
|
+
const normalizeComponentStylesheets = async (componentsOutputDir) => {
|
|
733
|
+
const cssFiles = await glob.async(node_path.join(componentsOutputDir, "**/*.css"));
|
|
734
|
+
for (const cssFile of cssFiles) {
|
|
735
|
+
const currentCss = await promises.readFile(cssFile, "utf-8");
|
|
736
|
+
const normalizedCss = normalizeComponentStylesheet(currentCss);
|
|
737
|
+
if (normalizedCss !== currentCss) {
|
|
738
|
+
await promises.writeFile(cssFile, normalizedCss);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
};
|
|
683
742
|
const getComponentStylesheetHrefs$1 = async (componentsOutputDir, componentsPublicDir) => {
|
|
684
743
|
if (!node_fs.existsSync(componentsOutputDir)) {
|
|
685
744
|
return [];
|
|
@@ -1059,11 +1118,15 @@ const build = async ({
|
|
|
1059
1118
|
node_path.resolve(entryFile)
|
|
1060
1119
|
])
|
|
1061
1120
|
);
|
|
1121
|
+
const componentBuildPlugins = [
|
|
1122
|
+
defuss(),
|
|
1123
|
+
...await loadProjectTailwindVitePlugins(projectDir, debug)
|
|
1124
|
+
];
|
|
1062
1125
|
await vite.build({
|
|
1063
1126
|
root: node_path.resolve(tmpComponentsDir),
|
|
1064
1127
|
configFile: false,
|
|
1065
1128
|
publicDir: false,
|
|
1066
|
-
plugins:
|
|
1129
|
+
plugins: componentBuildPlugins,
|
|
1067
1130
|
build: {
|
|
1068
1131
|
lib: {
|
|
1069
1132
|
entry: componentEntries,
|
|
@@ -1081,6 +1144,7 @@ const build = async ({
|
|
|
1081
1144
|
}
|
|
1082
1145
|
}
|
|
1083
1146
|
});
|
|
1147
|
+
await normalizeComponentStylesheets(tmpComponentOutDir);
|
|
1084
1148
|
timeEndDebug("[build] vite-components");
|
|
1085
1149
|
}
|
|
1086
1150
|
if (isFullBuild || changeKind === "page" || changeKind === "endpoint") {
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import glob from 'fast-glob';
|
|
2
2
|
import { existsSync, statSync, mkdirSync, rmSync, readdirSync, symlinkSync } from 'node:fs';
|
|
3
3
|
import { writeFile, readFile, cp, stat } from 'node:fs/promises';
|
|
4
|
-
import { join, resolve, relative, sep, extname, dirname } from 'node:path';
|
|
4
|
+
import { join, resolve, relative, sep, extname, basename, dirname } from 'node:path';
|
|
5
5
|
import { getBrowserGlobals, getDocument, renderSync, renderToString } from 'defuss/server';
|
|
6
6
|
import { createHash } from 'node:crypto';
|
|
7
7
|
import mdx from '@mdx-js/rollup';
|
|
8
8
|
import { createServer, build as build$1 } from 'vite';
|
|
9
9
|
import defuss from 'defuss-vite';
|
|
10
|
-
import {
|
|
10
|
+
import { createRequire } from 'node:module';
|
|
11
|
+
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
11
12
|
import { tmpdir } from 'node:os';
|
|
12
13
|
import esbuild from 'esbuild';
|
|
13
14
|
import rehypeKatex from 'rehype-katex';
|
|
@@ -75,6 +76,13 @@ const toStableHydrateId = (seed) => {
|
|
|
75
76
|
const digest = createHash("sha1").update(seed).digest("hex").slice(0, 12);
|
|
76
77
|
return `dh_${digest}`;
|
|
77
78
|
};
|
|
79
|
+
const toPascalCase = (value) => value.split(/[^A-Za-z0-9]+/).filter(Boolean).map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1)).join("");
|
|
80
|
+
const toComponentExportName = (componentFilePath) => {
|
|
81
|
+
const extension = extname(componentFilePath);
|
|
82
|
+
const fileStem = basename(componentFilePath, extension);
|
|
83
|
+
const exportBaseName = fileStem.toLowerCase() === "index" ? basename(dirname(componentFilePath)) : fileStem;
|
|
84
|
+
return toPascalCase(exportBaseName);
|
|
85
|
+
};
|
|
78
86
|
function applyAutoHydrate(vdom, componentsDir, componentsPublicPrefix, relativeOutputHtmlFilePath) {
|
|
79
87
|
const componentsRoot = resolve(componentsDir);
|
|
80
88
|
let hydrateIndex = 0;
|
|
@@ -90,6 +98,9 @@ function applyAutoHydrate(vdom, componentsDir, componentsPublicPrefix, relativeO
|
|
|
90
98
|
if (vnode.sourceInfo && typeof vnode.sourceInfo === "object" && typeof vnode.sourceInfo.fileName === "string" && vnode.sourceInfo.fileName.includes(componentsDir) && vnode.type !== "script" && vnode.type !== "head" && vnode.type !== "link" && vnode.type !== "meta" && vnode.type !== "title") {
|
|
91
99
|
const sourceFile = resolve(vnode.sourceInfo.fileName);
|
|
92
100
|
const relativeComponentPath = relative(componentsRoot, sourceFile);
|
|
101
|
+
const componentExportName = toComponentExportName(
|
|
102
|
+
relativeComponentPath
|
|
103
|
+
);
|
|
93
104
|
if (relativeComponentPath.startsWith("..") || relativeComponentPath.length === 0) {
|
|
94
105
|
throw new Error(
|
|
95
106
|
`[auto-hydrate] Component source file is outside the components directory: ${sourceFile}`
|
|
@@ -123,6 +134,7 @@ function applyAutoHydrate(vdom, componentsDir, componentsPublicPrefix, relativeO
|
|
|
123
134
|
attributes: {
|
|
124
135
|
"data-hydrate-id": id,
|
|
125
136
|
"data-hydrate": "true",
|
|
137
|
+
"data-hydrate-export": componentExportName,
|
|
126
138
|
"data-hydrate-src": clientSrcFile,
|
|
127
139
|
"data-hydrate-props": JSON.stringify(componentProps),
|
|
128
140
|
"data-hydrate-runtime": `/${componentsPublicPrefix}/runtime.js`
|
|
@@ -666,6 +678,30 @@ const resolveLocalHelperFile = (sourceRelativePath, builtRelativePath) => {
|
|
|
666
678
|
}
|
|
667
679
|
return resolve(__dirname$1, builtRelativePath);
|
|
668
680
|
};
|
|
681
|
+
const loadProjectTailwindVitePlugins = async (projectDir, debug) => {
|
|
682
|
+
const requireFromBuild = createRequire(import.meta.url);
|
|
683
|
+
try {
|
|
684
|
+
const resolvedPluginPath = requireFromBuild.resolve("@tailwindcss/vite", {
|
|
685
|
+
paths: [projectDir]
|
|
686
|
+
});
|
|
687
|
+
const tailwindModule = await import(pathToFileURL(resolvedPluginPath).href);
|
|
688
|
+
if (typeof tailwindModule.default !== "function") {
|
|
689
|
+
return [];
|
|
690
|
+
}
|
|
691
|
+
const plugin = tailwindModule.default();
|
|
692
|
+
if (!plugin) {
|
|
693
|
+
return [];
|
|
694
|
+
}
|
|
695
|
+
return Array.isArray(plugin) ? plugin : [plugin];
|
|
696
|
+
} catch (error) {
|
|
697
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
698
|
+
const isMissingPlugin = message.includes("@tailwindcss/vite");
|
|
699
|
+
if (!isMissingPlugin && debug) {
|
|
700
|
+
console.warn("[build] Failed to load @tailwindcss/vite from project:", error);
|
|
701
|
+
}
|
|
702
|
+
return [];
|
|
703
|
+
}
|
|
704
|
+
};
|
|
669
705
|
const injectStylesheetLinks$1 = (html, hrefs) => {
|
|
670
706
|
const missingHrefs = hrefs.filter((href) => !html.includes(`href="${href}"`));
|
|
671
707
|
if (missingHrefs.length === 0) {
|
|
@@ -677,6 +713,29 @@ const injectStylesheetLinks$1 = (html, hrefs) => {
|
|
|
677
713
|
}
|
|
678
714
|
return `${linkTags}${html}`;
|
|
679
715
|
};
|
|
716
|
+
const normalizeComponentStylesheet = (css) => {
|
|
717
|
+
const compiledTailwindBanner = "/*! tailwindcss";
|
|
718
|
+
const compiledTailwindIndex = css.indexOf(compiledTailwindBanner);
|
|
719
|
+
if (compiledTailwindIndex <= 0) {
|
|
720
|
+
return css;
|
|
721
|
+
}
|
|
722
|
+
const prefix = css.slice(0, compiledTailwindIndex).trimStart();
|
|
723
|
+
const hasRawTailwindPrelude = prefix.startsWith("@layer theme, base, components, utilities;") && prefix.includes("@theme default");
|
|
724
|
+
if (!hasRawTailwindPrelude) {
|
|
725
|
+
return css;
|
|
726
|
+
}
|
|
727
|
+
return css.slice(compiledTailwindIndex);
|
|
728
|
+
};
|
|
729
|
+
const normalizeComponentStylesheets = async (componentsOutputDir) => {
|
|
730
|
+
const cssFiles = await glob.async(join(componentsOutputDir, "**/*.css"));
|
|
731
|
+
for (const cssFile of cssFiles) {
|
|
732
|
+
const currentCss = await readFile(cssFile, "utf-8");
|
|
733
|
+
const normalizedCss = normalizeComponentStylesheet(currentCss);
|
|
734
|
+
if (normalizedCss !== currentCss) {
|
|
735
|
+
await writeFile(cssFile, normalizedCss);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
};
|
|
680
739
|
const getComponentStylesheetHrefs$1 = async (componentsOutputDir, componentsPublicDir) => {
|
|
681
740
|
if (!existsSync(componentsOutputDir)) {
|
|
682
741
|
return [];
|
|
@@ -1056,11 +1115,15 @@ const build = async ({
|
|
|
1056
1115
|
resolve(entryFile)
|
|
1057
1116
|
])
|
|
1058
1117
|
);
|
|
1118
|
+
const componentBuildPlugins = [
|
|
1119
|
+
defuss(),
|
|
1120
|
+
...await loadProjectTailwindVitePlugins(projectDir, debug)
|
|
1121
|
+
];
|
|
1059
1122
|
await build$1({
|
|
1060
1123
|
root: resolve(tmpComponentsDir),
|
|
1061
1124
|
configFile: false,
|
|
1062
1125
|
publicDir: false,
|
|
1063
|
-
plugins:
|
|
1126
|
+
plugins: componentBuildPlugins,
|
|
1064
1127
|
build: {
|
|
1065
1128
|
lib: {
|
|
1066
1129
|
entry: componentEntries,
|
|
@@ -1078,6 +1141,7 @@ const build = async ({
|
|
|
1078
1141
|
}
|
|
1079
1142
|
}
|
|
1080
1143
|
});
|
|
1144
|
+
await normalizeComponentStylesheets(tmpComponentOutDir);
|
|
1081
1145
|
timeEndDebug("[build] vite-components");
|
|
1082
1146
|
}
|
|
1083
1147
|
if (isFullBuild || changeKind === "page" || changeKind === "endpoint") {
|
package/dist/vite.cjs
CHANGED
|
@@ -5,11 +5,12 @@ require('node:fs');
|
|
|
5
5
|
require('node:fs/promises');
|
|
6
6
|
require('node:path');
|
|
7
7
|
require('defuss/server');
|
|
8
|
-
var vite = require('./vite-
|
|
8
|
+
var vite = require('./vite-CkpguLfK.cjs');
|
|
9
9
|
require('node:crypto');
|
|
10
10
|
require('@mdx-js/rollup');
|
|
11
11
|
require('vite');
|
|
12
12
|
require('defuss-vite');
|
|
13
|
+
require('node:module');
|
|
13
14
|
require('node:url');
|
|
14
15
|
require('node:os');
|
|
15
16
|
require('esbuild');
|
package/dist/vite.mjs
CHANGED
|
@@ -3,11 +3,12 @@ import 'node:fs';
|
|
|
3
3
|
import 'node:fs/promises';
|
|
4
4
|
import 'node:path';
|
|
5
5
|
import 'defuss/server';
|
|
6
|
-
export { f as defussSsg } from './vite-
|
|
6
|
+
export { f as defussSsg } from './vite-DdJcWQGP.mjs';
|
|
7
7
|
import 'node:crypto';
|
|
8
8
|
import '@mdx-js/rollup';
|
|
9
9
|
import 'vite';
|
|
10
10
|
import 'defuss-vite';
|
|
11
|
+
import 'node:module';
|
|
11
12
|
import 'node:url';
|
|
12
13
|
import 'node:os';
|
|
13
14
|
import 'esbuild';
|