@analogjs/platform 3.0.0-beta.2 → 3.0.0-beta.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/package.json +8 -5
- package/src/lib/content-plugin.js +12 -3
- package/src/lib/content-plugin.js.map +1 -1
- package/src/lib/deps-plugin.d.ts +1 -1
- package/src/lib/deps-plugin.js +10 -6
- package/src/lib/deps-plugin.js.map +1 -1
- package/src/lib/get-page-endpoints.d.ts +25 -0
- package/src/lib/get-page-endpoints.js +29 -0
- package/src/lib/get-page-endpoints.js.map +1 -0
- package/src/lib/nitro/get-page-handlers.d.ts +4 -19
- package/src/lib/nitro/get-page-handlers.js +9 -26
- package/src/lib/nitro/get-page-handlers.js.map +1 -1
- package/src/lib/nx-plugin/executors.json +0 -7
- package/src/lib/nx-plugin/src/generators/app/compat.d.ts +2 -1
- package/src/lib/nx-plugin/src/generators/app/compat.js +4 -1
- package/src/lib/nx-plugin/src/generators/app/compat.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/generator.js +7 -2
- package/src/lib/nx-plugin/src/generators/app/generator.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/lib/add-tailwind-helpers.js +2 -2
- package/src/lib/nx-plugin/src/generators/app/lib/add-tailwind-helpers.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/versions/minimum-supported-versions.d.ts +3 -1
- package/src/lib/nx-plugin/src/generators/app/versions/minimum-supported-versions.js +5 -1
- package/src/lib/nx-plugin/src/generators/app/versions/minimum-supported-versions.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/init/compat.d.ts +2 -1
- package/src/lib/nx-plugin/src/generators/init/compat.js +4 -1
- package/src/lib/nx-plugin/src/generators/init/compat.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/init/lib/add-analog-dependencies.js +2 -2
- package/src/lib/nx-plugin/src/generators/init/lib/add-analog-dependencies.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/page/compat.d.ts +2 -1
- package/src/lib/nx-plugin/src/generators/page/compat.js +4 -1
- package/src/lib/nx-plugin/src/generators/page/compat.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/preset/__snapshots__/generator.spec.ts.snap +4 -0
- package/src/lib/nx-plugin/src/generators/preset/generator.js +5 -2
- package/src/lib/nx-plugin/src/generators/preset/generator.js.map +1 -1
- package/src/lib/nx-plugin/src/utils/versions/dev-dependencies.d.ts +2 -2
- package/src/lib/nx-plugin/src/utils/versions/dev-dependencies.js +7 -3
- package/src/lib/nx-plugin/src/utils/versions/dev-dependencies.js.map +1 -1
- package/src/lib/nx-plugin/src/utils/versions/versions.d.ts +9 -6
- package/src/lib/nx-plugin/src/utils/versions/versions.js +13 -7
- package/src/lib/nx-plugin/src/utils/versions/versions.js.map +1 -1
- package/src/lib/options.d.ts +16 -0
- package/src/lib/platform-plugin.js +2 -0
- package/src/lib/platform-plugin.js.map +1 -1
- package/src/lib/router-plugin.js +1 -1
- package/src/lib/router-plugin.js.map +1 -1
- package/src/lib/server-plugin.d.ts +9 -0
- package/src/lib/server-plugin.js +154 -0
- package/src/lib/server-plugin.js.map +1 -0
- package/src/lib/typed-routes-plugin.js +1 -1
- package/src/lib/typed-routes-plugin.js.map +1 -1
- package/src/lib/nx-plugin/src/executors/vite-dev-server/compat.d.ts +0 -3
- package/src/lib/nx-plugin/src/executors/vite-dev-server/compat.js +0 -7
- package/src/lib/nx-plugin/src/executors/vite-dev-server/compat.js.map +0 -1
- package/src/lib/nx-plugin/src/executors/vite-dev-server/schema.d.ts +0 -1
- package/src/lib/nx-plugin/src/executors/vite-dev-server/schema.json +0 -101
- package/src/lib/nx-plugin/src/executors/vite-dev-server/vite-dev-server.impl.d.ts +0 -2
- package/src/lib/nx-plugin/src/executors/vite-dev-server/vite-dev-server.impl.js +0 -6
- package/src/lib/nx-plugin/src/executors/vite-dev-server/vite-dev-server.impl.js.map +0 -1
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { getPageEndpoints } from "./get-page-endpoints.js";
|
|
2
|
+
import { getServerFnHandlers } from "./nitro/get-server-fn-handlers.js";
|
|
3
|
+
import { relative, resolve } from "node:path";
|
|
4
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
5
|
+
import { normalizePath } from "vite";
|
|
6
|
+
//#region packages/platform/src/lib/server-plugin.ts
|
|
7
|
+
var MANIFEST_PLACEHOLDER = /ANALOG_SERVER_MANIFEST = \{\}/;
|
|
8
|
+
var DEV_TEMPLATE = Symbol.for("@analogjs/platform/dev-template");
|
|
9
|
+
var HTML_MIDDLEWARES = [
|
|
10
|
+
"viteIndexHtmlMiddleware",
|
|
11
|
+
"vite404Middleware",
|
|
12
|
+
"viteSpaFallbackMiddleware",
|
|
13
|
+
"viteHtmlFallbackMiddleware"
|
|
14
|
+
];
|
|
15
|
+
var NITRO_PLUGINS = ["nitro:main", "@analogjs/vite-plugin-nitro"];
|
|
16
|
+
/**
|
|
17
|
+
* Builds and serves the app from `server.entry` instead of Nitro: the client
|
|
18
|
+
* and one server bundle in `vite build`, and the entry's app behind Vite's
|
|
19
|
+
* own middleware in dev. Fills in the `ANALOG_SERVER_MANIFEST` placeholder
|
|
20
|
+
* that `createAnalogRequestHandler()` in `@analogjs/router/server` reads.
|
|
21
|
+
*/
|
|
22
|
+
function serverPlugin(server, options = {}) {
|
|
23
|
+
const workspaceRoot = options.workspaceRoot ?? process.env["NX_WORKSPACE_ROOT"] ?? process.cwd();
|
|
24
|
+
const apiPrefix = options.apiPrefix ?? "api";
|
|
25
|
+
let root = process.cwd();
|
|
26
|
+
let isBuild = false;
|
|
27
|
+
let builtTemplate;
|
|
28
|
+
let manifestId;
|
|
29
|
+
const rootDir = () => relative(workspaceRoot, root) || ".";
|
|
30
|
+
const indexHtml = () => resolve(root, options.index ?? "index.html");
|
|
31
|
+
return {
|
|
32
|
+
name: "@analogjs/platform-server",
|
|
33
|
+
config(config, { command }) {
|
|
34
|
+
if ((config.plugins ?? []).flat(Infinity).some((p) => NITRO_PLUGINS.includes(p?.name ?? ""))) throw new Error("[@analogjs/platform] `analog({ server })` replaces Nitro; remove `nitro()` from the Vite plugins.");
|
|
35
|
+
root = normalizePath(resolve(config.root ?? process.cwd()));
|
|
36
|
+
isBuild = command === "build";
|
|
37
|
+
const outDir = (name) => resolve(workspaceRoot, "dist", rootDir(), name);
|
|
38
|
+
return {
|
|
39
|
+
environments: {
|
|
40
|
+
client: { build: {
|
|
41
|
+
outDir: outDir("client"),
|
|
42
|
+
rollupOptions: { input: indexHtml() }
|
|
43
|
+
} },
|
|
44
|
+
ssr: { build: {
|
|
45
|
+
outDir: outDir("server"),
|
|
46
|
+
copyPublicDir: false,
|
|
47
|
+
rollupOptions: { input: { main: resolve(root, server.entry) } }
|
|
48
|
+
} }
|
|
49
|
+
},
|
|
50
|
+
builder: {
|
|
51
|
+
sharedPlugins: true,
|
|
52
|
+
async buildApp(builder) {
|
|
53
|
+
await builder.build(builder.environments["client"]);
|
|
54
|
+
await builder.build(builder.environments["ssr"]);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
writeBundle(_options, bundle) {
|
|
60
|
+
if (this.environment.name === "client") {
|
|
61
|
+
const document = bundle[normalizePath(relative(root, indexHtml()))];
|
|
62
|
+
if (document?.type === "asset") builtTemplate = String(document.source);
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
transform: {
|
|
66
|
+
filter: { code: "ANALOG_SERVER_MANIFEST" },
|
|
67
|
+
handler(code, id) {
|
|
68
|
+
if (!MANIFEST_PLACEHOLDER.test(code)) return;
|
|
69
|
+
manifestId = id;
|
|
70
|
+
return code.replace(MANIFEST_PLACEHOLDER, `ANALOG_SERVER_MANIFEST = ${serverManifest()}`);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
configureServer(viteServer) {
|
|
74
|
+
globalThis[DEV_TEMPLATE] = (url) => viteServer.transformIndexHtml(url, readFileSync(indexHtml(), "utf-8"));
|
|
75
|
+
const invalidateManifest = (file) => {
|
|
76
|
+
const graph = viteServer.environments["ssr"].moduleGraph;
|
|
77
|
+
const mod = manifestId && graph.getModuleById(manifestId);
|
|
78
|
+
if (file.endsWith(".server.ts") && mod) graph.invalidateModule(mod);
|
|
79
|
+
};
|
|
80
|
+
viteServer.watcher.on("add", invalidateManifest);
|
|
81
|
+
viteServer.watcher.on("unlink", invalidateManifest);
|
|
82
|
+
return () => {
|
|
83
|
+
removeHtmlMiddlewares(viteServer.middlewares);
|
|
84
|
+
viteServer.middlewares.use(devMiddleware(viteServer, resolve(root, server.entry)));
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
function requireBuiltTemplate() {
|
|
89
|
+
if (builtTemplate === void 0) throw new Error(`[@analogjs/platform] The client build didn't emit ${relative(root, indexHtml())}, which the server renders around.`);
|
|
90
|
+
return builtTemplate;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The manifest object literal: the template, and lazy imports of the SSR
|
|
94
|
+
* renderer, the server config, every server function module, and page
|
|
95
|
+
* endpoints keyed by route.
|
|
96
|
+
*/
|
|
97
|
+
function serverManifest() {
|
|
98
|
+
const src = `${root}/src`;
|
|
99
|
+
const lazy = (file) => `() => import(${JSON.stringify(file)})`;
|
|
100
|
+
const appConfig = [`${src}/app/app.config.server.ts`, `${src}/app.config.server.ts`].find((file) => existsSync(file));
|
|
101
|
+
const discovery = {
|
|
102
|
+
workspaceRoot,
|
|
103
|
+
sourceRoot: "src",
|
|
104
|
+
rootDir: rootDir()
|
|
105
|
+
};
|
|
106
|
+
const pageEndpoints = getPageEndpoints({
|
|
107
|
+
...discovery,
|
|
108
|
+
additionalPagesDirs: options.additionalPagesDirs
|
|
109
|
+
}).map(({ file, route }) => `${JSON.stringify(`/${apiPrefix}/_analog${route}`)}: ${lazy(normalizePath(file))}`);
|
|
110
|
+
const serverFnModules = getServerFnHandlers(discovery).map(({ file }) => lazy(file));
|
|
111
|
+
const template = isBuild ? `async () => ${JSON.stringify(requireBuiltTemplate())}` : `(url) => globalThis[Symbol.for('@analogjs/platform/dev-template')](url)`;
|
|
112
|
+
return `{
|
|
113
|
+
apiPrefix: ${JSON.stringify(apiPrefix)},
|
|
114
|
+
template: ${template},
|
|
115
|
+
render: () => import(${JSON.stringify(normalizePath(options.entryServer ?? `${src}/main.server.ts`))}).then((m) => m.default),
|
|
116
|
+
config: ${appConfig ? `() => import(${JSON.stringify(appConfig)}).then((m) => m.config)` : `async () => ({ providers: [] })`},
|
|
117
|
+
serverFnModules: [${serverFnModules.join(", ")}],
|
|
118
|
+
pageEndpoints: {${pageEndpoints.join(", ")}},
|
|
119
|
+
}`;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Hands every request Vite doesn't serve to the entry's app. The app is
|
|
124
|
+
* recreated when the server module graph changes (ssrLoadModule returns a new
|
|
125
|
+
* module) and the previous one is closed.
|
|
126
|
+
*/
|
|
127
|
+
function devMiddleware(viteServer, entry) {
|
|
128
|
+
let current;
|
|
129
|
+
async function getApp() {
|
|
130
|
+
const loaded = await viteServer.ssrLoadModule(entry);
|
|
131
|
+
if (current?.entry !== loaded) {
|
|
132
|
+
const previous = current;
|
|
133
|
+
current = {
|
|
134
|
+
entry: loaded,
|
|
135
|
+
app: loaded.createApp()
|
|
136
|
+
};
|
|
137
|
+
previous?.app.then((app) => app.close?.(), () => void 0);
|
|
138
|
+
}
|
|
139
|
+
return current.app;
|
|
140
|
+
}
|
|
141
|
+
return (req, res, next) => {
|
|
142
|
+
getApp().then((app) => app.handle(req, res, next)).catch((error) => {
|
|
143
|
+
viteServer.ssrFixStacktrace(error);
|
|
144
|
+
next(error);
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function removeHtmlMiddlewares(middlewares) {
|
|
149
|
+
middlewares.stack = middlewares.stack.filter((layer) => !HTML_MIDDLEWARES.includes(layer.handle.name ?? ""));
|
|
150
|
+
}
|
|
151
|
+
//#endregion
|
|
152
|
+
export { serverPlugin };
|
|
153
|
+
|
|
154
|
+
//# sourceMappingURL=server-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-plugin.js","names":[],"sources":["../../../src/lib/server-plugin.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport type { IncomingMessage, ServerResponse } from 'node:http';\nimport { relative, resolve } from 'node:path';\nimport {\n normalizePath,\n type Connect,\n type Plugin,\n type ViteDevServer,\n} from 'vite';\n\nimport { getPageEndpoints } from './get-page-endpoints.js';\nimport { getServerFnHandlers } from './nitro/get-server-fn-handlers.js';\nimport type { Options, ServerOptions } from './options.js';\n\nconst MANIFEST_PLACEHOLDER = /ANALOG_SERVER_MANIFEST = \\{\\}/;\nconst DEV_TEMPLATE = Symbol.for('@analogjs/platform/dev-template');\nconst HTML_MIDDLEWARES = [\n 'viteIndexHtmlMiddleware',\n 'vite404Middleware',\n 'viteSpaFallbackMiddleware',\n 'viteHtmlFallbackMiddleware',\n];\nconst NITRO_PLUGINS = ['nitro:main', '@analogjs/vite-plugin-nitro'];\n\ntype ServerApp = {\n handle: (\n req: IncomingMessage,\n res: ServerResponse,\n next: (error?: unknown) => void,\n ) => void;\n close?: () => Promise<void>;\n};\ntype ServerEntry = { createApp: () => Promise<ServerApp> };\n\n/**\n * Builds and serves the app from `server.entry` instead of Nitro: the client\n * and one server bundle in `vite build`, and the entry's app behind Vite's\n * own middleware in dev. Fills in the `ANALOG_SERVER_MANIFEST` placeholder\n * that `createAnalogRequestHandler()` in `@analogjs/router/server` reads.\n */\nexport function serverPlugin(\n server: ServerOptions,\n options: Options = {},\n): Plugin {\n const workspaceRoot =\n options.workspaceRoot ?? process.env['NX_WORKSPACE_ROOT'] ?? process.cwd();\n const apiPrefix = options.apiPrefix ?? 'api';\n let root = process.cwd();\n let isBuild = false;\n let builtTemplate: string | undefined;\n let manifestId: string | undefined;\n\n const rootDir = () => relative(workspaceRoot, root) || '.';\n const indexHtml = () => resolve(root, options.index ?? 'index.html');\n\n return {\n name: '@analogjs/platform-server',\n config(config, { command }) {\n const plugins = ((config.plugins ?? []) as unknown[]).flat(Infinity) as (\n | { name?: string }\n | null\n | undefined\n )[];\n if (plugins.some((p) => NITRO_PLUGINS.includes(p?.name ?? ''))) {\n throw new Error(\n '[@analogjs/platform] `analog({ server })` replaces Nitro; remove `nitro()` from the Vite plugins.',\n );\n }\n root = normalizePath(resolve(config.root ?? process.cwd()));\n isBuild = command === 'build';\n const outDir = (name: string) =>\n resolve(workspaceRoot, 'dist', rootDir(), name);\n return {\n environments: {\n client: {\n build: {\n outDir: outDir('client'),\n rollupOptions: { input: indexHtml() },\n },\n },\n ssr: {\n build: {\n outDir: outDir('server'),\n copyPublicDir: false,\n rollupOptions: { input: { main: resolve(root, server.entry) } },\n },\n },\n },\n builder: {\n // One plugin instance for both builds, so the server build sees\n // the document captured from the client build.\n sharedPlugins: true,\n async buildApp(builder) {\n await builder.build(builder.environments['client']);\n await builder.build(builder.environments['ssr']);\n },\n },\n };\n },\n // The server bundle renders around the built document, so take it from\n // the client build's own output.\n writeBundle(_options, bundle) {\n if (this.environment.name === 'client') {\n const document = bundle[normalizePath(relative(root, indexHtml()))];\n if (document?.type === 'asset') {\n builtTemplate = String(document.source);\n }\n }\n },\n transform: {\n filter: { code: 'ANALOG_SERVER_MANIFEST' },\n handler(code, id) {\n if (!MANIFEST_PLACEHOLDER.test(code)) {\n return undefined;\n }\n manifestId = id;\n return code.replace(\n MANIFEST_PLACEHOLDER,\n `ANALOG_SERVER_MANIFEST = ${serverManifest()}`,\n );\n },\n },\n configureServer(viteServer) {\n (globalThis as Record<symbol, unknown>)[DEV_TEMPLATE] = (url: string) =>\n viteServer.transformIndexHtml(url, readFileSync(indexHtml(), 'utf-8'));\n\n // New or removed page endpoints and server functions change the manifest.\n const invalidateManifest = (file: string) => {\n const graph = viteServer.environments['ssr'].moduleGraph;\n const mod = manifestId && graph.getModuleById(manifestId);\n if (file.endsWith('.server.ts') && mod) {\n graph.invalidateModule(mod);\n }\n };\n viteServer.watcher.on('add', invalidateManifest);\n viteServer.watcher.on('unlink', invalidateManifest);\n\n return () => {\n removeHtmlMiddlewares(viteServer.middlewares);\n viteServer.middlewares.use(\n devMiddleware(viteServer, resolve(root, server.entry)),\n );\n };\n },\n };\n\n function requireBuiltTemplate(): string {\n if (builtTemplate === undefined) {\n throw new Error(\n `[@analogjs/platform] The client build didn't emit ${relative(root, indexHtml())}, which the server renders around.`,\n );\n }\n return builtTemplate;\n }\n\n /**\n * The manifest object literal: the template, and lazy imports of the SSR\n * renderer, the server config, every server function module, and page\n * endpoints keyed by route.\n */\n function serverManifest(): string {\n const src = `${root}/src`;\n const lazy = (file: string) => `() => import(${JSON.stringify(file)})`;\n const appConfig = [\n `${src}/app/app.config.server.ts`,\n `${src}/app.config.server.ts`,\n ].find((file) => existsSync(file));\n const discovery = {\n workspaceRoot,\n sourceRoot: 'src',\n rootDir: rootDir(),\n };\n const pageEndpoints = getPageEndpoints({\n ...discovery,\n additionalPagesDirs: options.additionalPagesDirs,\n }).map(\n ({ file, route }) =>\n `${JSON.stringify(`/${apiPrefix}/_analog${route}`)}: ${lazy(normalizePath(file))}`,\n );\n const serverFnModules = getServerFnHandlers(discovery).map(({ file }) =>\n lazy(file),\n );\n const template = isBuild\n ? `async () => ${JSON.stringify(requireBuiltTemplate())}`\n : `(url) => globalThis[Symbol.for('@analogjs/platform/dev-template')](url)`;\n\n return `{\n apiPrefix: ${JSON.stringify(apiPrefix)},\n template: ${template},\n render: () => import(${JSON.stringify(normalizePath(options.entryServer ?? `${src}/main.server.ts`))}).then((m) => m.default),\n config: ${\n appConfig\n ? `() => import(${JSON.stringify(appConfig)}).then((m) => m.config)`\n : `async () => ({ providers: [] })`\n },\n serverFnModules: [${serverFnModules.join(', ')}],\n pageEndpoints: {${pageEndpoints.join(', ')}},\n}`;\n }\n}\n\n/**\n * Hands every request Vite doesn't serve to the entry's app. The app is\n * recreated when the server module graph changes (ssrLoadModule returns a new\n * module) and the previous one is closed.\n */\nfunction devMiddleware(\n viteServer: ViteDevServer,\n entry: string,\n): Connect.NextHandleFunction {\n let current: { entry: ServerEntry; app: Promise<ServerApp> } | undefined;\n\n async function getApp(): Promise<ServerApp> {\n const loaded = (await viteServer.ssrLoadModule(entry)) as ServerEntry;\n if (current?.entry !== loaded) {\n const previous = current;\n current = { entry: loaded, app: loaded.createApp() };\n void previous?.app.then(\n (app) => app.close?.(),\n () => undefined,\n );\n }\n return current.app;\n }\n\n return (req, res, next) => {\n getApp()\n .then((app) => app.handle(req, res, next))\n .catch((error: Error) => {\n viteServer.ssrFixStacktrace(error);\n next(error);\n });\n };\n}\n\nfunction removeHtmlMiddlewares(middlewares: Connect.Server): void {\n middlewares.stack = middlewares.stack.filter(\n (layer) =>\n !HTML_MIDDLEWARES.includes(\n (layer.handle as { name?: string }).name ?? '',\n ),\n );\n}\n"],"mappings":";;;;;;AAcA,IAAM,uBAAuB;AAC7B,IAAM,eAAe,OAAO,IAAI,iCAAiC;AACjE,IAAM,mBAAmB;CACvB;CACA;CACA;CACA;AACF;AACA,IAAM,gBAAgB,CAAC,cAAc,6BAA6B;;;;;;;AAkBlE,SAAgB,aACd,QACA,UAAmB,CAAC,GACZ;CACR,MAAM,gBACJ,QAAQ,iBAAiB,QAAQ,IAAI,wBAAwB,QAAQ,IAAI;CAC3E,MAAM,YAAY,QAAQ,aAAa;CACvC,IAAI,OAAO,QAAQ,IAAI;CACvB,IAAI,UAAU;CACd,IAAI;CACJ,IAAI;CAEJ,MAAM,gBAAgB,SAAS,eAAe,IAAI,KAAK;CACvD,MAAM,kBAAkB,QAAQ,MAAM,QAAQ,SAAS,YAAY;CAEnE,OAAO;EACL,MAAM;EACN,OAAO,QAAQ,EAAE,WAAW;GAM1B,KALkB,OAAO,WAAW,CAAC,EAAA,CAAiB,KAAK,QAKvD,CAAA,CAAQ,MAAM,MAAM,cAAc,SAAS,GAAG,QAAQ,EAAE,CAAC,GAC3D,MAA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;AAOA,SAAS,cACP,YACA,OAC4B;CAC5B,IAAI;CAEJ,eAAe,SAA6B;EAC1C,MAAM,SAAU,MAAM,WAAW,cAAc,KAAK;EACpD,IAAI,SAAS,UAAU,QAAQ;GAC7B,MAAM,WAAW;GACjB,UAAU;IAAE,OAAO;IAAQ,KAAK,OAAO,UAAU;GAAE;GACnD,UAAe,IAAI,MAChB,QAAQ,IAAI,QAAQ,SACf,KAAA,CACR;EACF;EACA,OAAO,QAAQ;CACjB;CAEA,QAAQ,KAAK,KAAK,SAAS;EACzB,OAAO,CAAC,CACL,MAAM,QAAQ,IAAI,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC,CACzC,OAAO,UAAiB;GACvB,WAAW,iBAAiB,KAAK;GACjC,KAAK,KAAK;EACZ,CAAC;CACL;AACF;AAEA,SAAS,sBAAsB,aAAmC;CAChE,YAAY,QAAQ,YAAY,MAAM,QACnC,UACC,CAAC,iBAAiB,SACf,MAAM,OAA6B,QAAQ,EAC9C,CACJ;AACF"}
|
|
@@ -65,7 +65,7 @@ function typedRoutes(options = {}) {
|
|
|
65
65
|
generate();
|
|
66
66
|
},
|
|
67
67
|
configResolved(config) {
|
|
68
|
-
const compiler = config.plugins.find((plugin) => plugin.name === "@analogjs/vite-plugin-angular" || plugin.name === "@analogjs/vite-plugin-angular-fast-compile" || plugin.name === "@analogjs/vite-plugin-angular-compilation-api");
|
|
68
|
+
const compiler = config.plugins.find((plugin) => plugin.name === "@analogjs/vite-plugin-angular" || plugin.name === "@analogjs/vite-plugin-angular-fast-compile" || plugin.name === "@analogjs/vite-plugin-angular-compilation-api" || plugin.name === "@analogjs/vite-plugin-angular-ngp");
|
|
69
69
|
getTsConfigPath = compiler?.api?.getTsConfigPath;
|
|
70
70
|
if (compiler && !getTsConfigPath) throw new Error("[analog] Typed routing requires a matching @analogjs/vite-plugin-angular version to verify the application tsconfig.");
|
|
71
71
|
verifyTypeInclusion();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typed-routes-plugin.js","names":[],"sources":["../../../src/lib/typed-routes-plugin.ts"],"sourcesContent":["import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';\nimport { dirname, join, relative, resolve } from 'node:path';\nimport { readConfiguration } from '@angular/compiler-cli';\nimport { parseSync } from 'oxc-parser';\nimport { normalizePath, type Plugin } from 'vite';\n\nimport {\n createRouteFileDiscovery,\n type RouteFileDiscovery,\n} from './route-file-discovery.js';\nimport {\n generateRouteManifest,\n generateRouteTableDeclaration,\n} from './route-manifest.js';\n\nexport interface TypedRoutingOptions {\n /** Generated declaration path (.d.ts), relative to the app root. */\n outFile?: string;\n /** Fail builds when a checked-in route table is stale. Defaults to true. */\n verifyOnBuild?: boolean;\n}\n\nexport interface TypedRoutesPluginOptions extends TypedRoutingOptions {\n workspaceRoot?: string;\n additionalPagesDirs?: string[];\n additionalContentDirs?: string[];\n}\n\nexport function typedRoutes(options: TypedRoutesPluginOptions = {}): Plugin {\n const workspaceRoot = normalizePath(options.workspaceRoot ?? process.cwd());\n const outFile = options.outFile ?? 'src/routeTree.gen.d.ts';\n if (!outFile.endsWith('.d.ts')) {\n throw new Error(\n '[analog] Typed routing outFile must end in .d.ts. Include this declaration in your application tsconfig.',\n );\n }\n let root: string;\n let command: 'build' | 'serve';\n let discovery: RouteFileDiscovery;\n\n let getTsConfigPath: (() => string) | undefined;\n\n function verifyTypeInclusion(): void {\n if (!getTsConfigPath) return;\n const tsconfig = getTsConfigPath();\n const { rootNames, errors } = readConfiguration(tsconfig);\n if (errors.length) {\n throw new Error(\n `[analog] Cannot verify typed routing: unable to read ${tsconfig}.`,\n );\n }\n const outputPath = normalizePath(resolve(root, outFile));\n if (\n !rootNames.some((file) => normalizePath(resolve(file)) === outputPath)\n ) {\n const declaration = normalizePath(\n relative(dirname(tsconfig), outputPath),\n );\n throw new Error(\n `[analog] Typed route declaration is not included in ${tsconfig}. Add \"${declaration}\" to its \"files\" or \"include\" list so typed routing is available to the compiler and editor.`,\n );\n }\n }\n\n function generate(): void {\n const manifest = generateRouteManifest(\n [...discovery.getRouteFiles(), ...discovery.getContentFiles()],\n (filename) => (discovery.isAppLocal(filename) ? 0 : 1),\n );\n const collisions = manifest.collisions.filter(\n (collision) => collision.samePriority,\n );\n if (command === 'build' && collisions.length) {\n throw new Error(\n `[analog] Route collisions detected: ${collisions.map((c) => `${c.fullPath}: ${c.keptFile}, ${c.droppedFile}`).join('; ')}`,\n );\n }\n const outputPath = join(root, outFile);\n const output = generateRouteTableDeclaration(manifest, (filename) => {\n const pageFile = [\n join(root, filename),\n join(workspaceRoot, filename),\n filename,\n ].find((file) => existsSync(file));\n if (!pageFile) return undefined;\n const serverFile = pageFile.replace(/\\.page\\.ts$/, '.server.ts');\n return {\n routeMeta: hasNamedExport(pageFile, 'routeMeta')\n ? toImportSpecifier(dirname(outputPath), pageFile)\n : undefined,\n load:\n serverFile !== pageFile &&\n existsSync(serverFile) &&\n hasNamedExport(serverFile, 'load')\n ? toImportSpecifier(dirname(outputPath), serverFile)\n : undefined,\n };\n });\n const exists = existsSync(outputPath);\n const current = exists ? readFileSync(outputPath, 'utf8') : '';\n if (current !== output && !sameDeclarations(current, output)) {\n if (exists && command === 'build' && (options.verifyOnBuild ?? true)) {\n throw new Error(\n `[analog] Stale route file: ${outFile}. Run the dev server to regenerate it before building.`,\n );\n }\n mkdirSync(dirname(outputPath), { recursive: true });\n writeFileSync(outputPath, output);\n }\n }\n\n return {\n name: 'analog-typed-routes',\n config(config, env) {\n command = env.command;\n root = normalizePath(resolve(workspaceRoot, config.root ?? '.'));\n discovery = createRouteFileDiscovery({\n root,\n workspaceRoot,\n additionalPagesDirs: options.additionalPagesDirs ?? [],\n additionalContentDirs: options.additionalContentDirs ?? [],\n });\n // Generate before Angular reads the application tsconfig.\n generate();\n },\n configResolved(config) {\n const compiler = config.plugins.find(\n (plugin) =>\n plugin.name === '@analogjs/vite-plugin-angular' ||\n plugin.name === '@analogjs/vite-plugin-angular-fast-compile' ||\n plugin.name === '@analogjs/vite-plugin-angular-compilation-api',\n );\n getTsConfigPath = compiler?.api?.getTsConfigPath;\n if (compiler && !getTsConfigPath) {\n throw new Error(\n '[analog] Typed routing requires a matching @analogjs/vite-plugin-angular version to verify the application tsconfig.',\n );\n }\n verifyTypeInclusion();\n },\n buildStart() {\n discovery.reset();\n generate();\n verifyTypeInclusion();\n },\n configureServer(server) {\n server.watcher.add(join(root, outFile));\n for (const event of ['add', 'change', 'unlink'] as const) {\n server.watcher.on(event, (path) => {\n if (!discovery.getDiscoveredFileKind(path)) return;\n discovery.updateDiscoveredFile(path, event);\n generate();\n });\n }\n },\n };\n}\n\nfunction toImportSpecifier(fromDir: string, file: string): string {\n const specifier = normalizePath(relative(fromDir, file)).replace(/\\.ts$/, '');\n return specifier.startsWith('.') ? specifier : `./${specifier}`;\n}\n\nfunction hasNamedExport(file: string, name: string): boolean {\n const source = readFileSync(file, 'utf8');\n if (!source.includes(name)) return false;\n const { program, errors } = parseSync(file, source);\n if (errors.length) return false;\n return program.body.some((statement) => {\n if (\n statement.type !== 'ExportNamedDeclaration' ||\n statement.exportKind === 'type'\n ) {\n return false;\n }\n const declaration = statement.declaration;\n if (declaration?.type === 'VariableDeclaration') {\n return declaration.declarations.some(\n (item) => item.id.type === 'Identifier' && item.id.name === name,\n );\n }\n if (declaration?.type === 'FunctionDeclaration') {\n return declaration.id?.name === name;\n }\n return statement.specifiers.some(\n (specifier) =>\n specifier.exportKind !== 'type' &&\n (specifier.exported.type === 'Identifier'\n ? specifier.exported.name\n : specifier.exported.value) === name,\n );\n });\n}\n\nfunction sameDeclarations(current: string, output: string): boolean {\n const left = parseSync('routeTree.gen.d.ts', current);\n const right = parseSync('routeTree.gen.d.ts', output);\n if (left.errors.length || right.errors.length) return false;\n const withoutFormatting = (key: string, value: unknown) =>\n key === 'start' || key === 'end' || key === 'raw' ? undefined : value;\n return (\n JSON.stringify(left.program, withoutFormatting) ===\n JSON.stringify(right.program, withoutFormatting)\n );\n}\n"],"mappings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,SAAS,QAAQ,QAAQ,KAAA,IAAY;CAClE,OACE,KAAK,UAAU,KAAK,SAAS,iBAAiB,MAC9C,KAAK,UAAU,MAAM,SAAS,iBAAiB;AAEnD"}
|
|
1
|
+
{"version":3,"file":"typed-routes-plugin.js","names":[],"sources":["../../../src/lib/typed-routes-plugin.ts"],"sourcesContent":["import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';\nimport { dirname, join, relative, resolve } from 'node:path';\nimport { readConfiguration } from '@angular/compiler-cli';\nimport { parseSync } from 'oxc-parser';\nimport { normalizePath, type Plugin } from 'vite';\n\nimport {\n createRouteFileDiscovery,\n type RouteFileDiscovery,\n} from './route-file-discovery.js';\nimport {\n generateRouteManifest,\n generateRouteTableDeclaration,\n} from './route-manifest.js';\n\nexport interface TypedRoutingOptions {\n /** Generated declaration path (.d.ts), relative to the app root. */\n outFile?: string;\n /** Fail builds when a checked-in route table is stale. Defaults to true. */\n verifyOnBuild?: boolean;\n}\n\nexport interface TypedRoutesPluginOptions extends TypedRoutingOptions {\n workspaceRoot?: string;\n additionalPagesDirs?: string[];\n additionalContentDirs?: string[];\n}\n\nexport function typedRoutes(options: TypedRoutesPluginOptions = {}): Plugin {\n const workspaceRoot = normalizePath(options.workspaceRoot ?? process.cwd());\n const outFile = options.outFile ?? 'src/routeTree.gen.d.ts';\n if (!outFile.endsWith('.d.ts')) {\n throw new Error(\n '[analog] Typed routing outFile must end in .d.ts. Include this declaration in your application tsconfig.',\n );\n }\n let root: string;\n let command: 'build' | 'serve';\n let discovery: RouteFileDiscovery;\n\n let getTsConfigPath: (() => string) | undefined;\n\n function verifyTypeInclusion(): void {\n if (!getTsConfigPath) return;\n const tsconfig = getTsConfigPath();\n const { rootNames, errors } = readConfiguration(tsconfig);\n if (errors.length) {\n throw new Error(\n `[analog] Cannot verify typed routing: unable to read ${tsconfig}.`,\n );\n }\n const outputPath = normalizePath(resolve(root, outFile));\n if (\n !rootNames.some((file) => normalizePath(resolve(file)) === outputPath)\n ) {\n const declaration = normalizePath(\n relative(dirname(tsconfig), outputPath),\n );\n throw new Error(\n `[analog] Typed route declaration is not included in ${tsconfig}. Add \"${declaration}\" to its \"files\" or \"include\" list so typed routing is available to the compiler and editor.`,\n );\n }\n }\n\n function generate(): void {\n const manifest = generateRouteManifest(\n [...discovery.getRouteFiles(), ...discovery.getContentFiles()],\n (filename) => (discovery.isAppLocal(filename) ? 0 : 1),\n );\n const collisions = manifest.collisions.filter(\n (collision) => collision.samePriority,\n );\n if (command === 'build' && collisions.length) {\n throw new Error(\n `[analog] Route collisions detected: ${collisions.map((c) => `${c.fullPath}: ${c.keptFile}, ${c.droppedFile}`).join('; ')}`,\n );\n }\n const outputPath = join(root, outFile);\n const output = generateRouteTableDeclaration(manifest, (filename) => {\n const pageFile = [\n join(root, filename),\n join(workspaceRoot, filename),\n filename,\n ].find((file) => existsSync(file));\n if (!pageFile) return undefined;\n const serverFile = pageFile.replace(/\\.page\\.ts$/, '.server.ts');\n return {\n routeMeta: hasNamedExport(pageFile, 'routeMeta')\n ? toImportSpecifier(dirname(outputPath), pageFile)\n : undefined,\n load:\n serverFile !== pageFile &&\n existsSync(serverFile) &&\n hasNamedExport(serverFile, 'load')\n ? toImportSpecifier(dirname(outputPath), serverFile)\n : undefined,\n };\n });\n const exists = existsSync(outputPath);\n const current = exists ? readFileSync(outputPath, 'utf8') : '';\n if (current !== output && !sameDeclarations(current, output)) {\n if (exists && command === 'build' && (options.verifyOnBuild ?? true)) {\n throw new Error(\n `[analog] Stale route file: ${outFile}. Run the dev server to regenerate it before building.`,\n );\n }\n mkdirSync(dirname(outputPath), { recursive: true });\n writeFileSync(outputPath, output);\n }\n }\n\n return {\n name: 'analog-typed-routes',\n config(config, env) {\n command = env.command;\n root = normalizePath(resolve(workspaceRoot, config.root ?? '.'));\n discovery = createRouteFileDiscovery({\n root,\n workspaceRoot,\n additionalPagesDirs: options.additionalPagesDirs ?? [],\n additionalContentDirs: options.additionalContentDirs ?? [],\n });\n // Generate before Angular reads the application tsconfig.\n generate();\n },\n configResolved(config) {\n const compiler = config.plugins.find(\n (plugin) =>\n plugin.name === '@analogjs/vite-plugin-angular' ||\n plugin.name === '@analogjs/vite-plugin-angular-fast-compile' ||\n plugin.name === '@analogjs/vite-plugin-angular-compilation-api' ||\n plugin.name === '@analogjs/vite-plugin-angular-ngp',\n );\n getTsConfigPath = compiler?.api?.getTsConfigPath;\n if (compiler && !getTsConfigPath) {\n throw new Error(\n '[analog] Typed routing requires a matching @analogjs/vite-plugin-angular version to verify the application tsconfig.',\n );\n }\n verifyTypeInclusion();\n },\n buildStart() {\n discovery.reset();\n generate();\n verifyTypeInclusion();\n },\n configureServer(server) {\n server.watcher.add(join(root, outFile));\n for (const event of ['add', 'change', 'unlink'] as const) {\n server.watcher.on(event, (path) => {\n if (!discovery.getDiscoveredFileKind(path)) return;\n discovery.updateDiscoveredFile(path, event);\n generate();\n });\n }\n },\n };\n}\n\nfunction toImportSpecifier(fromDir: string, file: string): string {\n const specifier = normalizePath(relative(fromDir, file)).replace(/\\.ts$/, '');\n return specifier.startsWith('.') ? specifier : `./${specifier}`;\n}\n\nfunction hasNamedExport(file: string, name: string): boolean {\n const source = readFileSync(file, 'utf8');\n if (!source.includes(name)) return false;\n const { program, errors } = parseSync(file, source);\n if (errors.length) return false;\n return program.body.some((statement) => {\n if (\n statement.type !== 'ExportNamedDeclaration' ||\n statement.exportKind === 'type'\n ) {\n return false;\n }\n const declaration = statement.declaration;\n if (declaration?.type === 'VariableDeclaration') {\n return declaration.declarations.some(\n (item) => item.id.type === 'Identifier' && item.id.name === name,\n );\n }\n if (declaration?.type === 'FunctionDeclaration') {\n return declaration.id?.name === name;\n }\n return statement.specifiers.some(\n (specifier) =>\n specifier.exportKind !== 'type' &&\n (specifier.exported.type === 'Identifier'\n ? specifier.exported.name\n : specifier.exported.value) === name,\n );\n });\n}\n\nfunction sameDeclarations(current: string, output: string): boolean {\n const left = parseSync('routeTree.gen.d.ts', current);\n const right = parseSync('routeTree.gen.d.ts', output);\n if (left.errors.length || right.errors.length) return false;\n const withoutFormatting = (key: string, value: unknown) =>\n key === 'start' || key === 'end' || key === 'raw' ? undefined : value;\n return (\n JSON.stringify(left.program, withoutFormatting) ===\n JSON.stringify(right.program, withoutFormatting)\n );\n}\n"],"mappings":";;;;;;;;AA4BA,SAAgB,YAAY,UAAoC,CAAC,GAAW;CAC1E,MAAM,gBAAgB,cAAc,QAAQ,iBAAiB,QAAQ,IAAI,CAAC;CAC1E,MAAM,UAAU,QAAQ,WAAW;CACnC,IAAI,CAAC,QAAQ,SAAS,OAAO,GAC3B,MAAM,IAAI,MACR,0GACF;CAEF,IAAI;CACJ,IAAI;CACJ,IAAI;CAEJ,IAAI;CAEJ,SAAS,sBAA4B;EACnC,IAAI,CAAC,iBAAiB;EACtB,MAAM,WAAW,gBAAgB;EACjC,MAAM,EAAE,WAAW,WAAW,kBAAkB,QAAQ;EACxD,IAAI,OAAO,QACT,MAAM,IAAI,MACR,wDAAwD,SAAS,EACnE;EAEF,MAAM,aAAa,cAAc,QAAQ,MAAM,OAAO,CAAC;EACvD,IACE,CAAC,UAAU,MAAM,SAAS,cAAc,QAAQ,IAAI,CAAC,MAAM,UAAU,GACrE;GACA,MAAM,cAAc,cAClB,SAAS,QAAQ,QAAQ,GAAG,UAAU,CACxC;GACA,MAAM,IAAI,MACR,uDAAuD,SAAS,SAAS,YAAY,6FACvF;EACF;CACF;CAEA,SAAS,WAAiB;EACxB,MAAM,WAAW,sBACf,CAAC,GAAG,UAAU,cAAc,GAAG,GAAG,UAAU,gBAAgB,CAAC,IAC5D,aAAc,UAAU,WAAW,QAAQ,IAAI,IAAI,CACtD;EACA,MAAM,aAAa,SAAS,WAAW,QACpC,cAAc,UAAU,YAC3B;EACA,IAAI,YAAY,WAAW,WAAW,QACpC,MAAM,IAAI,MACR,uCAAuC,WAAW,KAAK,MAAM,GAAG,EAAE,SAAS,IAAI,EAAE,SAAS,IAAI,EAAE,aAAa,CAAC,CAAC,K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AAiB,SAAiB,QAAyB;CAClE,MAAM,OAAO,UAAU,sBAAsB,OAAO;CACpD,MAAM,QAAQ,UAAU,sBAAsB,MAAM;CACpD,IAAI,KAAK,OAAO,UAAU,MAAM,OAAO,QAAQ,OAAO;CACtD,MAAM,qBAAqB,KAAa,UACtC,QAAQ,WAAW,QAAQ,SAAS,QAAQ,QAAQ,KAAA,IAAY;CAClE,OACE,KAAK,UAAU,KAAK,SAAS,iBAAiB,MAC9C,KAAK,UAAU,MAAM,SAAS,iBAAiB;AAEnD"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
const require_src_executors_vite_dev_server_vite_dev_server_impl = require("./vite-dev-server.impl.js");
|
|
2
|
-
//#region packages/nx-plugin/src/executors/vite-dev-server/compat.ts
|
|
3
|
-
var compat = (0, require("@nx/devkit").convertNxExecutor)(require_src_executors_vite_dev_server_vite_dev_server_impl);
|
|
4
|
-
//#endregion
|
|
5
|
-
module.exports = compat;
|
|
6
|
-
|
|
7
|
-
//# sourceMappingURL=compat.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compat.js","names":[],"sources":["../../../../../../../../nx-plugin/src/executors/vite-dev-server/compat.ts"],"sourcesContent":["import { convertNxExecutor } from '@nx/devkit';\n\nimport viteDevServerExecutor from './vite-dev-server.impl';\n\nconst compat: ReturnType<typeof convertNxExecutor> = convertNxExecutor(\n viteDevServerExecutor,\n);\nexport default compat;\n"],"mappings":";;AAIA,IAAM,UAAA,uBAA+C,CAAA,CAAA,kBAAA,CACnD,0DACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type { ViteDevServerExecutorOptions } from '@nx/vite/executors';
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 2,
|
|
3
|
-
"outputCapture": "direct-nodejs",
|
|
4
|
-
"title": "Vite Dev Server",
|
|
5
|
-
"cli": "nx",
|
|
6
|
-
"description": "Starts a dev server using Vite.",
|
|
7
|
-
"type": "object",
|
|
8
|
-
"presets": [
|
|
9
|
-
{
|
|
10
|
-
"name": "Default minimum setup",
|
|
11
|
-
"keys": ["buildTarget"]
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
"name": "Using a Different Port",
|
|
15
|
-
"keys": ["buildTarget", "port"]
|
|
16
|
-
}
|
|
17
|
-
],
|
|
18
|
-
"properties": {
|
|
19
|
-
"buildTarget": {
|
|
20
|
-
"type": "string",
|
|
21
|
-
"description": "Target which builds the application. Only used to retrieve the configuration as the dev-server does not build the code.",
|
|
22
|
-
"x-priority": "important"
|
|
23
|
-
},
|
|
24
|
-
"buildLibsFromSource": {
|
|
25
|
-
"type": "boolean",
|
|
26
|
-
"description": "Read buildable libraries from source instead of building them separately.",
|
|
27
|
-
"default": true
|
|
28
|
-
},
|
|
29
|
-
"proxyConfig": {
|
|
30
|
-
"type": "string",
|
|
31
|
-
"description": "Path to the proxy configuration file.",
|
|
32
|
-
"x-completion-type": "file"
|
|
33
|
-
},
|
|
34
|
-
"port": {
|
|
35
|
-
"type": "number",
|
|
36
|
-
"description": "Port to listen on.",
|
|
37
|
-
"x-priority": "important"
|
|
38
|
-
},
|
|
39
|
-
"host": {
|
|
40
|
-
"description": "Specify which IP addresses the server should listen on.",
|
|
41
|
-
"oneOf": [
|
|
42
|
-
{
|
|
43
|
-
"type": "boolean"
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
"type": "string"
|
|
47
|
-
}
|
|
48
|
-
]
|
|
49
|
-
},
|
|
50
|
-
"https": {
|
|
51
|
-
"oneOf": [
|
|
52
|
-
{
|
|
53
|
-
"type": "boolean"
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
"type": "object"
|
|
57
|
-
}
|
|
58
|
-
],
|
|
59
|
-
"description": "Serve using HTTPS. https://vitejs.dev/config/server-options.html#server-https"
|
|
60
|
-
},
|
|
61
|
-
"hmr": {
|
|
62
|
-
"description": "Enable hot module replacement. For more options, use the 'hmr' option in the Vite configuration file.",
|
|
63
|
-
"type": "boolean"
|
|
64
|
-
},
|
|
65
|
-
"open": {
|
|
66
|
-
"description": "Automatically open the app in the browser on server start. When the value is a string, it will be used as the URL's pathname.",
|
|
67
|
-
"oneOf": [
|
|
68
|
-
{
|
|
69
|
-
"type": "boolean"
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
"type": "string"
|
|
73
|
-
}
|
|
74
|
-
]
|
|
75
|
-
},
|
|
76
|
-
"cors": {
|
|
77
|
-
"description": "Configure CORS for the dev server.",
|
|
78
|
-
"type": "boolean"
|
|
79
|
-
},
|
|
80
|
-
"logLevel": {
|
|
81
|
-
"type": "string",
|
|
82
|
-
"description": "Adjust console output verbosity.",
|
|
83
|
-
"enum": ["info", "warn", "error", "silent"]
|
|
84
|
-
},
|
|
85
|
-
"mode": {
|
|
86
|
-
"type": "string",
|
|
87
|
-
"description": "Mode to run the server in."
|
|
88
|
-
},
|
|
89
|
-
"clearScreen": {
|
|
90
|
-
"description": "Set to false to prevent Vite from clearing the terminal screen when logging certain messages.",
|
|
91
|
-
"type": "boolean"
|
|
92
|
-
},
|
|
93
|
-
"force": {
|
|
94
|
-
"description": "Force the optimizer to ignore the cache and re-bundle",
|
|
95
|
-
"type": "boolean"
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
"definitions": {},
|
|
99
|
-
"required": ["buildTarget"],
|
|
100
|
-
"examplesFile": "../../../docs/dev-server-examples.md"
|
|
101
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
//#region packages/nx-plugin/src/executors/vite-dev-server/vite-dev-server.impl.ts
|
|
2
|
-
var vite_dev_server_impl_default = require("@nx/vite/executors").viteDevServerExecutor;
|
|
3
|
-
//#endregion
|
|
4
|
-
module.exports = vite_dev_server_impl_default;
|
|
5
|
-
|
|
6
|
-
//# sourceMappingURL=vite-dev-server.impl.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vite-dev-server.impl.js","names":[],"sources":["../../../../../../../../nx-plugin/src/executors/vite-dev-server/vite-dev-server.impl.ts"],"sourcesContent":["import { viteDevServerExecutor } from '@nx/vite/executors';\n\nexport default viteDevServerExecutor;\n"],"mappings":";AAEA,IAAA,2DAAe,CAAA,CAAA"}
|