@analogjs/vite-plugin-nitro 3.0.0-alpha.4 → 3.0.0-alpha.41

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.
Files changed (57) hide show
  1. package/package.json +26 -11
  2. package/src/index.d.ts +11 -9
  3. package/src/index.js +7 -2
  4. package/src/index.js.map +1 -1
  5. package/src/lib/build-server.d.ts +2 -2
  6. package/src/lib/build-server.js +45 -149
  7. package/src/lib/build-server.js.map +1 -1
  8. package/src/lib/build-sitemap.d.ts +23 -9
  9. package/src/lib/build-sitemap.js +132 -63
  10. package/src/lib/build-sitemap.js.map +1 -1
  11. package/src/lib/build-ssr.d.ts +3 -2
  12. package/src/lib/build-ssr.js +26 -18
  13. package/src/lib/build-ssr.js.map +1 -1
  14. package/src/lib/hooks/post-rendering-hook.d.ts +1 -1
  15. package/src/lib/hooks/post-rendering-hook.js +10 -6
  16. package/src/lib/hooks/post-rendering-hook.js.map +1 -1
  17. package/src/lib/options.d.ts +143 -106
  18. package/src/lib/plugins/dev-server-plugin.d.ts +3 -3
  19. package/src/lib/plugins/dev-server-plugin.js +98 -101
  20. package/src/lib/plugins/dev-server-plugin.js.map +1 -1
  21. package/src/lib/plugins/page-endpoints.d.ts +5 -5
  22. package/src/lib/plugins/page-endpoints.js +26 -57
  23. package/src/lib/plugins/page-endpoints.js.map +1 -1
  24. package/src/lib/utils/debug.d.ts +5 -0
  25. package/src/lib/utils/debug.js +15 -0
  26. package/src/lib/utils/debug.js.map +1 -0
  27. package/src/lib/utils/get-content-files.d.ts +54 -54
  28. package/src/lib/utils/get-content-files.js +88 -97
  29. package/src/lib/utils/get-content-files.js.map +1 -1
  30. package/src/lib/utils/get-page-handlers.d.ts +58 -58
  31. package/src/lib/utils/get-page-handlers.js +70 -84
  32. package/src/lib/utils/get-page-handlers.js.map +1 -1
  33. package/src/lib/utils/i18n-prerender.d.ts +36 -0
  34. package/src/lib/utils/i18n-prerender.js +23 -0
  35. package/src/lib/utils/i18n-prerender.js.map +1 -0
  36. package/src/lib/utils/load-esm.d.ts +18 -18
  37. package/src/lib/utils/node-web-bridge.d.ts +1 -1
  38. package/src/lib/utils/node-web-bridge.js +50 -45
  39. package/src/lib/utils/node-web-bridge.js.map +1 -1
  40. package/src/lib/utils/register-dev-middleware.d.ts +12 -12
  41. package/src/lib/utils/register-dev-middleware.js +41 -47
  42. package/src/lib/utils/register-dev-middleware.js.map +1 -1
  43. package/src/lib/utils/register-i18n-watcher.d.ts +15 -0
  44. package/src/lib/utils/renderers.d.ts +47 -47
  45. package/src/lib/utils/renderers.js +57 -56
  46. package/src/lib/utils/renderers.js.map +1 -1
  47. package/src/lib/utils/rolldown.d.ts +2 -0
  48. package/src/lib/utils/rolldown.js +12 -0
  49. package/src/lib/utils/rolldown.js.map +1 -0
  50. package/src/lib/vite-plugin-nitro.d.ts +3 -3
  51. package/src/lib/vite-plugin-nitro.js +790 -677
  52. package/src/lib/vite-plugin-nitro.js.map +1 -1
  53. package/README.md +0 -125
  54. package/src/lib/options.js +0 -2
  55. package/src/lib/options.js.map +0 -1
  56. package/src/lib/utils/load-esm.js +0 -23
  57. package/src/lib/utils/load-esm.js.map +0 -1
@@ -1,20 +1,28 @@
1
- import { build, mergeConfig } from 'vite';
2
- import * as vite from 'vite';
3
- import { relative, resolve } from 'node:path';
4
- export async function buildSSRApp(config, options) {
5
- const workspaceRoot = options?.workspaceRoot ?? process.cwd();
6
- const sourceRoot = options?.sourceRoot ?? 'src';
7
- const rootDir = relative(workspaceRoot, config.root || '.') || '.';
8
- const ssrBuildConfig = mergeConfig(config, {
9
- build: {
10
- ssr: true,
11
- [vite.rolldownVersion ? 'rolldownOptions' : 'rollupOptions']: {
12
- input: options?.entryServer ||
13
- resolve(workspaceRoot, rootDir, `${sourceRoot}/main.server.ts`),
14
- },
15
- outDir: options?.ssrBuildDir || resolve(workspaceRoot, 'dist', rootDir, 'ssr'),
16
- },
17
- });
18
- await build(ssrBuildConfig);
1
+ import { getBundleOptionsKey } from "./utils/rolldown.js";
2
+ import { build, mergeConfig } from "vite";
3
+ import { relative, resolve } from "node:path";
4
+ //#region packages/vite-plugin-nitro/src/lib/build-ssr.ts
5
+ async function buildClientApp(config, options) {
6
+ const workspaceRoot = options?.workspaceRoot ?? process.cwd();
7
+ const rootDir = relative(workspaceRoot, config.root || ".") || ".";
8
+ await build(mergeConfig(config, { build: {
9
+ ssr: false,
10
+ outDir: config.build?.outDir || resolve(workspaceRoot, "dist", rootDir, "client"),
11
+ emptyOutDir: true
12
+ } }));
19
13
  }
14
+ async function buildSSRApp(config, options) {
15
+ const workspaceRoot = options?.workspaceRoot ?? process.cwd();
16
+ const sourceRoot = options?.sourceRoot ?? "src";
17
+ const rootDir = relative(workspaceRoot, config.root || ".") || ".";
18
+ await build(mergeConfig(config, { build: {
19
+ ssr: true,
20
+ [getBundleOptionsKey()]: { input: options?.entryServer || resolve(workspaceRoot, rootDir, `${sourceRoot}/main.server.ts`) },
21
+ outDir: options?.ssrBuildDir || resolve(workspaceRoot, "dist", rootDir, "ssr"),
22
+ emptyOutDir: false
23
+ } }));
24
+ }
25
+ //#endregion
26
+ export { buildClientApp, buildSSRApp };
27
+
20
28
  //# sourceMappingURL=build-ssr.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"build-ssr.js","sourceRoot":"","sources":["../../../../../packages/vite-plugin-nitro/src/lib/build-ssr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAc,MAAM,MAAM,CAAC;AACtD,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAI9C,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAAkB,EAClB,OAAiB;IAEjB,MAAM,aAAa,GAAG,OAAO,EAAE,aAAa,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAC9D,MAAM,UAAU,GAAG,OAAO,EAAE,UAAU,IAAI,KAAK,CAAC;IAChD,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,GAAG,CAAC;IACnE,MAAM,cAAc,GAAG,WAAW,CAAC,MAAM,EAAc;QACrD,KAAK,EAAE;YACL,GAAG,EAAE,IAAI;YACT,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,eAAe,CAAC,EAAE;gBAC5D,KAAK,EACH,OAAO,EAAE,WAAW;oBACpB,OAAO,CAAC,aAAa,EAAE,OAAO,EAAE,GAAG,UAAU,iBAAiB,CAAC;aAClE;YACD,MAAM,EACJ,OAAO,EAAE,WAAW,IAAI,OAAO,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC;SACzE;KACF,CAAC,CAAC;IAEH,MAAM,KAAK,CAAC,cAAc,CAAC,CAAC;AAC9B,CAAC"}
1
+ {"version":3,"file":"build-ssr.js","names":[],"sources":["../../../src/lib/build-ssr.ts"],"sourcesContent":["import { build, mergeConfig, UserConfig } from 'vite';\nimport { relative, resolve } from 'node:path';\n\nimport { Options } from './options.js';\nimport { getBundleOptionsKey } from './utils/rolldown.js';\n\nexport async function buildClientApp(\n config: UserConfig,\n options?: Options,\n): Promise<void> {\n const workspaceRoot = options?.workspaceRoot ?? process.cwd();\n const rootDir = relative(workspaceRoot, config.root || '.') || '.';\n const clientBuildConfig = mergeConfig(config, <UserConfig>{\n build: {\n ssr: false,\n outDir:\n config.build?.outDir ||\n resolve(workspaceRoot, 'dist', rootDir, 'client'),\n emptyOutDir: true,\n },\n });\n\n await build(clientBuildConfig);\n}\n\nexport async function buildSSRApp(\n config: UserConfig,\n options?: Options,\n): Promise<void> {\n const workspaceRoot = options?.workspaceRoot ?? process.cwd();\n const sourceRoot = options?.sourceRoot ?? 'src';\n const rootDir = relative(workspaceRoot, config.root || '.') || '.';\n const bundleOptionsKey = getBundleOptionsKey();\n\n /**\n * SSR is built as a second pass from the already prepared Analog/Vite config.\n *\n * That means we intentionally start from the same base config used for the\n * client build and then merge only the SSR-specific overrides (entry, outDir,\n * `build.ssr`, etc).\n *\n * A side effect of this design is that the resolved SSR config can expose the\n * same high-level Analog plugin chain more than once when Vite/Nitro replays\n * shared plugins for the server environment. In particular,\n * `@analogjs/vite-plugin-angular` may appear twice in `config.plugins` during\n * SSR resolution:\n * - once from the normal Analog platform plugin expansion\n * - once from the reused/shared plugin graph for the SSR pass\n *\n * That does NOT imply the client build has two competing style registries.\n * The client-side duplicate-registration guard in `vite-plugin-angular`\n * therefore explicitly ignores `build.ssr === true` to avoid treating this\n * valid SSR orchestration detail as a style-map bug.\n */\n const ssrBuildConfig = mergeConfig(config, <UserConfig>{\n build: {\n ssr: true,\n [bundleOptionsKey]: {\n input:\n options?.entryServer ||\n resolve(workspaceRoot, rootDir, `${sourceRoot}/main.server.ts`),\n },\n outDir:\n options?.ssrBuildDir || resolve(workspaceRoot, 'dist', rootDir, 'ssr'),\n // Preserve the client build output. The client pass already handled its\n // own cleanup, and on Windows this nested SSR build can otherwise remove\n // sibling artifacts that Nitro needs to read immediately afterward.\n emptyOutDir: false,\n },\n });\n\n await build(ssrBuildConfig);\n}\n"],"mappings":";;;;AAMA,eAAsB,eACpB,QACA,SACe;CACf,MAAM,gBAAgB,SAAS,iBAAiB,QAAQ,KAAK;CAC7D,MAAM,UAAU,SAAS,eAAe,OAAO,QAAQ,IAAI,IAAI;AAW/D,OAAM,MAVoB,YAAY,QAAoB,EACxD,OAAO;EACL,KAAK;EACL,QACE,OAAO,OAAO,UACd,QAAQ,eAAe,QAAQ,SAAS,SAAS;EACnD,aAAa;EACd,EACF,CAAC,CAE4B;;AAGhC,eAAsB,YACpB,QACA,SACe;CACf,MAAM,gBAAgB,SAAS,iBAAiB,QAAQ,KAAK;CAC7D,MAAM,aAAa,SAAS,cAAc;CAC1C,MAAM,UAAU,SAAS,eAAe,OAAO,QAAQ,IAAI,IAAI;AAwC/D,OAAM,MAjBiB,YAAY,QAAoB,EACrD,OAAO;EACL,KAAK;GAxBgB,qBAAqB,GAyBtB,EAClB,OACE,SAAS,eACT,QAAQ,eAAe,SAAS,GAAG,WAAW,iBAAiB,EAClE;EACD,QACE,SAAS,eAAe,QAAQ,eAAe,QAAQ,SAAS,MAAM;EAIxE,aAAa;EACd,EACF,CAAC,CAEyB"}
@@ -1,2 +1,2 @@
1
- import type { Nitro, PrerenderRoute } from 'nitro/types';
1
+ import type { Nitro, PrerenderRoute } from "nitro/types";
2
2
  export declare function addPostRenderingHooks(nitro: Nitro, hooks: ((pr: PrerenderRoute) => Promise<void>)[]): void;
@@ -1,8 +1,12 @@
1
- export function addPostRenderingHooks(nitro, hooks) {
2
- hooks.forEach((hook) => {
3
- nitro.hooks.hook('prerender:generate', (route) => {
4
- hook(route);
5
- });
6
- });
1
+ //#region packages/vite-plugin-nitro/src/lib/hooks/post-rendering-hook.ts
2
+ function addPostRenderingHooks(nitro, hooks) {
3
+ hooks.forEach((hook) => {
4
+ nitro.hooks.hook("prerender:generate", (route) => {
5
+ hook(route);
6
+ });
7
+ });
7
8
  }
9
+ //#endregion
10
+ export { addPostRenderingHooks };
11
+
8
12
  //# sourceMappingURL=post-rendering-hook.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"post-rendering-hook.js","sourceRoot":"","sources":["../../../../../../packages/vite-plugin-nitro/src/lib/hooks/post-rendering-hook.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,qBAAqB,CACnC,KAAY,EACZ,KAAgD;IAEhD,KAAK,CAAC,OAAO,CAAC,CAAC,IAAwC,EAAE,EAAE;QACzD,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,oBAAoB,EAAE,CAAC,KAAqB,EAAE,EAAE;YAC/D,IAAI,CAAC,KAAK,CAAC,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
1
+ {"version":3,"file":"post-rendering-hook.js","names":[],"sources":["../../../../src/lib/hooks/post-rendering-hook.ts"],"sourcesContent":["import type { Nitro, PrerenderRoute } from 'nitro/types';\n\nexport function addPostRenderingHooks(\n nitro: Nitro,\n hooks: ((pr: PrerenderRoute) => Promise<void>)[],\n): void {\n hooks.forEach((hook: (preRoute: PrerenderRoute) => void) => {\n nitro.hooks.hook('prerender:generate', (route: PrerenderRoute) => {\n hook(route);\n });\n });\n}\n"],"mappings":";AAEA,SAAgB,sBACd,OACA,OACM;AACN,OAAM,SAAS,SAA6C;AAC1D,QAAM,MAAM,KAAK,uBAAuB,UAA0B;AAChE,QAAK,MAAM;IACX;GACF"}
@@ -1,121 +1,158 @@
1
- import type { PrerenderRoute } from 'nitro/types';
1
+ import type { PrerenderRoute } from "nitro/types";
2
+ import type { UserConfig } from "vite";
3
+ export interface I18nPrerenderOptions {
4
+ /**
5
+ * The default/source locale for the application.
6
+ */
7
+ defaultLocale: string;
8
+ /**
9
+ * List of supported locale identifiers.
10
+ * Each route will be prerendered once per locale with a locale prefix.
11
+ */
12
+ locales: string[];
13
+ }
2
14
  export interface Options {
3
- ssr?: boolean;
4
- ssrBuildDir?: string;
5
- /**
6
- * Prerender the static pages without producing the server output.
7
- */
8
- static?: boolean;
9
- prerender?: PrerenderOptions;
10
- entryServer?: string;
11
- index?: string;
12
- /**
13
- * Relative path to source files. Default is 'src'.
14
- */
15
- sourceRoot?: string;
16
- /**
17
- * Absolute path to workspace root. Default is 'process.cwd()'
18
- */
19
- workspaceRoot?: string;
20
- /**
21
- * Additional page paths to include
22
- */
23
- additionalPagesDirs?: string[];
24
- /**
25
- * Additional API paths to include
26
- */
27
- additionalAPIDirs?: string[];
28
- apiPrefix?: string;
29
- /**
30
- * Toggles internal API middleware.
31
- * If disabled, a proxy request is used to route /api
32
- * requests to / in the production server build.
33
- *
34
- * @deprecated
35
- * Use the src/server/routes/api folder
36
- * for API routes.
37
- */
38
- useAPIMiddleware?: boolean;
15
+ ssr?: boolean;
16
+ ssrBuildDir?: string;
17
+ /**
18
+ * Prerender the static pages without producing the server output.
19
+ */
20
+ static?: boolean;
21
+ prerender?: PrerenderOptions;
22
+ entryServer?: string;
23
+ index?: string;
24
+ /**
25
+ * Relative path to source files. Default is 'src'.
26
+ */
27
+ sourceRoot?: string;
28
+ /**
29
+ * Absolute path to workspace root. Default is 'process.cwd()'
30
+ */
31
+ workspaceRoot?: string;
32
+ /**
33
+ * Additional page paths to include
34
+ */
35
+ additionalPagesDirs?: string[];
36
+ /**
37
+ * Additional API paths to include
38
+ */
39
+ additionalAPIDirs?: string[];
40
+ apiPrefix?: string;
41
+ /**
42
+ * Toggles internal API middleware.
43
+ * If disabled, a proxy request is used to route /api
44
+ * requests to / in the production server build.
45
+ *
46
+ * @deprecated
47
+ * Use the src/server/routes/api folder
48
+ * for API routes.
49
+ */
50
+ useAPIMiddleware?: boolean;
51
+ /**
52
+ * Vite-native build passthrough. Rolldown-only options such as
53
+ * `build.rolldownOptions.output.codeSplitting` are forwarded when present.
54
+ */
55
+ vite?: {
56
+ build?: UserConfig["build"];
57
+ };
39
58
  }
40
59
  export interface PrerenderOptions {
41
- /**
42
- * Add additional routes to prerender through crawling page links.
43
- */
44
- discover?: boolean;
45
- /**
46
- * List of routes to prerender resolved statically or dynamically.
47
- */
48
- routes?: (string | PrerenderContentDir | PrerenderRouteConfig)[] | (() => Promise<(string | PrerenderContentDir | PrerenderRouteConfig | undefined)[]>);
49
- sitemap?: SitemapConfig;
50
- /** List of functions that run for each route after pre-rendering is complete. */
51
- postRenderingHooks?: ((routes: PrerenderRoute) => Promise<void>)[];
60
+ /**
61
+ * Add additional routes to prerender through crawling page links.
62
+ */
63
+ discover?: boolean;
64
+ /**
65
+ * List of routes to prerender resolved statically or dynamically.
66
+ */
67
+ routes?: (string | PrerenderContentDir | PrerenderRouteConfig)[] | (() => Promise<(string | PrerenderContentDir | PrerenderRouteConfig | undefined)[]>);
68
+ sitemap?: SitemapConfig;
69
+ /** List of functions that run for each route after pre-rendering is complete. */
70
+ postRenderingHooks?: ((routes: PrerenderRoute) => Promise<void>)[];
71
+ }
72
+ export type SitemapPriority = number | `${number}`;
73
+ export interface SitemapRouteDefinition {
74
+ route: string;
75
+ lastmod?: string;
76
+ changefreq?: "always" | "hourly" | "daily" | "weekly" | "monthly" | "yearly" | "never";
77
+ priority?: SitemapPriority;
78
+ }
79
+ export interface SitemapEntry extends SitemapRouteDefinition {
80
+ loc: string;
52
81
  }
82
+ export type SitemapRouteInput = string | SitemapRouteDefinition | undefined;
83
+ export type SitemapRouteSource = SitemapRouteInput[] | (() => Promise<SitemapRouteInput[]>);
84
+ export type SitemapExcludeRule = string | RegExp | ((entry: SitemapEntry) => boolean | Promise<boolean>);
85
+ export type SitemapTransform = (entry: SitemapEntry) => SitemapRouteDefinition | false | Promise<SitemapRouteDefinition | false>;
53
86
  export interface SitemapConfig {
54
- host: string;
87
+ host: string;
88
+ include?: SitemapRouteSource;
89
+ exclude?: SitemapExcludeRule[];
90
+ defaults?: PrerenderSitemapConfig;
91
+ transform?: SitemapTransform;
55
92
  }
56
93
  export interface PrerenderContentDir {
57
- /**
58
- * The directory where files should be grabbed from.
59
- * @example `/src/contents/blog`
60
- */
61
- contentDir: string;
62
- /**
63
- * Transform the matching content files path into a route.
64
- * The function is called for each matching content file within the specified contentDir.
65
- * @param file information of the matching file (`path`, `name`, `extension`, `attributes`, `content`)
66
- * @returns a string with the route should be returned (e. g. `/blog/<slug>`) or the value `false`, when the route should not be prerendered.
67
- */
68
- transform: (file: PrerenderContentFile) => string | false;
69
- /**
70
- * Customize the sitemap definition for the prerendered route
71
- *
72
- * https://www.sitemaps.org/protocol.html#xmlTagDefinitions
73
- */
74
- sitemap?: PrerenderSitemapConfig | ((file: PrerenderContentFile) => PrerenderSitemapConfig);
75
- /**
76
- * Output the source markdown content alongside the prerendered route.
77
- * The source file will be accessible at the route path with a .md extension.
78
- * @param file information of the matching file including its content
79
- * @returns the markdown content string to output, or `false` to skip outputting for this file
80
- */
81
- outputSourceFile?: (file: PrerenderContentFile) => string | false;
94
+ /**
95
+ * The directory where files should be grabbed from.
96
+ * @example `/src/contents/blog`
97
+ */
98
+ contentDir: string;
99
+ /**
100
+ * Transform the matching content files path into a route.
101
+ * The function is called for each matching content file within the specified contentDir.
102
+ * @param file information of the matching file (`path`, `name`, `extension`, `attributes`, `content`)
103
+ * @returns a string with the route should be returned (e. g. `/blog/<slug>`) or the value `false`, when the route should not be prerendered.
104
+ */
105
+ transform: (file: PrerenderContentFile) => string | false;
106
+ /**
107
+ * Customize the sitemap definition for the prerendered route
108
+ *
109
+ * https://www.sitemaps.org/protocol.html#xmlTagDefinitions
110
+ */
111
+ sitemap?: PrerenderSitemapConfig | ((file: PrerenderContentFile) => PrerenderSitemapConfig);
112
+ /**
113
+ * Output the source markdown content alongside the prerendered route.
114
+ * The source file will be accessible at the route path with a .md extension.
115
+ * @param file information of the matching file including its content
116
+ * @returns the markdown content string to output, or `false` to skip outputting for this file
117
+ */
118
+ outputSourceFile?: (file: PrerenderContentFile) => string | false;
82
119
  }
83
120
  /**
84
- * @param path the path to the content file
85
- * @param name the basename of the matching content file without the file extension
86
- * @param extension the file extension
87
- * @param attributes the frontmatter attributes extracted from the frontmatter section of the file
88
- * @param content the raw file content including frontmatter
89
- * @returns a string with the route should be returned (e. g. `/blog/<slug>`) or the value `false`, when the route should not be prerendered.
90
- */
121
+ * @param path the path to the content file
122
+ * @param name the basename of the matching content file without the file extension
123
+ * @param extension the file extension
124
+ * @param attributes the frontmatter attributes extracted from the frontmatter section of the file
125
+ * @param content the raw file content including frontmatter
126
+ * @returns a string with the route should be returned (e. g. `/blog/<slug>`) or the value `false`, when the route should not be prerendered.
127
+ */
91
128
  export interface PrerenderContentFile {
92
- path: string;
93
- attributes: Record<string, any>;
94
- name: string;
95
- extension: string;
96
- content: string;
129
+ path: string;
130
+ attributes: Record<string, any>;
131
+ name: string;
132
+ extension: string;
133
+ content: string;
97
134
  }
98
135
  export interface PrerenderSitemapConfig {
99
- lastmod?: string;
100
- changefreq?: 'always' | 'hourly' | 'daily' | 'weekly' | 'monthly' | 'yearly' | 'never';
101
- priority?: string;
136
+ lastmod?: string;
137
+ changefreq?: "always" | "hourly" | "daily" | "weekly" | "monthly" | "yearly" | "never";
138
+ priority?: SitemapPriority;
102
139
  }
103
140
  export interface PrerenderRouteConfig {
104
- route: string;
105
- /**
106
- * Customize the sitemap definition for the prerendered route
107
- *
108
- * https://www.sitemaps.org/protocol.html#xmlTagDefinitions
109
- */
110
- sitemap?: PrerenderSitemapConfig | (() => PrerenderSitemapConfig);
111
- /**
112
- * Prerender static data for the prerendered route
113
- */
114
- staticData?: boolean;
115
- /**
116
- * Path to the source markdown file to output alongside the prerendered route.
117
- * The source file will be accessible at the route path with a .md extension.
118
- * @example 'src/content/overview.md'
119
- */
120
- outputSourceFile?: string;
141
+ route: string;
142
+ /**
143
+ * Customize the sitemap definition for the prerendered route
144
+ *
145
+ * https://www.sitemaps.org/protocol.html#xmlTagDefinitions
146
+ */
147
+ sitemap?: PrerenderSitemapConfig | (() => PrerenderSitemapConfig);
148
+ /**
149
+ * Prerender static data for the prerendered route
150
+ */
151
+ staticData?: boolean;
152
+ /**
153
+ * Path to the source markdown file to output alongside the prerendered route.
154
+ * The source file will be accessible at the route path with a .md extension.
155
+ * @example 'src/content/overview.md'
156
+ */
157
+ outputSourceFile?: string;
121
158
  }
@@ -1,7 +1,7 @@
1
- import { Plugin } from 'vite';
2
- import { Options } from '../options.js';
1
+ import { Plugin } from "vite";
2
+ import { Options } from "../options.js";
3
3
  type ServerOptions = Options & {
4
- routeRules?: Record<string, any> | undefined;
4
+ routeRules?: Record<string, any> | undefined;
5
5
  };
6
6
  export declare function devServerPlugin(options: ServerOptions): Plugin;
7
7
  export {};
@@ -1,70 +1,66 @@
1
- // SSR dev server, middleware and error page source modified from
2
- // https://github.com/solidjs/solid-start/blob/main/packages/start/dev/server.js
3
- import { normalizePath, } from 'vite';
4
- import { resolve } from 'node:path';
5
- import { readFileSync } from 'node:fs';
6
- import { createRouter as createRadixRouter, toRouteMatcher } from 'radix3';
7
- import { defu } from 'defu';
8
- import { registerDevServerMiddleware } from '../utils/register-dev-middleware.js';
9
- import { writeWebResponseToNode } from '../utils/node-web-bridge.js';
10
- export function devServerPlugin(options) {
11
- const workspaceRoot = options?.workspaceRoot || process.cwd();
12
- const sourceRoot = options?.sourceRoot ?? 'src';
13
- const index = options.index || 'index.html';
14
- let config;
15
- let root;
16
- let isTest = false;
17
- return {
18
- name: 'analogjs-dev-ssr-plugin',
19
- config(userConfig, { mode }) {
20
- config = userConfig;
21
- root = normalizePath(resolve(workspaceRoot, config.root || '.') || '.');
22
- isTest = isTest ? isTest : mode === 'test';
23
- return {
24
- appType: 'custom',
25
- resolve: {
26
- alias: {
27
- '~analog/entry-server': options.entryServer || `${root}/${sourceRoot}/main.server.ts`,
28
- },
29
- },
30
- };
31
- },
32
- configureServer(viteServer) {
33
- if (isTest) {
34
- return;
35
- }
36
- return async () => {
37
- remove_html_middlewares(viteServer.middlewares);
38
- registerDevServerMiddleware(root, sourceRoot, viteServer);
39
- viteServer.middlewares.use(async (req, res) => {
40
- let template = readFileSync(resolve(viteServer.config.root, index), 'utf-8');
41
- template = await viteServer.transformIndexHtml(req.originalUrl, template);
42
- const _routeRulesMatcher = toRouteMatcher(createRadixRouter({ routes: options.routeRules }));
43
- const _getRouteRules = (path) => defu({}, ..._routeRulesMatcher.matchAll(path).reverse());
44
- try {
45
- let result;
46
- // Check for route rules explicitly disabling SSR
47
- if (_getRouteRules(req.originalUrl).ssr === false) {
48
- result = template;
49
- }
50
- else {
51
- const entryServer = (await viteServer.ssrLoadModule('~analog/entry-server'))['default'];
52
- result = await entryServer(req.originalUrl, template, {
53
- req,
54
- res,
55
- });
56
- }
57
- if (result instanceof Response) {
58
- await writeWebResponseToNode(res, result);
59
- return;
60
- }
61
- res.setHeader('Content-Type', 'text/html');
62
- res.end(result);
63
- }
64
- catch (e) {
65
- viteServer.ssrFixStacktrace(e);
66
- res.statusCode = 500;
67
- res.end(`
1
+ import { writeWebResponseToNode } from "../utils/node-web-bridge.js";
2
+ import { registerDevServerMiddleware } from "../utils/register-dev-middleware.js";
3
+ import { detectLocaleFromRoute, setHtmlLang } from "../utils/i18n-prerender.js";
4
+ import { normalizePath } from "vite";
5
+ import { resolve } from "node:path";
6
+ import { readFileSync } from "node:fs";
7
+ import { createRouter, toRouteMatcher } from "radix3";
8
+ import { defu } from "defu";
9
+ //#region packages/vite-plugin-nitro/src/lib/plugins/dev-server-plugin.ts
10
+ function devServerPlugin(options) {
11
+ const workspaceRoot = options?.workspaceRoot || process.cwd();
12
+ const sourceRoot = options?.sourceRoot ?? "src";
13
+ const index = options.index || "index.html";
14
+ let config;
15
+ let root;
16
+ let isTest = false;
17
+ return {
18
+ name: "analogjs-dev-ssr-plugin",
19
+ config(userConfig, { mode }) {
20
+ config = userConfig;
21
+ root = normalizePath(resolve(workspaceRoot, config.root || ".") || ".");
22
+ isTest = isTest ? isTest : mode === "test";
23
+ return {
24
+ appType: "custom",
25
+ resolve: { alias: { "~analog/entry-server": options.entryServer || `${root}/${sourceRoot}/main.server.ts` } }
26
+ };
27
+ },
28
+ configureServer(viteServer) {
29
+ if (isTest) return;
30
+ return async () => {
31
+ remove_html_middlewares(viteServer.middlewares);
32
+ registerDevServerMiddleware(root, sourceRoot, viteServer);
33
+ if (options.i18n) registerI18nWatcher(viteServer);
34
+ viteServer.middlewares.use(async (req, res) => {
35
+ let template = readFileSync(resolve(viteServer.config.root, index), "utf-8");
36
+ template = await viteServer.transformIndexHtml(req.originalUrl, template);
37
+ const _routeRulesMatcher = toRouteMatcher(createRouter({ routes: options.routeRules }));
38
+ const _getRouteRules = (path) => defu({}, ..._routeRulesMatcher.matchAll(path).reverse());
39
+ try {
40
+ let result;
41
+ if (_getRouteRules(req.originalUrl).ssr === false) result = template;
42
+ else {
43
+ const entryServer = (await viteServer.ssrLoadModule("~analog/entry-server"))["default"];
44
+ result = await entryServer(req.originalUrl, template, {
45
+ req,
46
+ res
47
+ });
48
+ }
49
+ if (result instanceof Response) {
50
+ await writeWebResponseToNode(res, result);
51
+ return;
52
+ }
53
+ let html = typeof result === "string" ? result : template;
54
+ if (options.i18n) {
55
+ const locale = detectLocaleFromRoute(req.originalUrl, options.i18n);
56
+ html = setHtmlLang(html, locale);
57
+ }
58
+ res.setHeader("Content-Type", "text/html");
59
+ res.end(html);
60
+ } catch (e) {
61
+ viteServer.ssrFixStacktrace(e);
62
+ res.statusCode = 500;
63
+ res.end(`
68
64
  <!DOCTYPE html>
69
65
  <html lang="en">
70
66
  <head>
@@ -72,50 +68,51 @@ export function devServerPlugin(options) {
72
68
  <title>Error</title>
73
69
  <script type="module">
74
70
  import { ErrorOverlay } from '/@vite/client'
75
- document.body.appendChild(new ErrorOverlay(${JSON.stringify(prepareError(req, e)).replace(/</g, '\\u003c')}))
76
- </script>
71
+ document.body.appendChild(new ErrorOverlay(${JSON.stringify(prepareError(req, e)).replace(/</g, "\\u003c")}))
72
+ <\/script>
77
73
  </head>
78
74
  <body>
79
75
  </body>
80
76
  </html>
81
77
  `);
82
- }
83
- });
84
- };
85
- },
86
- };
78
+ }
79
+ });
80
+ };
81
+ }
82
+ };
87
83
  }
88
84
  /**
89
- * Removes Vite internal middleware
90
- *
91
- * @param server
92
- */
85
+ * Removes Vite internal middleware
86
+ *
87
+ * @param server
88
+ */
93
89
  function remove_html_middlewares(server) {
94
- const html_middlewares = [
95
- 'viteIndexHtmlMiddleware',
96
- 'vite404Middleware',
97
- 'viteSpaFallbackMiddleware',
98
- 'viteHtmlFallbackMiddleware',
99
- ];
100
- for (let i = server.stack.length - 1; i > 0; i--) {
101
- const handler = server.stack[i]?.handle;
102
- const handlerName = typeof handler === 'function' ? handler.name : undefined;
103
- if (handlerName && html_middlewares.includes(handlerName)) {
104
- server.stack.splice(i, 1);
105
- }
106
- }
90
+ const html_middlewares = [
91
+ "viteIndexHtmlMiddleware",
92
+ "vite404Middleware",
93
+ "viteSpaFallbackMiddleware",
94
+ "viteHtmlFallbackMiddleware"
95
+ ];
96
+ for (let i = server.stack.length - 1; i > 0; i--) {
97
+ const handler = server.stack[i]?.handle;
98
+ const handlerName = typeof handler === "function" ? handler.name : void 0;
99
+ if (handlerName && html_middlewares.includes(handlerName)) server.stack.splice(i, 1);
100
+ }
107
101
  }
108
102
  /**
109
- * Formats error for SSR message in error overlay
110
- * @param req
111
- * @param error
112
- * @returns
113
- */
103
+ * Formats error for SSR message in error overlay
104
+ * @param req
105
+ * @param error
106
+ * @returns
107
+ */
114
108
  function prepareError(req, error) {
115
- const e = error;
116
- return {
117
- message: `An error occured while server rendering ${req.url}:\n\n\t${typeof e === 'string' ? e : e.message} `,
118
- stack: typeof e === 'string' ? '' : e.stack,
119
- };
109
+ const e = error;
110
+ return {
111
+ message: `An error occured while server rendering ${req.url}:\n\n\t${typeof e === "string" ? e : e.message} `,
112
+ stack: typeof e === "string" ? "" : e.stack
113
+ };
120
114
  }
115
+ //#endregion
116
+ export { devServerPlugin };
117
+
121
118
  //# sourceMappingURL=dev-server-plugin.js.map