@tanstack/start-plugin-core 1.121.0-alpha.2 → 1.121.0-alpha.20
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/constants.cjs +4 -0
- package/dist/cjs/constants.cjs.map +1 -1
- package/dist/cjs/constants.d.cts +2 -0
- package/dist/cjs/{extractHtmlScripts.cjs → dev-server-plugin/extract-html-scripts.cjs} +1 -1
- package/dist/cjs/dev-server-plugin/extract-html-scripts.cjs.map +1 -0
- package/dist/cjs/{nitro/dev-server-plugin.cjs → dev-server-plugin/plugin.cjs} +2 -2
- package/dist/cjs/dev-server-plugin/plugin.cjs.map +1 -0
- package/dist/cjs/index.cjs +2 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -0
- package/dist/cjs/load-env-plugin/plugin.cjs +34 -0
- package/dist/cjs/load-env-plugin/plugin.cjs.map +1 -0
- package/dist/cjs/load-env-plugin/plugin.d.cts +3 -0
- package/dist/cjs/nitro-plugin/build-sitemap.cjs +138 -0
- package/dist/cjs/nitro-plugin/build-sitemap.cjs.map +1 -0
- package/dist/cjs/nitro-plugin/build-sitemap.d.cts +31 -0
- package/dist/cjs/{nitro/nitro-plugin.cjs → nitro-plugin/plugin.cjs} +77 -54
- package/dist/cjs/nitro-plugin/plugin.cjs.map +1 -0
- package/dist/cjs/{prerender.cjs → nitro-plugin/prerender.cjs} +12 -17
- package/dist/cjs/nitro-plugin/prerender.cjs.map +1 -0
- package/dist/cjs/{prerender.d.cts → nitro-plugin/prerender.d.cts} +1 -1
- package/dist/cjs/nitro-plugin/queue.cjs.map +1 -0
- package/dist/cjs/plugin.cjs +38 -27
- package/dist/cjs/plugin.cjs.map +1 -1
- package/dist/cjs/plugin.d.cts +25 -3064
- package/dist/cjs/resolve-virtual-entries-plugin/plugin.cjs +66 -0
- package/dist/cjs/resolve-virtual-entries-plugin/plugin.cjs.map +1 -0
- package/dist/cjs/resolve-virtual-entries-plugin/plugin.d.cts +3 -0
- package/dist/cjs/schema.cjs +6 -4
- package/dist/cjs/schema.cjs.map +1 -1
- package/dist/cjs/schema.d.cts +530 -1656
- package/dist/cjs/start-compiler-plugin.cjs +2 -2
- package/dist/cjs/start-compiler-plugin.cjs.map +1 -1
- package/dist/cjs/start-compiler-plugin.d.cts +1 -1
- package/dist/cjs/{routesManifestPlugin.cjs → start-routes-manifest-plugin/plugin.cjs} +86 -44
- package/dist/cjs/start-routes-manifest-plugin/plugin.cjs.map +1 -0
- package/dist/cjs/start-routes-manifest-plugin/plugin.d.cts +3 -0
- package/dist/cjs/start-server-routes-plugin/plugin.cjs +2 -1
- package/dist/cjs/start-server-routes-plugin/plugin.cjs.map +1 -1
- package/dist/cjs/utils.cjs +18 -0
- package/dist/cjs/utils.cjs.map +1 -0
- package/dist/cjs/utils.d.cts +8 -0
- package/dist/esm/constants.d.ts +2 -0
- package/dist/esm/constants.js +4 -0
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/{extractHtmlScripts.js → dev-server-plugin/extract-html-scripts.js} +1 -1
- package/dist/esm/dev-server-plugin/extract-html-scripts.js.map +1 -0
- package/dist/esm/{nitro/dev-server-plugin.js → dev-server-plugin/plugin.js} +2 -2
- package/dist/esm/dev-server-plugin/plugin.js.map +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +3 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/load-env-plugin/plugin.d.ts +3 -0
- package/dist/esm/load-env-plugin/plugin.js +17 -0
- package/dist/esm/load-env-plugin/plugin.js.map +1 -0
- package/dist/esm/nitro-plugin/build-sitemap.d.ts +31 -0
- package/dist/esm/nitro-plugin/build-sitemap.js +138 -0
- package/dist/esm/nitro-plugin/build-sitemap.js.map +1 -0
- package/dist/esm/nitro-plugin/plugin.js +181 -0
- package/dist/esm/nitro-plugin/plugin.js.map +1 -0
- package/dist/esm/{prerender.d.ts → nitro-plugin/prerender.d.ts} +1 -1
- package/dist/esm/{prerender.js → nitro-plugin/prerender.js} +12 -17
- package/dist/esm/nitro-plugin/prerender.js.map +1 -0
- package/dist/esm/nitro-plugin/queue.js.map +1 -0
- package/dist/esm/plugin.d.ts +25 -3064
- package/dist/esm/plugin.js +39 -28
- package/dist/esm/plugin.js.map +1 -1
- package/dist/esm/resolve-virtual-entries-plugin/plugin.d.ts +3 -0
- package/dist/esm/resolve-virtual-entries-plugin/plugin.js +49 -0
- package/dist/esm/resolve-virtual-entries-plugin/plugin.js.map +1 -0
- package/dist/esm/schema.d.ts +530 -1656
- package/dist/esm/schema.js +6 -4
- package/dist/esm/schema.js.map +1 -1
- package/dist/esm/start-compiler-plugin.d.ts +1 -1
- package/dist/esm/start-compiler-plugin.js +2 -2
- package/dist/esm/start-compiler-plugin.js.map +1 -1
- package/dist/esm/start-routes-manifest-plugin/plugin.d.ts +3 -0
- package/dist/esm/{routesManifestPlugin.js → start-routes-manifest-plugin/plugin.js} +87 -45
- package/dist/esm/start-routes-manifest-plugin/plugin.js.map +1 -0
- package/dist/esm/start-server-routes-plugin/plugin.js +2 -1
- package/dist/esm/start-server-routes-plugin/plugin.js.map +1 -1
- package/dist/esm/utils.d.ts +8 -0
- package/dist/esm/utils.js +18 -0
- package/dist/esm/utils.js.map +1 -0
- package/package.json +6 -6
- package/src/constants.ts +3 -0
- package/src/{nitro/dev-server-plugin.ts → dev-server-plugin/plugin.ts} +11 -1
- package/src/index.ts +1 -0
- package/src/load-env-plugin/plugin.ts +17 -0
- package/src/nitro-plugin/build-sitemap.ts +213 -0
- package/src/nitro-plugin/plugin.ts +244 -0
- package/src/{prerender.ts → nitro-plugin/prerender.ts} +14 -21
- package/src/plugin.ts +57 -29
- package/src/resolve-virtual-entries-plugin/plugin.ts +63 -0
- package/src/schema.ts +11 -9
- package/src/start-compiler-plugin.ts +1 -1
- package/src/{routesManifestPlugin.ts → start-routes-manifest-plugin/plugin.ts} +111 -45
- package/src/start-server-routes-plugin/plugin.ts +2 -1
- package/src/utils.ts +14 -0
- package/dist/cjs/extractHtmlScripts.cjs.map +0 -1
- package/dist/cjs/nitro/build-nitro.cjs +0 -18
- package/dist/cjs/nitro/build-nitro.cjs.map +0 -1
- package/dist/cjs/nitro/build-nitro.d.cts +0 -2
- package/dist/cjs/nitro/build-sitemap.d.cts +0 -9
- package/dist/cjs/nitro/dev-server-plugin.cjs.map +0 -1
- package/dist/cjs/nitro/nitro-plugin.cjs.map +0 -1
- package/dist/cjs/prerender.cjs.map +0 -1
- package/dist/cjs/queue.cjs.map +0 -1
- package/dist/cjs/routesManifestPlugin.cjs.map +0 -1
- package/dist/cjs/routesManifestPlugin.d.cts +0 -3
- package/dist/esm/extractHtmlScripts.js.map +0 -1
- package/dist/esm/nitro/build-nitro.d.ts +0 -2
- package/dist/esm/nitro/build-nitro.js +0 -18
- package/dist/esm/nitro/build-nitro.js.map +0 -1
- package/dist/esm/nitro/build-sitemap.d.ts +0 -9
- package/dist/esm/nitro/dev-server-plugin.js.map +0 -1
- package/dist/esm/nitro/nitro-plugin.js +0 -158
- package/dist/esm/nitro/nitro-plugin.js.map +0 -1
- package/dist/esm/prerender.js.map +0 -1
- package/dist/esm/queue.js.map +0 -1
- package/dist/esm/routesManifestPlugin.d.ts +0 -3
- package/dist/esm/routesManifestPlugin.js.map +0 -1
- package/src/nitro/build-nitro.ts +0 -27
- package/src/nitro/build-sitemap.ts +0 -79
- package/src/nitro/nitro-plugin.ts +0 -199
- /package/dist/cjs/{extractHtmlScripts.d.cts → dev-server-plugin/extract-html-scripts.d.cts} +0 -0
- /package/dist/cjs/{nitro/dev-server-plugin.d.cts → dev-server-plugin/plugin.d.cts} +0 -0
- /package/dist/cjs/{nitro/nitro-plugin.d.cts → nitro-plugin/plugin.d.cts} +0 -0
- /package/dist/cjs/{queue.cjs → nitro-plugin/queue.cjs} +0 -0
- /package/dist/cjs/{queue.d.cts → nitro-plugin/queue.d.cts} +0 -0
- /package/dist/esm/{extractHtmlScripts.d.ts → dev-server-plugin/extract-html-scripts.d.ts} +0 -0
- /package/dist/esm/{nitro/dev-server-plugin.d.ts → dev-server-plugin/plugin.d.ts} +0 -0
- /package/dist/esm/{nitro/nitro-plugin.d.ts → nitro-plugin/plugin.d.ts} +0 -0
- /package/dist/esm/{queue.d.ts → nitro-plugin/queue.d.ts} +0 -0
- /package/dist/esm/{queue.js → nitro-plugin/queue.js} +0 -0
- /package/src/{extractHtmlScripts.ts → dev-server-plugin/extract-html-scripts.ts} +0 -0
- /package/src/{queue.ts → nitro-plugin/queue.ts} +0 -0
package/dist/cjs/constants.cjs
CHANGED
|
@@ -6,5 +6,9 @@ const VITE_ENVIRONMENT_NAMES = {
|
|
|
6
6
|
server: "ssr",
|
|
7
7
|
client: "client"
|
|
8
8
|
};
|
|
9
|
+
const CLIENT_DIST_DIR = ".tanstack-start/build/client-dist";
|
|
10
|
+
const SSR_ENTRY_FILE = "ssr.mjs";
|
|
11
|
+
exports.CLIENT_DIST_DIR = CLIENT_DIST_DIR;
|
|
12
|
+
exports.SSR_ENTRY_FILE = SSR_ENTRY_FILE;
|
|
9
13
|
exports.VITE_ENVIRONMENT_NAMES = VITE_ENVIRONMENT_NAMES;
|
|
10
14
|
//# sourceMappingURL=constants.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.cjs","sources":["../../src/constants.ts"],"sourcesContent":["export const VITE_ENVIRONMENT_NAMES = {\n // 'ssr' is chosen as the name for the server environment to ensure backwards compatibility\n // with vite plugins that are not compatible with the new vite environment API (e.g. tailwindcss)\n server: 'ssr',\n client: 'client',\n} as const\n"],"names":[],"mappings":";;AAAO,MAAM,yBAAyB;AAAA;AAAA;AAAA,EAGpC,QAAQ;AAAA,EACR,QAAQ;AACV
|
|
1
|
+
{"version":3,"file":"constants.cjs","sources":["../../src/constants.ts"],"sourcesContent":["export const VITE_ENVIRONMENT_NAMES = {\n // 'ssr' is chosen as the name for the server environment to ensure backwards compatibility\n // with vite plugins that are not compatible with the new vite environment API (e.g. tailwindcss)\n server: 'ssr',\n client: 'client',\n} as const\n\nexport const CLIENT_DIST_DIR = '.tanstack-start/build/client-dist'\nexport const SSR_ENTRY_FILE = 'ssr.mjs'\n"],"names":[],"mappings":";;AAAO,MAAM,yBAAyB;AAAA;AAAA;AAAA,EAGpC,QAAQ;AAAA,EACR,QAAQ;AACV;AAEO,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;;;;"}
|
package/dist/cjs/constants.d.cts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-html-scripts.cjs","sources":["../../../src/dev-server-plugin/extract-html-scripts.ts"],"sourcesContent":["import * as cheerio from 'cheerio'\n\nexport function extractHtmlScripts(\n html: string,\n): Array<{ content?: string; src?: string }> {\n const $ = cheerio.load(html)\n const scripts: Array<{ content?: string; src?: string }> = []\n\n $('script').each((_, element) => {\n const src = $(element).attr('src')\n const content = $(element).html() ?? undefined\n scripts.push({\n src,\n content,\n })\n })\n\n return scripts\n}\n"],"names":["cheerio"],"mappings":";;;;;;;;;;;;;;;;;;;;AAEO,SAAS,mBACd,MAC2C;AACrC,QAAA,IAAIA,mBAAQ,KAAK,IAAI;AAC3B,QAAM,UAAqD,CAAC;AAE5D,IAAE,QAAQ,EAAE,KAAK,CAAC,GAAG,YAAY;AAC/B,UAAM,MAAM,EAAE,OAAO,EAAE,KAAK,KAAK;AACjC,UAAM,UAAU,EAAE,OAAO,EAAE,KAAU,KAAA;AACrC,YAAQ,KAAK;AAAA,MACX;AAAA,MACA;AAAA,IAAA,CACD;AAAA,EAAA,CACF;AAEM,SAAA;AACT;;"}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const h3 = require("h3");
|
|
4
4
|
const vite = require("vite");
|
|
5
|
-
const extractHtmlScripts = require("../extractHtmlScripts.cjs");
|
|
6
5
|
const constants = require("../constants.cjs");
|
|
6
|
+
const extractHtmlScripts = require("./extract-html-scripts.cjs");
|
|
7
7
|
function devServerPlugin() {
|
|
8
8
|
let isTest = false;
|
|
9
9
|
return {
|
|
@@ -133,4 +133,4 @@ function prepareError(req, error) {
|
|
|
133
133
|
};
|
|
134
134
|
}
|
|
135
135
|
exports.devServerPlugin = devServerPlugin;
|
|
136
|
-
//# sourceMappingURL=
|
|
136
|
+
//# sourceMappingURL=plugin.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.cjs","sources":["../../../src/dev-server-plugin/plugin.ts"],"sourcesContent":["import { createEvent, getHeader, sendWebResponse } from 'h3'\nimport { isRunnableDevEnvironment } from 'vite'\nimport { VITE_ENVIRONMENT_NAMES } from '../constants'\nimport { extractHtmlScripts } from './extract-html-scripts'\nimport type { Connect, DevEnvironment, Plugin, ViteDevServer } from 'vite'\n\ndeclare global {\n // eslint-disable-next-line no-var\n var TSS_INJECTED_HEAD_SCRIPTS: string | undefined\n}\n\nexport function devServerPlugin(): Plugin {\n // let config: UserConfig\n let isTest = false\n\n return {\n name: 'start-dev-ssr-plugin',\n config(userConfig, { mode }) {\n // config = userConfig\n isTest = isTest ? isTest : mode === 'test'\n },\n configureServer(viteDevServer) {\n if (isTest) {\n return\n }\n\n ;(globalThis as any).viteDevServer = viteDevServer\n\n return () => {\n remove_html_middlewares(viteDevServer.middlewares)\n let cachedScripts: string | undefined\n\n viteDevServer.middlewares.use(async (req, res) => {\n // Create an H3Event to have it passed into the server entry\n // i.e: event => defineEventHandler(event)\n const event = createEvent(req, res)\n\n const serverEnv = viteDevServer.environments[\n VITE_ENVIRONMENT_NAMES.server\n ] as DevEnvironment | undefined\n\n try {\n if (!serverEnv) {\n throw new Error(\n `Server environment ${VITE_ENVIRONMENT_NAMES.server} not found`,\n )\n }\n\n if (!isRunnableDevEnvironment(serverEnv)) {\n throw new Error(\n `Expected server environment ${VITE_ENVIRONMENT_NAMES.server} to be a RunnableDevEnvironment. This can be caused by multiple vite versions being installed in the project.`,\n )\n }\n\n // Extract the scripts that Vite plugins would inject into the initial HTML\n if (cachedScripts === undefined) {\n const templateHtml = `<html><head></head><body></body></html>`\n const transformedHtml = await viteDevServer.transformIndexHtml(\n req.url || '/',\n templateHtml,\n )\n const scripts = extractHtmlScripts(transformedHtml)\n globalThis.TSS_INJECTED_HEAD_SCRIPTS = scripts\n .map((script) => script.content ?? '')\n .join(';')\n }\n\n // Import and resolve the request by running the server entry point\n // i.e export default defineEventHandler((event) => { ... })\n const serverEntry = await serverEnv.runner.import(\n '/~start/server-entry',\n )\n const response = await serverEntry['default'](event)\n\n return sendWebResponse(event, response)\n } catch (e) {\n console.error(e)\n viteDevServer.ssrFixStacktrace(e as Error)\n\n if (\n getHeader(event, 'content-type')?.includes('application/json')\n ) {\n return sendWebResponse(\n event,\n new Response(\n JSON.stringify(\n {\n status: 500,\n error: 'Internal Server Error',\n message:\n 'An unexpected error occurred. Please try again later.',\n timestamp: new Date().toISOString(),\n },\n null,\n 2,\n ),\n {\n status: 500,\n headers: {\n 'Content-Type': 'application/json',\n },\n },\n ),\n )\n }\n\n return sendWebResponse(\n event,\n new Response(\n `\n <!DOCTYPE html>\n <html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\" />\n <title>Error</title>\n <script type=\"module\">\n import { ErrorOverlay } from '/@vite/client'\n document.body.appendChild(new ErrorOverlay(${JSON.stringify(\n prepareError(req, e),\n ).replace(/</g, '\\\\u003c')}))\n </script>\n </head>\n <body>\n </body>\n </html>\n `,\n {\n status: 500,\n headers: {\n 'Content-Type': 'text/html',\n },\n },\n ),\n )\n }\n })\n }\n },\n }\n}\n\n/**\n * Removes Vite internal middleware\n *\n * @param server\n */\nfunction remove_html_middlewares(server: ViteDevServer['middlewares']) {\n const html_middlewares = [\n 'viteIndexHtmlMiddleware',\n 'vite404Middleware',\n 'viteSpaFallbackMiddleware',\n ]\n for (let i = server.stack.length - 1; i > 0; i--) {\n if (\n html_middlewares.includes(\n // @ts-expect-error\n server.stack[i].handle.name,\n )\n ) {\n server.stack.splice(i, 1)\n }\n }\n}\n\n/**\n * Formats error for SSR message in error overlay\n * @param req\n * @param error\n * @returns\n */\nfunction prepareError(req: Connect.IncomingMessage, error: unknown) {\n const e = error as Error\n return {\n message: `An error occured while server rendering ${req.url}:\\n\\n\\t${\n typeof e === 'string' ? e : e.message\n } `,\n stack: typeof e === 'string' ? '' : e.stack,\n }\n}\n"],"names":["createEvent","VITE_ENVIRONMENT_NAMES","isRunnableDevEnvironment","extractHtmlScripts","sendWebResponse","getHeader"],"mappings":";;;;;;AAWO,SAAS,kBAA0B;AAExC,MAAI,SAAS;AAEN,SAAA;AAAA,IACL,MAAM;AAAA,IACN,OAAO,YAAY,EAAE,QAAQ;AAElB,eAAA,SAAS,SAAS,SAAS;AAAA,IACtC;AAAA,IACA,gBAAgB,eAAe;AAC7B,UAAI,QAAQ;AACV;AAAA,MAAA;AAGA,iBAAmB,gBAAgB;AAErC,aAAO,MAAM;AACX,gCAAwB,cAAc,WAAW;AAC7C,YAAA;AAEJ,sBAAc,YAAY,IAAI,OAAO,KAAK,QAAQ;;AAG1C,gBAAA,QAAQA,GAAAA,YAAY,KAAK,GAAG;AAElC,gBAAM,YAAY,cAAc,aAC9BC,UAAAA,uBAAuB,MACzB;AAEI,cAAA;AACF,gBAAI,CAAC,WAAW;AACd,oBAAM,IAAI;AAAA,gBACR,sBAAsBA,iCAAuB,MAAM;AAAA,cACrD;AAAA,YAAA;AAGE,gBAAA,CAACC,KAAAA,yBAAyB,SAAS,GAAG;AACxC,oBAAM,IAAI;AAAA,gBACR,+BAA+BD,iCAAuB,MAAM;AAAA,cAC9D;AAAA,YAAA;AAIF,gBAAI,kBAAkB,QAAW;AAC/B,oBAAM,eAAe;AACf,oBAAA,kBAAkB,MAAM,cAAc;AAAA,gBAC1C,IAAI,OAAO;AAAA,gBACX;AAAA,cACF;AACM,oBAAA,UAAUE,sCAAmB,eAAe;AACvC,yBAAA,4BAA4B,QACpC,IAAI,CAAC,WAAW,OAAO,WAAW,EAAE,EACpC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,GAAG,IAAI,GAAG,KAAK;AAChD,QACE,iBAAiB;AAAA;AAAA,MAEf,OAAO,MAAM,CAAC,EAAE,OAAO;AAAA,IAAA,GAEzB;AACO,aAAA,MAAM,OAAO,GAAG,CAAC;AAAA,IAAA;AAAA,EAC1B;AAEJ;AAQA,SAAS,aAAa,KAA8B,OAAgB;AAClE,QAAM,IAAI;AACH,SAAA;AAAA,IACL,SAAS,2CAA2C,IAAI,GAAG;AAAA;AAAA,GACzD,OAAO,MAAM,WAAW,IAAI,EAAE,OAChC;AAAA,IACA,OAAO,OAAO,MAAM,WAAW,KAAK,EAAE;AAAA,EACxC;AACF;;"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const schema = require("./schema.cjs");
|
|
4
4
|
const plugin = require("./plugin.cjs");
|
|
5
|
+
const utils = require("./utils.cjs");
|
|
5
6
|
exports.createTanStackConfig = schema.createTanStackConfig;
|
|
6
7
|
exports.createTanStackStartOptionsSchema = schema.createTanStackStartOptionsSchema;
|
|
7
8
|
exports.pageSchema = schema.pageSchema;
|
|
8
9
|
exports.TanStackStartVitePluginCore = plugin.TanStackStartVitePluginCore;
|
|
10
|
+
exports.resolveViteId = utils.resolveViteId;
|
|
9
11
|
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const vite = require("vite");
|
|
4
|
+
function _interopNamespaceDefault(e) {
|
|
5
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
6
|
+
if (e) {
|
|
7
|
+
for (const k in e) {
|
|
8
|
+
if (k !== "default") {
|
|
9
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
10
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: () => e[k]
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
n.default = e;
|
|
18
|
+
return Object.freeze(n);
|
|
19
|
+
}
|
|
20
|
+
const vite__namespace = /* @__PURE__ */ _interopNamespaceDefault(vite);
|
|
21
|
+
function loadEnvPlugin(startOpts) {
|
|
22
|
+
return {
|
|
23
|
+
name: "tanstack-vite-plugin-nitro-load-env",
|
|
24
|
+
enforce: "pre",
|
|
25
|
+
config(userConfig, envConfig) {
|
|
26
|
+
Object.assign(
|
|
27
|
+
process.env,
|
|
28
|
+
vite__namespace.loadEnv(envConfig.mode, userConfig.root ?? startOpts.root, "")
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
exports.loadEnvPlugin = loadEnvPlugin;
|
|
34
|
+
//# sourceMappingURL=plugin.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.cjs","sources":["../../../src/load-env-plugin/plugin.ts"],"sourcesContent":["import * as vite from 'vite'\nimport type { TanStackStartOutputConfig } from '../plugin'\n\nexport function loadEnvPlugin(\n startOpts: TanStackStartOutputConfig,\n): vite.Plugin {\n return {\n name: 'tanstack-vite-plugin-nitro-load-env',\n enforce: 'pre',\n config(userConfig, envConfig) {\n Object.assign(\n process.env,\n vite.loadEnv(envConfig.mode, userConfig.root ?? startOpts.root, ''),\n )\n },\n }\n}\n"],"names":["vite"],"mappings":";;;;;;;;;;;;;;;;;;;;AAGO,SAAS,cACd,WACa;AACN,SAAA;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT,OAAO,YAAY,WAAW;AACrB,aAAA;AAAA,QACL,QAAQ;AAAA,QACRA,gBAAK,QAAQ,UAAU,MAAM,WAAW,QAAQ,UAAU,MAAM,EAAE;AAAA,MACpE;AAAA,IAAA;AAAA,EAEJ;AACF;;"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const fs = require("node:fs");
|
|
4
|
+
const path = require("node:path");
|
|
5
|
+
const xmlbuilder2 = require("xmlbuilder2");
|
|
6
|
+
const utils = require("../utils.cjs");
|
|
7
|
+
function buildSitemapJson(pages, host) {
|
|
8
|
+
const slash = checkSlash(host);
|
|
9
|
+
const urls = pages.filter((page) => {
|
|
10
|
+
var _a;
|
|
11
|
+
return ((_a = page.sitemap) == null ? void 0 : _a.exclude) !== true;
|
|
12
|
+
}).map((page) => {
|
|
13
|
+
var _a, _b, _c, _d, _e, _f;
|
|
14
|
+
return {
|
|
15
|
+
loc: `${host}${slash}${page.path.replace(/^\/+/g, "")}`,
|
|
16
|
+
lastmod: ((_a = page.sitemap) == null ? void 0 : _a.lastmod) ? new Date(page.sitemap.lastmod).toISOString().split("T")[0] : (/* @__PURE__ */ new Date()).toISOString().split("T")[0],
|
|
17
|
+
priority: (_b = page.sitemap) == null ? void 0 : _b.priority,
|
|
18
|
+
changefreq: (_c = page.sitemap) == null ? void 0 : _c.changefreq,
|
|
19
|
+
alternateRefs: (_d = page.sitemap) == null ? void 0 : _d.alternateRefs,
|
|
20
|
+
images: (_e = page.sitemap) == null ? void 0 : _e.images,
|
|
21
|
+
news: (_f = page.sitemap) == null ? void 0 : _f.news
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
return { urls };
|
|
25
|
+
}
|
|
26
|
+
function jsonToXml(sitemapData) {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
const sitemap = createXml("urlset");
|
|
29
|
+
for (const item of sitemapData.urls) {
|
|
30
|
+
const page = sitemap.ele("url");
|
|
31
|
+
page.ele("loc").txt(item.loc);
|
|
32
|
+
page.ele("lastmod").txt(item.lastmod);
|
|
33
|
+
if (item.priority !== void 0) {
|
|
34
|
+
page.ele("priority").txt(item.priority.toString());
|
|
35
|
+
}
|
|
36
|
+
if (item.changefreq) {
|
|
37
|
+
page.ele("changefreq").txt(item.changefreq);
|
|
38
|
+
}
|
|
39
|
+
if ((_a = item.alternateRefs) == null ? void 0 : _a.length) {
|
|
40
|
+
for (const ref of item.alternateRefs) {
|
|
41
|
+
const alternateRef = page.ele("xhtml:link");
|
|
42
|
+
alternateRef.att("rel", "alternate");
|
|
43
|
+
alternateRef.att("href", ref.href);
|
|
44
|
+
if (ref.hreflang) {
|
|
45
|
+
alternateRef.att("hreflang", ref.hreflang);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if ((_b = item.images) == null ? void 0 : _b.length) {
|
|
50
|
+
for (const image of item.images) {
|
|
51
|
+
const imageElement = page.ele("image:image");
|
|
52
|
+
imageElement.ele("image:loc").txt(image.loc);
|
|
53
|
+
if (image.title) {
|
|
54
|
+
imageElement.ele("image:title").txt(image.title);
|
|
55
|
+
}
|
|
56
|
+
if (image.caption) {
|
|
57
|
+
imageElement.ele("image:caption").txt(image.caption);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (item.news) {
|
|
62
|
+
const newsElement = page.ele("news:news");
|
|
63
|
+
const publication = newsElement.ele("news:publication");
|
|
64
|
+
publication.ele("news:name").txt(item.news.publication.name);
|
|
65
|
+
publication.ele("news:language").txt(item.news.publication.language);
|
|
66
|
+
newsElement.ele("news:publication_date").txt(new Date(item.news.publicationDate).toISOString().split("T")[0]);
|
|
67
|
+
newsElement.ele("news:title").txt(item.news.title);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return sitemap.end({ prettyPrint: true });
|
|
71
|
+
}
|
|
72
|
+
function buildSitemap({
|
|
73
|
+
options,
|
|
74
|
+
publicDir
|
|
75
|
+
}) {
|
|
76
|
+
const logger = utils.createLogger("sitemap");
|
|
77
|
+
let sitemapOptions = options.sitemap;
|
|
78
|
+
if (!sitemapOptions && options.pages.length) {
|
|
79
|
+
sitemapOptions = { enabled: true, outputPath: "sitemap.xml" };
|
|
80
|
+
}
|
|
81
|
+
if (!(sitemapOptions == null ? void 0 : sitemapOptions.enabled)) {
|
|
82
|
+
throw new Error("Sitemap is not enabled");
|
|
83
|
+
}
|
|
84
|
+
const { host, outputPath } = sitemapOptions;
|
|
85
|
+
if (!host) {
|
|
86
|
+
if (!options.sitemap) {
|
|
87
|
+
logger.info(
|
|
88
|
+
"Hint: Pages found, but no sitemap host has been set. To enable sitemap generation, set the `sitemap.host` option."
|
|
89
|
+
);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
throw new Error(
|
|
93
|
+
"Sitemap host is not set and required to build the sitemap."
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
if (!outputPath) {
|
|
97
|
+
throw new Error("Sitemap output path is not set");
|
|
98
|
+
}
|
|
99
|
+
const { pages } = options;
|
|
100
|
+
if (!pages.length) {
|
|
101
|
+
logger.info("No pages were found to build the sitemap. Skipping...");
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
logger.info("Building Sitemap...");
|
|
105
|
+
const sitemapData = buildSitemapJson(pages, host);
|
|
106
|
+
const xmlOutputPath = path.join(publicDir, outputPath);
|
|
107
|
+
const pagesOutputPath = path.join(publicDir, "pages.json");
|
|
108
|
+
try {
|
|
109
|
+
logger.info(`Writing sitemap XML at ${xmlOutputPath}`);
|
|
110
|
+
fs.writeFileSync(xmlOutputPath, jsonToXml(sitemapData));
|
|
111
|
+
logger.info(`Writing pages data at ${pagesOutputPath}`);
|
|
112
|
+
fs.writeFileSync(
|
|
113
|
+
pagesOutputPath,
|
|
114
|
+
JSON.stringify(
|
|
115
|
+
{
|
|
116
|
+
pages,
|
|
117
|
+
host,
|
|
118
|
+
lastBuilt: (/* @__PURE__ */ new Date()).toISOString()
|
|
119
|
+
},
|
|
120
|
+
null,
|
|
121
|
+
2
|
|
122
|
+
)
|
|
123
|
+
);
|
|
124
|
+
} catch (e) {
|
|
125
|
+
logger.error(`Unable to write sitemap files`, e);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function createXml(elementName) {
|
|
129
|
+
return xmlbuilder2.create({ version: "1.0", encoding: "UTF-8" }).ele(elementName, {
|
|
130
|
+
xmlns: "https://www.sitemaps.org/schemas/sitemap/0.9"
|
|
131
|
+
}).com(`This file was automatically generated by TanStack Start.`);
|
|
132
|
+
}
|
|
133
|
+
function checkSlash(host) {
|
|
134
|
+
const finalChar = host.slice(-1);
|
|
135
|
+
return finalChar === "/" ? "" : "/";
|
|
136
|
+
}
|
|
137
|
+
exports.buildSitemap = buildSitemap;
|
|
138
|
+
//# sourceMappingURL=build-sitemap.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-sitemap.cjs","sources":["../../../src/nitro-plugin/build-sitemap.ts"],"sourcesContent":["import { writeFileSync } from 'node:fs'\nimport path from 'node:path'\nimport { create } from 'xmlbuilder2'\nimport { createLogger } from '../utils'\nimport type { TanStackStartOutputConfig } from '../plugin'\nimport type { XMLBuilder } from 'xmlbuilder2/lib/interfaces'\n\nexport type SitemapUrl = {\n loc: string\n lastmod: string\n priority?: number\n changefreq?:\n | 'always'\n | 'hourly'\n | 'daily'\n | 'weekly'\n | 'monthly'\n | 'yearly'\n | 'never'\n alternateRefs?: Array<{\n href: string\n hreflang?: string\n }>\n images?: Array<{\n loc: string\n title?: string\n caption?: string\n }>\n news?: {\n publication: {\n name: string\n language: string\n }\n publicationDate: string | Date\n title: string\n }\n}\n\nexport type SitemapData = {\n urls: Array<SitemapUrl>\n}\n\nfunction buildSitemapJson(\n pages: TanStackStartOutputConfig['pages'],\n host: string,\n): SitemapData {\n const slash = checkSlash(host)\n\n const urls: Array<SitemapUrl> = pages\n .filter((page) => {\n return page.sitemap?.exclude !== true\n })\n .map((page) => ({\n loc: `${host}${slash}${page.path.replace(/^\\/+/g, '')}`,\n lastmod: page.sitemap?.lastmod\n ? new Date(page.sitemap.lastmod).toISOString().split('T')[0]!\n : new Date().toISOString().split('T')[0]!,\n priority: page.sitemap?.priority,\n changefreq: page.sitemap?.changefreq,\n alternateRefs: page.sitemap?.alternateRefs,\n images: page.sitemap?.images,\n news: page.sitemap?.news,\n }))\n\n return { urls }\n}\n\nfunction jsonToXml(sitemapData: SitemapData): string {\n const sitemap = createXml('urlset')\n\n for (const item of sitemapData.urls) {\n const page = sitemap.ele('url')\n page.ele('loc').txt(item.loc)\n page.ele('lastmod').txt(item.lastmod)\n\n if (item.priority !== undefined) {\n page.ele('priority').txt(item.priority.toString())\n }\n if (item.changefreq) {\n page.ele('changefreq').txt(item.changefreq)\n }\n\n // Add alternate references\n if (item.alternateRefs?.length) {\n for (const ref of item.alternateRefs) {\n const alternateRef = page.ele('xhtml:link')\n alternateRef.att('rel', 'alternate')\n alternateRef.att('href', ref.href)\n if (ref.hreflang) {\n alternateRef.att('hreflang', ref.hreflang)\n }\n }\n }\n\n // Add images\n if (item.images?.length) {\n for (const image of item.images) {\n const imageElement = page.ele('image:image')\n imageElement.ele('image:loc').txt(image.loc)\n if (image.title) {\n imageElement.ele('image:title').txt(image.title)\n }\n if (image.caption) {\n imageElement.ele('image:caption').txt(image.caption)\n }\n }\n }\n\n // Add news\n if (item.news) {\n const newsElement = page.ele('news:news')\n const publication = newsElement.ele('news:publication')\n publication.ele('news:name').txt(item.news.publication.name)\n publication.ele('news:language').txt(item.news.publication.language)\n newsElement\n .ele('news:publication_date')\n .txt(new Date(item.news.publicationDate).toISOString().split('T')[0]!)\n newsElement.ele('news:title').txt(item.news.title)\n }\n }\n\n return sitemap.end({ prettyPrint: true })\n}\n\nexport function buildSitemap({\n options,\n publicDir,\n}: {\n options: TanStackStartOutputConfig\n publicDir: string\n}) {\n const logger = createLogger('sitemap')\n\n let sitemapOptions = options.sitemap\n\n if (!sitemapOptions && options.pages.length) {\n sitemapOptions = { enabled: true, outputPath: 'sitemap.xml' }\n }\n\n if (!sitemapOptions?.enabled) {\n throw new Error('Sitemap is not enabled')\n }\n\n const { host, outputPath } = sitemapOptions\n\n if (!host) {\n if (!options.sitemap) {\n logger.info(\n 'Hint: Pages found, but no sitemap host has been set. To enable sitemap generation, set the `sitemap.host` option.',\n )\n return\n }\n throw new Error(\n 'Sitemap host is not set and required to build the sitemap.',\n )\n }\n\n if (!outputPath) {\n throw new Error('Sitemap output path is not set')\n }\n\n const { pages } = options\n\n if (!pages.length) {\n logger.info('No pages were found to build the sitemap. Skipping...')\n return\n }\n\n logger.info('Building Sitemap...')\n\n // Build the sitemap data\n const sitemapData = buildSitemapJson(pages, host)\n\n // Generate output paths\n const xmlOutputPath = path.join(publicDir, outputPath)\n const pagesOutputPath = path.join(publicDir, 'pages.json')\n\n try {\n // Write XML sitemap\n logger.info(`Writing sitemap XML at ${xmlOutputPath}`)\n writeFileSync(xmlOutputPath, jsonToXml(sitemapData))\n\n // Write pages data for runtime use\n logger.info(`Writing pages data at ${pagesOutputPath}`)\n writeFileSync(\n pagesOutputPath,\n JSON.stringify(\n {\n pages,\n host,\n lastBuilt: new Date().toISOString(),\n },\n null,\n 2,\n ),\n )\n } catch (e) {\n logger.error(`Unable to write sitemap files`, e)\n }\n}\n\nfunction createXml(elementName: 'urlset' | 'sitemapindex'): XMLBuilder {\n return create({ version: '1.0', encoding: 'UTF-8' })\n .ele(elementName, {\n xmlns: 'https://www.sitemaps.org/schemas/sitemap/0.9',\n })\n .com(`This file was automatically generated by TanStack Start.`)\n}\n\nfunction checkSlash(host: string): string {\n const finalChar = host.slice(-1)\n return finalChar === '/' ? '' : '/'\n}\n"],"names":["createLogger","writeFileSync","create"],"mappings":";;;;;;AA0CA,SAAS,iBACP,OACA,MACa;AACP,QAAA,QAAQ,WAAW,IAAI;A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type SitemapUrl = {
|
|
3
|
+
loc: string;
|
|
4
|
+
lastmod: string;
|
|
5
|
+
priority?: number;
|
|
6
|
+
changefreq?: 'always' | 'hourly' | 'daily' | 'weekly' | 'monthly' | 'yearly' | 'never';
|
|
7
|
+
alternateRefs?: Array<{
|
|
8
|
+
href: string;
|
|
9
|
+
hreflang?: string;
|
|
10
|
+
}>;
|
|
11
|
+
images?: Array<{
|
|
12
|
+
loc: string;
|
|
13
|
+
title?: string;
|
|
14
|
+
caption?: string;
|
|
15
|
+
}>;
|
|
16
|
+
news?: {
|
|
17
|
+
publication: {
|
|
18
|
+
name: string;
|
|
19
|
+
language: string;
|
|
20
|
+
};
|
|
21
|
+
publicationDate: string | Date;
|
|
22
|
+
title: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export type SitemapData = {
|
|
26
|
+
urls: Array<SitemapUrl>;
|
|
27
|
+
};
|
|
28
|
+
export declare function buildSitemap({ options, publicDir, }: {
|
|
29
|
+
options: TanStackStartOutputConfig;
|
|
30
|
+
publicDir: string;
|
|
31
|
+
}): void;
|
|
@@ -4,15 +4,12 @@ const path = require("node:path");
|
|
|
4
4
|
const fs = require("node:fs");
|
|
5
5
|
const nitropack = require("nitropack");
|
|
6
6
|
const pathe = require("pathe");
|
|
7
|
-
const plugin = require("../plugin.cjs");
|
|
8
|
-
const prerender = require("../prerender.cjs");
|
|
9
7
|
const constants = require("../constants.cjs");
|
|
10
|
-
const
|
|
11
|
-
const
|
|
8
|
+
const buildSitemap = require("./build-sitemap.cjs");
|
|
9
|
+
const prerender = require("./prerender.cjs");
|
|
12
10
|
function nitroPlugin(options, getSsrBundle) {
|
|
13
11
|
const buildPreset = process.env["START_TARGET"] ?? options.target;
|
|
14
12
|
return [
|
|
15
|
-
devServerPlugin.devServerPlugin(),
|
|
16
13
|
{
|
|
17
14
|
name: "tanstack-vite-plugin-nitro",
|
|
18
15
|
configEnvironment(name) {
|
|
@@ -37,77 +34,54 @@ function nitroPlugin(options, getSsrBundle) {
|
|
|
37
34
|
builder: {
|
|
38
35
|
sharedPlugins: true,
|
|
39
36
|
async buildApp(builder) {
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
if (!clientEnv) {
|
|
37
|
+
const client = builder.environments[constants.VITE_ENVIRONMENT_NAMES.client];
|
|
38
|
+
const server = builder.environments[constants.VITE_ENVIRONMENT_NAMES.server];
|
|
39
|
+
if (!client) {
|
|
44
40
|
throw new Error("Client environment not found");
|
|
45
41
|
}
|
|
46
|
-
if (!
|
|
42
|
+
if (!server) {
|
|
47
43
|
throw new Error("SSR environment not found");
|
|
48
44
|
}
|
|
49
|
-
const clientOutputDir = pathe.resolve(options.root,
|
|
45
|
+
const clientOutputDir = pathe.resolve(options.root, constants.CLIENT_DIST_DIR);
|
|
50
46
|
fs.rmSync(clientOutputDir, { recursive: true, force: true });
|
|
51
|
-
await builder.build(
|
|
52
|
-
await builder.build(
|
|
47
|
+
await builder.build(client);
|
|
48
|
+
await builder.build(server);
|
|
53
49
|
const nitroConfig = {
|
|
54
50
|
dev: false,
|
|
55
|
-
// TODO do we need this? should this be made configurable?
|
|
51
|
+
// TODO: do we need this? should this be made configurable?
|
|
56
52
|
compatibilityDate: "2024-11-19",
|
|
57
53
|
logLevel: 3,
|
|
58
54
|
preset: buildPreset,
|
|
55
|
+
baseURL: globalThis.TSS_APP_BASE,
|
|
59
56
|
publicAssets: [
|
|
60
57
|
{
|
|
61
|
-
dir: path.resolve(options.root,
|
|
58
|
+
dir: path.resolve(options.root, constants.CLIENT_DIST_DIR),
|
|
59
|
+
baseURL: "/",
|
|
60
|
+
maxAge: 31536e3
|
|
61
|
+
// 1 year
|
|
62
62
|
}
|
|
63
63
|
],
|
|
64
64
|
typescript: {
|
|
65
65
|
generateTsConfig: false
|
|
66
66
|
},
|
|
67
67
|
prerender: void 0,
|
|
68
|
-
renderer:
|
|
68
|
+
renderer: constants.SSR_ENTRY_FILE,
|
|
69
|
+
plugins: [],
|
|
70
|
+
// Nitro's plugins
|
|
71
|
+
appConfigFiles: [],
|
|
72
|
+
scanDirs: [],
|
|
73
|
+
imports: false,
|
|
74
|
+
// unjs/unimport for global/magic imports
|
|
69
75
|
rollupConfig: {
|
|
70
76
|
plugins: [virtualBundlePlugin(getSsrBundle())]
|
|
77
|
+
},
|
|
78
|
+
virtual: {
|
|
79
|
+
// This is Nitro's way of defining virtual modules
|
|
80
|
+
// Should we define the ones for TanStack Start's here as well?
|
|
71
81
|
}
|
|
72
82
|
};
|
|
73
83
|
const nitro = await nitropack.createNitro(nitroConfig);
|
|
74
|
-
await
|
|
75
|
-
if (((_a = options.prerender) == null ? void 0 : _a.enabled) !== false) {
|
|
76
|
-
options.prerender = {
|
|
77
|
-
...options.prerender,
|
|
78
|
-
enabled: options.pages.some(
|
|
79
|
-
(d) => {
|
|
80
|
-
var _a2;
|
|
81
|
-
return typeof d === "string" ? false : !!((_a2 = d.prerender) == null ? void 0 : _a2.enabled);
|
|
82
|
-
}
|
|
83
|
-
)
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
if ((_b = options.spa) == null ? void 0 : _b.enabled) {
|
|
87
|
-
options.prerender = {
|
|
88
|
-
...options.prerender,
|
|
89
|
-
enabled: true
|
|
90
|
-
};
|
|
91
|
-
const maskUrl = new URL(
|
|
92
|
-
options.spa.maskPath,
|
|
93
|
-
"http://localhost"
|
|
94
|
-
);
|
|
95
|
-
maskUrl.searchParams.set("__TSS_SHELL", "true");
|
|
96
|
-
options.pages.push({
|
|
97
|
-
path: maskUrl.toString().replace("http://localhost", ""),
|
|
98
|
-
prerender: options.spa.prerender,
|
|
99
|
-
sitemap: {
|
|
100
|
-
exclude: true
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
if (options.prerender.enabled) {
|
|
105
|
-
await prerender.prerender({
|
|
106
|
-
options,
|
|
107
|
-
nitro,
|
|
108
|
-
builder
|
|
109
|
-
});
|
|
110
|
-
}
|
|
84
|
+
await buildNitroApp(builder, nitro, options);
|
|
111
85
|
}
|
|
112
86
|
}
|
|
113
87
|
};
|
|
@@ -115,6 +89,55 @@ function nitroPlugin(options, getSsrBundle) {
|
|
|
115
89
|
}
|
|
116
90
|
];
|
|
117
91
|
}
|
|
92
|
+
async function buildNitroApp(builder, nitro, options) {
|
|
93
|
+
var _a, _b;
|
|
94
|
+
await nitropack.prepare(nitro);
|
|
95
|
+
await nitropack.copyPublicAssets(nitro);
|
|
96
|
+
if (((_a = options.prerender) == null ? void 0 : _a.enabled) !== false) {
|
|
97
|
+
options.prerender = {
|
|
98
|
+
...options.prerender,
|
|
99
|
+
enabled: options.pages.some(
|
|
100
|
+
(d) => {
|
|
101
|
+
var _a2;
|
|
102
|
+
return typeof d === "string" ? false : !!((_a2 = d.prerender) == null ? void 0 : _a2.enabled);
|
|
103
|
+
}
|
|
104
|
+
)
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
if ((_b = options.spa) == null ? void 0 : _b.enabled) {
|
|
108
|
+
options.prerender = {
|
|
109
|
+
...options.prerender,
|
|
110
|
+
enabled: true
|
|
111
|
+
};
|
|
112
|
+
const maskUrl = new URL(options.spa.maskPath, "http://localhost");
|
|
113
|
+
maskUrl.searchParams.set("__TSS_SHELL", "true");
|
|
114
|
+
options.pages.push({
|
|
115
|
+
path: maskUrl.toString().replace("http://localhost", ""),
|
|
116
|
+
prerender: options.spa.prerender,
|
|
117
|
+
sitemap: {
|
|
118
|
+
exclude: true
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
if (options.prerender.enabled) {
|
|
123
|
+
await prerender.prerender({
|
|
124
|
+
options,
|
|
125
|
+
nitro,
|
|
126
|
+
builder
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
if (options.pages.length) {
|
|
130
|
+
buildSitemap.buildSitemap({
|
|
131
|
+
options,
|
|
132
|
+
publicDir: nitro.options.output.publicDir
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
await nitropack.build(nitro);
|
|
136
|
+
await nitro.close();
|
|
137
|
+
nitro.logger.success(
|
|
138
|
+
"Client and Server bundles for TanStack Start have been successfully built."
|
|
139
|
+
);
|
|
140
|
+
}
|
|
118
141
|
function virtualBundlePlugin(ssrBundle) {
|
|
119
142
|
const _modules = /* @__PURE__ */ new Map();
|
|
120
143
|
for (const [fileName, content] of Object.entries(ssrBundle)) {
|
|
@@ -155,4 +178,4 @@ function virtualBundlePlugin(ssrBundle) {
|
|
|
155
178
|
};
|
|
156
179
|
}
|
|
157
180
|
exports.nitroPlugin = nitroPlugin;
|
|
158
|
-
//# sourceMappingURL=
|
|
181
|
+
//# sourceMappingURL=plugin.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.cjs","sources":["../../../src/nitro-plugin/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { rmSync } from 'node:fs'\nimport { build, copyPublicAssets, createNitro, prepare } from 'nitropack'\nimport { dirname, resolve } from 'pathe'\nimport {\n CLIENT_DIST_DIR,\n SSR_ENTRY_FILE,\n VITE_ENVIRONMENT_NAMES,\n} from '../constants'\nimport { buildSitemap } from './build-sitemap'\nimport { prerender } from './prerender'\nimport type {\n EnvironmentOptions,\n PluginOption,\n Rollup,\n ViteBuilder,\n} from 'vite'\nimport type { Nitro, NitroConfig } from 'nitropack'\nimport type { TanStackStartOutputConfig } from '../plugin'\n\nexport function nitroPlugin(\n options: TanStackStartOutputConfig,\n getSsrBundle: () => Rollup.OutputBundle,\n): Array<PluginOption> {\n const buildPreset =\n process.env['START_TARGET'] ?? (options.target as string | undefined)\n return [\n {\n name: 'tanstack-vite-plugin-nitro',\n configEnvironment(name) {\n if (name === VITE_ENVIRONMENT_NAMES.server) {\n return {\n build: {\n commonjsOptions: {\n include: [],\n },\n ssr: true,\n sourcemap: true,\n rollupOptions: {\n input: '/~start/server-entry',\n },\n },\n } satisfies EnvironmentOptions\n }\n\n return null\n },\n config() {\n return {\n builder: {\n sharedPlugins: true,\n async buildApp(builder) {\n const client = builder.environments[VITE_ENVIRONMENT_NAMES.client]\n const server = builder.environments[VITE_ENVIRONMENT_NAMES.server]\n\n if (!client) {\n throw new Error('Client environment not found')\n }\n\n if (!server) {\n throw new Error('SSR environment not found')\n }\n\n // Build the client bundle\n // i.e client entry file with `hydrateRoot(...)`\n const clientOutputDir = resolve(options.root, CLIENT_DIST_DIR)\n rmSync(clientOutputDir, { recursive: true, force: true })\n await builder.build(client)\n\n // Build the SSR bundle\n await builder.build(server)\n\n const nitroConfig: NitroConfig = {\n dev: false,\n // TODO: do we need this? should this be made configurable?\n compatibilityDate: '2024-11-19',\n logLevel: 3,\n preset: buildPreset,\n baseURL: globalThis.TSS_APP_BASE,\n publicAssets: [\n {\n dir: path.resolve(options.root, CLIENT_DIST_DIR),\n baseURL: '/',\n maxAge: 31536000, // 1 year\n },\n ],\n typescript: {\n generateTsConfig: false,\n },\n prerender: undefined,\n renderer: SSR_ENTRY_FILE,\n plugins: [], // Nitro's plugins\n appConfigFiles: [],\n scanDirs: [],\n imports: false, // unjs/unimport for global/magic imports\n rollupConfig: {\n plugins: [virtualBundlePlugin(getSsrBundle())],\n },\n virtual: {\n // This is Nitro's way of defining virtual modules\n // Should we define the ones for TanStack Start's here as well?\n },\n }\n\n const nitro = await createNitro(nitroConfig)\n\n await buildNitroApp(builder, nitro, options)\n },\n },\n }\n },\n },\n ]\n}\n\n/**\n * Correctly co-ordinates the nitro app build process to make sure that the\n * app is built, while also correctly handling the prerendering and sitemap\n * generation and including their outputs in the final build.\n */\nasync function buildNitroApp(\n builder: ViteBuilder,\n nitro: Nitro,\n options: TanStackStartOutputConfig,\n) {\n // Cleans the public and server directories for a fresh build\n // i.e the `.output/public` and `.output/server` directories\n await prepare(nitro)\n\n // Creates the `.output/public` directory and copies the public assets\n await copyPublicAssets(nitro)\n\n // If the user has not set a prerender option, we need to set it to true\n // if the pages array is not empty and has sub options requiring for prerendering\n if (options.prerender?.enabled !== false) {\n options.prerender = {\n ...options.prerender,\n enabled: options.pages.some((d) =>\n typeof d === 'string' ? false : !!d.prerender?.enabled,\n ),\n }\n }\n\n // Setup the options for prerendering the SPA shell (i.e `src/routes/__root.tsx`)\n if (options.spa?.enabled) {\n options.prerender = {\n ...options.prerender,\n enabled: true,\n }\n\n const maskUrl = new URL(options.spa.maskPath, 'http://localhost')\n\n maskUrl.searchParams.set('__TSS_SHELL', 'true')\n\n options.pages.push({\n path: maskUrl.toString().replace('http://localhost', ''),\n prerender: options.spa.prerender,\n sitemap: {\n exclude: true,\n },\n })\n }\n\n // Run the prerendering process\n if (options.prerender.enabled) {\n await prerender({\n options,\n nitro,\n builder,\n })\n }\n\n // Run the sitemap build process\n if (options.pages.length) {\n buildSitemap({\n options,\n publicDir: nitro.options.output.publicDir,\n })\n }\n\n // Build the nitro app\n // We only build the nitro app, once we've prepared the public assets,\n // prerendered the pages and built the sitemap.\n // If we try to do this earlier, then the public assets may not be available\n // in the production build.\n await build(nitro)\n\n // Close the nitro instance\n await nitro.close()\n nitro.logger.success(\n 'Client and Server bundles for TanStack Start have been successfully built.',\n )\n}\n\ntype NitroRollupPluginOption = NonNullable<\n NitroConfig['rollupConfig']\n>['plugins']\n\nfunction virtualBundlePlugin(\n ssrBundle: Rollup.OutputBundle,\n): NitroRollupPluginOption {\n type VirtualModule = { code: string; map: string | null }\n const _modules = new Map<string, VirtualModule>()\n\n // group chunks and source maps\n for (const [fileName, content] of Object.entries(ssrBundle)) {\n if (content.type === 'chunk') {\n const virtualModule: VirtualModule = {\n code: content.code,\n map: null,\n }\n const maybeMap = ssrBundle[`${fileName}.map`]\n if (maybeMap && maybeMap.type === 'asset') {\n virtualModule.map = maybeMap.source as string\n }\n _modules.set(fileName, virtualModule)\n _modules.set(resolve(fileName), virtualModule)\n }\n }\n\n return {\n name: 'virtual-bundle',\n resolveId(id, importer) {\n if (_modules.has(id)) {\n return resolve(id)\n }\n\n if (importer) {\n const resolved = resolve(dirname(importer), id)\n if (_modules.has(resolved)) {\n return resolved\n }\n }\n return null\n },\n load(id) {\n const m = _modules.get(id)\n if (!m) {\n return null\n }\n return m\n },\n }\n}\n"],"names":["VITE_ENVIRONMENT_NAMES","resolve","CLIENT_DIST_DIR","rmSync","SSR_ENTRY_FILE","createNitro","prepare","copyPublicAssets","_a","prerender","buildSitemap","build","dirname"],"mappings":";;;;;;;;;AAoBgB,SAAA,YACd,SACA,cACqB;AACrB,QAAM,cACJ,QAAQ,IAAI,cAAc,KAAM,QAAQ;AACnC,SAAA;AAAA,IACL;AAAA,MACE,MAAM;AAAA,MACN,kBAAkB,MAAM;AAClB,YAAA,SAASA,iCAAuB,QAAQ;AACnC,iBAAA;AAAA,YACL,OAAO;AAAA,cACL,iBAAiB;AAAA,gBACf,SAAS,CAAA;AAAA,cACX;AAAA,cACA,KAAK;AAAA,cACL,WAAW;AAAA,cACX,eAAe;AAAA,gBACb,OAAO;AAAA,cAAA;AAAA,YACT;AAAA,UAEJ;AAAA,QAAA;AAGK,eAAA;AAAA,MACT;AAAA,MACA,SAAS;AACA,eAAA;AAAA,UACL,SAAS;AAAA,YACP,eAAe;AAAA,YACf,MAAM,SAAS,SAAS;AACtB,oBAAM,SAAS,QAAQ,aAAaA,UAAAA,uBAAuB,MAAM;AACjE,oBAAM,SAAS,QAAQ,aAAaA,UAAAA,uBAAuB,MAAM;AAEjE,kBAAI,CAAC,QAAQ;AACL,sBAAA,IAAI,MAAM,8BAA8B;AAAA,cAAA;AAGhD,kBAAI,CAAC,QAAQ;AACL,sBAAA,IAAI,MAAM,2BAA2B;AAAA,cAAA;AAK7C,oBAAM,kBAAkBC,MAAA,QAAQ,QAAQ,MAAMC,UAAAA,eAAe;AAC7DC,iBAAA,OAAO,iBAAiB,EAAE,WAAW,MAAM,OAAO,MAAM;AAClD,oBAAA,QAAQ,MAAM,MAAM;AAGpB,oBAAA,QAAQ,MAAM,MAAM;AAE1B,oBAAM,cAA2B;AAAA,gBAC/B,KAAK;AAAA;AAAA,gBAE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MAAA,QAAQW,MAAQ,QAAA,QAAQ,GAAG,EAAE;AAC1C,YAAA,SAAS,IAAI,QAAQ,GAAG;AACnB,iBAAA;AAAA,QAAA;AAAA,MACT;AAEK,aAAA;AAAA,IACT;AAAA,IACA,KAAK,IAAI;AACD,YAAA,IAAI,SAAS,IAAI,EAAE;AACzB,UAAI,CAAC,GAAG;AACC,eAAA;AAAA,MAAA;AAEF,aAAA;AAAA,IAAA;AAAA,EAEX;AACF;;"}
|
|
@@ -6,16 +6,17 @@ const path = require("node:path");
|
|
|
6
6
|
const rollup = require("nitropack/rollup");
|
|
7
7
|
const nitropack = require("nitropack");
|
|
8
8
|
const ufo = require("ufo");
|
|
9
|
+
const constants = require("../constants.cjs");
|
|
10
|
+
const utils = require("../utils.cjs");
|
|
9
11
|
const queue = require("./queue.cjs");
|
|
10
|
-
const buildNitro = require("./nitro/build-nitro.cjs");
|
|
11
|
-
const constants = require("./constants.cjs");
|
|
12
12
|
async function prerender({
|
|
13
13
|
options,
|
|
14
14
|
nitro,
|
|
15
15
|
builder
|
|
16
16
|
}) {
|
|
17
17
|
var _a;
|
|
18
|
-
|
|
18
|
+
const logger = utils.createLogger("prerender");
|
|
19
|
+
logger.info("Prendering pages...");
|
|
19
20
|
if (((_a = options.prerender) == null ? void 0 : _a.enabled) && !options.pages.length) {
|
|
20
21
|
options.pages = [
|
|
21
22
|
{
|
|
@@ -55,7 +56,7 @@ async function prerender({
|
|
|
55
56
|
sourcemap: void 0
|
|
56
57
|
}
|
|
57
58
|
};
|
|
58
|
-
await
|
|
59
|
+
await nitropack.build(nodeNitro);
|
|
59
60
|
const serverFilename = typeof nodeNitroRollupOptions.output.entryFileNames === "string" ? nodeNitroRollupOptions.output.entryFileNames : "index.mjs";
|
|
60
61
|
const serverEntrypoint = path.resolve(
|
|
61
62
|
path.join(nodeNitro.options.output.serverDir, serverFilename)
|
|
@@ -63,12 +64,12 @@ async function prerender({
|
|
|
63
64
|
const { closePrerenderer, localFetch } = await import(serverEntrypoint);
|
|
64
65
|
try {
|
|
65
66
|
const pages = await prerenderPages();
|
|
66
|
-
|
|
67
|
+
logger.info(`Prerendered ${pages.length} pages:`);
|
|
67
68
|
pages.forEach((page) => {
|
|
68
|
-
|
|
69
|
+
logger.info(`- ${page}`);
|
|
69
70
|
});
|
|
70
71
|
} catch (error) {
|
|
71
|
-
|
|
72
|
+
logger.error(error);
|
|
72
73
|
} finally {
|
|
73
74
|
closePrerenderer();
|
|
74
75
|
}
|
|
@@ -89,15 +90,9 @@ async function prerender({
|
|
|
89
90
|
const seen = /* @__PURE__ */ new Set();
|
|
90
91
|
const retriesByPath = /* @__PURE__ */ new Map();
|
|
91
92
|
const concurrency = ((_a2 = options.prerender) == null ? void 0 : _a2.concurrency) ?? os.cpus().length;
|
|
92
|
-
|
|
93
|
+
logger.info(`Concurrency: ${concurrency}`);
|
|
93
94
|
const queue$1 = new queue.Queue({ concurrency });
|
|
94
|
-
options.pages.forEach((
|
|
95
|
-
let page = _page;
|
|
96
|
-
if (typeof _page === "string") {
|
|
97
|
-
page = { path: _page };
|
|
98
|
-
}
|
|
99
|
-
addCrawlPageTask(page);
|
|
100
|
-
});
|
|
95
|
+
options.pages.forEach((page) => addCrawlPageTask(page));
|
|
101
96
|
await queue$1.start();
|
|
102
97
|
return Array.from(seen);
|
|
103
98
|
function addCrawlPageTask(page) {
|
|
@@ -115,7 +110,7 @@ async function prerender({
|
|
|
115
110
|
};
|
|
116
111
|
queue$1.add(async () => {
|
|
117
112
|
var _a4;
|
|
118
|
-
|
|
113
|
+
logger.info(`Crawling: ${page.path}`);
|
|
119
114
|
const retries = retriesByPath.get(page.path) || 0;
|
|
120
115
|
try {
|
|
121
116
|
const encodedRoute = encodeURI(page.path);
|
|
@@ -157,7 +152,7 @@ async function prerender({
|
|
|
157
152
|
}
|
|
158
153
|
} catch (error) {
|
|
159
154
|
if (retries < (prerenderOptions.retryCount ?? 0)) {
|
|
160
|
-
|
|
155
|
+
logger.warn(`Encountered error, retrying: ${page.path} in 500ms`);
|
|
161
156
|
await new Promise(
|
|
162
157
|
(resolve) => setTimeout(resolve, prerenderOptions.retryDelay)
|
|
163
158
|
);
|