@analogjs/vite-plugin-angular 3.0.0-alpha.7 → 3.0.0-alpha.9

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 (54) hide show
  1. package/package.json +7 -9
  2. package/setup-vitest.js +154 -193
  3. package/setup-vitest.js.map +1 -1
  4. package/src/index.d.ts +1 -1
  5. package/src/index.js +6 -2
  6. package/src/index.js.map +1 -1
  7. package/src/lib/angular-build-optimizer-plugin.js +48 -62
  8. package/src/lib/angular-build-optimizer-plugin.js.map +1 -1
  9. package/src/lib/angular-jit-plugin.js +31 -37
  10. package/src/lib/angular-jit-plugin.js.map +1 -1
  11. package/src/lib/angular-pending-tasks.plugin.js +17 -18
  12. package/src/lib/angular-pending-tasks.plugin.js.map +1 -1
  13. package/src/lib/angular-vite-plugin.js +790 -1076
  14. package/src/lib/angular-vite-plugin.js.map +1 -1
  15. package/src/lib/angular-vitest-plugin.d.ts +16 -12
  16. package/src/lib/angular-vitest-plugin.js +97 -114
  17. package/src/lib/angular-vitest-plugin.js.map +1 -1
  18. package/src/lib/compiler-plugin.js +40 -44
  19. package/src/lib/compiler-plugin.js.map +1 -1
  20. package/src/lib/component-resolvers.d.ts +4 -2
  21. package/src/lib/component-resolvers.js +93 -64
  22. package/src/lib/component-resolvers.js.map +1 -1
  23. package/src/lib/host.js +69 -101
  24. package/src/lib/host.js.map +1 -1
  25. package/src/lib/live-reload-plugin.js +51 -63
  26. package/src/lib/live-reload-plugin.js.map +1 -1
  27. package/src/lib/nx-folder-plugin.js +18 -16
  28. package/src/lib/nx-folder-plugin.js.map +1 -1
  29. package/src/lib/plugins/file-replacements.plugin.js +35 -62
  30. package/src/lib/plugins/file-replacements.plugin.js.map +1 -1
  31. package/src/lib/router-plugin.js +23 -23
  32. package/src/lib/router-plugin.js.map +1 -1
  33. package/src/lib/tools/package.json +2 -5
  34. package/src/lib/tools/src/builders/vite/vite-build.impl.js +31 -38
  35. package/src/lib/tools/src/builders/vite/vite-build.impl.js.map +1 -1
  36. package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js +52 -60
  37. package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js.map +1 -1
  38. package/src/lib/tools/src/index.js +0 -2
  39. package/src/lib/utils/devkit.js +34 -38
  40. package/src/lib/utils/devkit.js.map +1 -1
  41. package/src/lib/utils/rolldown.d.ts +2 -0
  42. package/src/lib/utils/rolldown.js +12 -0
  43. package/src/lib/utils/rolldown.js.map +1 -0
  44. package/src/lib/utils/source-file-cache.js +35 -37
  45. package/src/lib/utils/source-file-cache.js.map +1 -1
  46. package/README.md +0 -91
  47. package/src/lib/models.js +0 -1
  48. package/src/lib/models.js.map +0 -1
  49. package/src/lib/tools/README.md +0 -3
  50. package/src/lib/tools/src/index.js.map +0 -1
  51. package/src/lib/utils/compiler-plugin-options.js +0 -1
  52. package/src/lib/utils/compiler-plugin-options.js.map +0 -1
  53. package/src/lib/utils/hmr-candidates.js +0 -272
  54. package/src/lib/utils/hmr-candidates.js.map +0 -1
@@ -1,65 +1,53 @@
1
- import { resolve } from 'node:path';
2
- import { normalizePath } from 'vite';
3
- const ANGULAR_COMPONENT_PREFIX = '/@ng/component';
4
- const FILE_PREFIX = 'file:';
5
- export function liveReloadPlugin({ classNames, fileEmitter, }) {
6
- return {
7
- name: 'analogjs-live-reload-plugin',
8
- apply: 'serve',
9
- configureServer(server) {
10
- const angularComponentMiddleware = async (req, res, next) => {
11
- if (req.url === undefined || res.writableEnded) {
12
- return;
13
- }
14
- if (!req.url.includes(ANGULAR_COMPONENT_PREFIX)) {
15
- next();
16
- return;
17
- }
18
- const requestUrl = new URL(req.url, 'http://localhost');
19
- const componentId = requestUrl.searchParams.get('c');
20
- if (!componentId) {
21
- res.statusCode = 400;
22
- res.end();
23
- return;
24
- }
25
- const [fileId] = decodeURIComponent(componentId).split('@');
26
- const resolvedId = normalizePath(resolve(process.cwd(), fileId));
27
- const invalidated = !!server.moduleGraph.getModuleById(resolvedId)
28
- ?.lastInvalidationTimestamp && classNames.get(resolvedId);
29
- // don't send an HMR update until the file has been invalidated
30
- if (!invalidated) {
31
- res.setHeader('Content-Type', 'text/javascript');
32
- res.setHeader('Cache-Control', 'no-cache');
33
- res.end('');
34
- return;
35
- }
36
- const result = fileEmitter(resolvedId);
37
- res.setHeader('Content-Type', 'text/javascript');
38
- res.setHeader('Cache-Control', 'no-cache');
39
- res.end(`${result?.hmrUpdateCode || ''}`);
40
- };
41
- server.middlewares.use(angularComponentMiddleware);
42
- },
43
- resolveId(id, _importer, options) {
44
- if (options?.ssr &&
45
- id.startsWith(FILE_PREFIX) &&
46
- id.includes(ANGULAR_COMPONENT_PREFIX)) {
47
- return `\0${id}`;
48
- }
49
- return undefined;
50
- },
51
- load(id, options) {
52
- if (options?.ssr && id.includes(ANGULAR_COMPONENT_PREFIX)) {
53
- const requestUrl = new URL(id.slice(1), 'http://localhost');
54
- const componentId = requestUrl.searchParams.get('c');
55
- if (!componentId) {
56
- return;
57
- }
58
- const result = fileEmitter(normalizePath(resolve(process.cwd(), decodeURIComponent(componentId).split('@')[0])));
59
- return result?.hmrUpdateCode || '';
60
- }
61
- return;
62
- },
63
- };
1
+ import { resolve } from "node:path";
2
+ import { normalizePath } from "vite";
3
+ //#region packages/vite-plugin-angular/src/lib/live-reload-plugin.ts
4
+ var ANGULAR_COMPONENT_PREFIX = "/@ng/component";
5
+ var FILE_PREFIX = "file:";
6
+ function liveReloadPlugin({ classNames, fileEmitter }) {
7
+ return {
8
+ name: "analogjs-live-reload-plugin",
9
+ apply: "serve",
10
+ configureServer(server) {
11
+ const angularComponentMiddleware = async (req, res, next) => {
12
+ if (req.url === void 0 || res.writableEnded) return;
13
+ if (!req.url.includes(ANGULAR_COMPONENT_PREFIX)) {
14
+ next();
15
+ return;
16
+ }
17
+ const componentId = new URL(req.url, "http://localhost").searchParams.get("c");
18
+ if (!componentId) {
19
+ res.statusCode = 400;
20
+ res.end();
21
+ return;
22
+ }
23
+ const [fileId] = decodeURIComponent(componentId).split("@");
24
+ const resolvedId = normalizePath(resolve(process.cwd(), fileId));
25
+ if (!(!!server.moduleGraph.getModuleById(resolvedId)?.lastInvalidationTimestamp && classNames.get(resolvedId))) {
26
+ res.setHeader("Content-Type", "text/javascript");
27
+ res.setHeader("Cache-Control", "no-cache");
28
+ res.end("");
29
+ return;
30
+ }
31
+ const result = fileEmitter(resolvedId);
32
+ res.setHeader("Content-Type", "text/javascript");
33
+ res.setHeader("Cache-Control", "no-cache");
34
+ res.end(`${result?.hmrUpdateCode || ""}`);
35
+ };
36
+ server.middlewares.use(angularComponentMiddleware);
37
+ },
38
+ resolveId(id, _importer, options) {
39
+ if (options?.ssr && id.startsWith(FILE_PREFIX) && id.includes(ANGULAR_COMPONENT_PREFIX)) return `\0${id}`;
40
+ },
41
+ load(id, options) {
42
+ if (options?.ssr && id.includes(ANGULAR_COMPONENT_PREFIX)) {
43
+ const componentId = new URL(id.slice(1), "http://localhost").searchParams.get("c");
44
+ if (!componentId) return;
45
+ return fileEmitter(normalizePath(resolve(process.cwd(), decodeURIComponent(componentId).split("@")[0])))?.hmrUpdateCode || "";
46
+ }
47
+ }
48
+ };
64
49
  }
50
+ //#endregion
51
+ export { liveReloadPlugin };
52
+
65
53
  //# sourceMappingURL=live-reload-plugin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"live-reload-plugin.js","sourceRoot":"","sources":["../../../../../packages/vite-plugin-angular/src/lib/live-reload-plugin.ts"],"names":[],"mappings":"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"}
1
+ {"version":3,"file":"live-reload-plugin.js","names":[],"sources":["../../../../../packages/vite-plugin-angular/src/lib/live-reload-plugin.ts"],"sourcesContent":["import { resolve } from 'node:path';\nimport { ServerResponse } from 'node:http';\nimport { Connect, normalizePath, Plugin, ViteDevServer } from 'vite';\n\nimport { EmitFileResult } from './models.js';\n\nconst ANGULAR_COMPONENT_PREFIX = '/@ng/component';\nconst FILE_PREFIX = 'file:';\n\nexport function liveReloadPlugin({\n classNames,\n fileEmitter,\n}: {\n classNames: Map<string, string>;\n fileEmitter: (file: string) => EmitFileResult | undefined;\n}): Plugin {\n return {\n name: 'analogjs-live-reload-plugin',\n apply: 'serve',\n configureServer(server: ViteDevServer) {\n const angularComponentMiddleware: Connect.HandleFunction = async (\n req: Connect.IncomingMessage,\n res: ServerResponse<Connect.IncomingMessage>,\n next: Connect.NextFunction,\n ) => {\n if (req.url === undefined || res.writableEnded) {\n return;\n }\n\n if (!req.url.includes(ANGULAR_COMPONENT_PREFIX)) {\n next();\n\n return;\n }\n\n const requestUrl = new URL(req.url, 'http://localhost');\n const componentId = requestUrl.searchParams.get('c');\n\n if (!componentId) {\n res.statusCode = 400;\n res.end();\n\n return;\n }\n\n const [fileId] = decodeURIComponent(componentId).split('@');\n const resolvedId = normalizePath(resolve(process.cwd(), fileId));\n const invalidated =\n !!server.moduleGraph.getModuleById(resolvedId)\n ?.lastInvalidationTimestamp && classNames.get(resolvedId);\n\n // don't send an HMR update until the file has been invalidated\n if (!invalidated) {\n res.setHeader('Content-Type', 'text/javascript');\n res.setHeader('Cache-Control', 'no-cache');\n res.end('');\n return;\n }\n\n const result = fileEmitter(resolvedId);\n res.setHeader('Content-Type', 'text/javascript');\n res.setHeader('Cache-Control', 'no-cache');\n res.end(`${result?.hmrUpdateCode || ''}`);\n };\n\n server.middlewares.use(angularComponentMiddleware);\n },\n resolveId(id, _importer, options) {\n if (\n options?.ssr &&\n id.startsWith(FILE_PREFIX) &&\n id.includes(ANGULAR_COMPONENT_PREFIX)\n ) {\n return `\\0${id}`;\n }\n\n return undefined;\n },\n load(id, options) {\n if (options?.ssr && id.includes(ANGULAR_COMPONENT_PREFIX)) {\n const requestUrl = new URL(id.slice(1), 'http://localhost');\n const componentId = requestUrl.searchParams.get('c');\n\n if (!componentId) {\n return;\n }\n\n const result = fileEmitter(\n normalizePath(\n resolve(\n process.cwd(),\n decodeURIComponent(componentId).split('@')[0],\n ),\n ),\n );\n\n return result?.hmrUpdateCode || '';\n }\n\n return;\n },\n };\n}\n"],"mappings":";;;AAMA,IAAM,2BAA2B;AACjC,IAAM,cAAc;AAEpB,SAAgB,iBAAiB,EAC/B,YACA,eAIS;AACT,QAAO;EACL,MAAM;EACN,OAAO;EACP,gBAAgB,QAAuB;GACrC,MAAM,6BAAqD,OACzD,KACA,KACA,SACG;AACH,QAAI,IAAI,QAAQ,KAAA,KAAa,IAAI,cAC/B;AAGF,QAAI,CAAC,IAAI,IAAI,SAAS,yBAAyB,EAAE;AAC/C,WAAM;AAEN;;IAIF,MAAM,cADa,IAAI,IAAI,IAAI,KAAK,mBAAmB,CACxB,aAAa,IAAI,IAAI;AAEpD,QAAI,CAAC,aAAa;AAChB,SAAI,aAAa;AACjB,SAAI,KAAK;AAET;;IAGF,MAAM,CAAC,UAAU,mBAAmB,YAAY,CAAC,MAAM,IAAI;IAC3D,MAAM,aAAa,cAAc,QAAQ,QAAQ,KAAK,EAAE,OAAO,CAAC;AAMhE,QAAI,EAJF,CAAC,CAAC,OAAO,YAAY,cAAc,WAAW,EAC1C,6BAA6B,WAAW,IAAI,WAAW,GAG3C;AAChB,SAAI,UAAU,gBAAgB,kBAAkB;AAChD,SAAI,UAAU,iBAAiB,WAAW;AAC1C,SAAI,IAAI,GAAG;AACX;;IAGF,MAAM,SAAS,YAAY,WAAW;AACtC,QAAI,UAAU,gBAAgB,kBAAkB;AAChD,QAAI,UAAU,iBAAiB,WAAW;AAC1C,QAAI,IAAI,GAAG,QAAQ,iBAAiB,KAAK;;AAG3C,UAAO,YAAY,IAAI,2BAA2B;;EAEpD,UAAU,IAAI,WAAW,SAAS;AAChC,OACE,SAAS,OACT,GAAG,WAAW,YAAY,IAC1B,GAAG,SAAS,yBAAyB,CAErC,QAAO,KAAK;;EAKhB,KAAK,IAAI,SAAS;AAChB,OAAI,SAAS,OAAO,GAAG,SAAS,yBAAyB,EAAE;IAEzD,MAAM,cADa,IAAI,IAAI,GAAG,MAAM,EAAE,EAAE,mBAAmB,CAC5B,aAAa,IAAI,IAAI;AAEpD,QAAI,CAAC,YACH;AAYF,WATe,YACb,cACE,QACE,QAAQ,KAAK,EACb,mBAAmB,YAAY,CAAC,MAAM,IAAI,CAAC,GAC5C,CACF,CACF,EAEc,iBAAiB;;;EAKrC"}
@@ -1,19 +1,21 @@
1
- import { normalizePath } from 'vite';
1
+ import { normalizePath } from "vite";
2
+ //#region packages/vite-plugin-angular/src/lib/nx-folder-plugin.ts
2
3
  /**
3
- * Ignores anything in the .nx folder from triggering HMR
4
- *
5
- * @returns
6
- */
7
- export function nxFolderPlugin() {
8
- return {
9
- name: 'analogjs-nx-folder-plugin',
10
- apply: 'serve',
11
- handleHotUpdate(ctx) {
12
- if (ctx.file.includes(normalizePath('/.nx/'))) {
13
- return [];
14
- }
15
- return ctx.modules;
16
- },
17
- };
4
+ * Ignores anything in the .nx folder from triggering HMR
5
+ *
6
+ * @returns
7
+ */
8
+ function nxFolderPlugin() {
9
+ return {
10
+ name: "analogjs-nx-folder-plugin",
11
+ apply: "serve",
12
+ handleHotUpdate(ctx) {
13
+ if (ctx.file.includes(normalizePath("/.nx/"))) return [];
14
+ return ctx.modules;
15
+ }
16
+ };
18
17
  }
18
+ //#endregion
19
+ export { nxFolderPlugin };
20
+
19
21
  //# sourceMappingURL=nx-folder-plugin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"nx-folder-plugin.js","sourceRoot":"","sources":["../../../../../packages/vite-plugin-angular/src/lib/nx-folder-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAU,MAAM,MAAM,CAAC;AAE7C;;;;GAIG;AACH,MAAM,UAAU,cAAc;IAC5B,OAAO;QACL,IAAI,EAAE,2BAA2B;QACjC,KAAK,EAAE,OAAO;QACd,eAAe,CAAC,GAAG;YACjB,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC;gBAC9C,OAAO,EAAE,CAAC;YACZ,CAAC;YAED,OAAO,GAAG,CAAC,OAAO,CAAC;QACrB,CAAC;KACF,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"nx-folder-plugin.js","names":[],"sources":["../../../../../packages/vite-plugin-angular/src/lib/nx-folder-plugin.ts"],"sourcesContent":["import { normalizePath, Plugin } from 'vite';\n\n/**\n * Ignores anything in the .nx folder from triggering HMR\n *\n * @returns\n */\nexport function nxFolderPlugin(): Plugin {\n return {\n name: 'analogjs-nx-folder-plugin',\n apply: 'serve',\n handleHotUpdate(ctx) {\n if (ctx.file.includes(normalizePath('/.nx/'))) {\n return [];\n }\n\n return ctx.modules;\n },\n };\n}\n"],"mappings":";;;;;;;AAOA,SAAgB,iBAAyB;AACvC,QAAO;EACL,MAAM;EACN,OAAO;EACP,gBAAgB,KAAK;AACnB,OAAI,IAAI,KAAK,SAAS,cAAc,QAAQ,CAAC,CAC3C,QAAO,EAAE;AAGX,UAAO,IAAI;;EAEd"}
@@ -1,64 +1,37 @@
1
- // source: https://github.com/Myrmod/vitejs-theming/blob/master/build-plugins/rollup/replace-files.js
2
- import { isAbsolute, resolve } from 'node:path';
3
- export function replaceFiles(replacements, workspaceRoot) {
4
- if (!replacements?.length) {
5
- return false;
6
- }
7
- return {
8
- name: 'rollup-plugin-replace-files',
9
- enforce: 'pre',
10
- async resolveId(source, importer, options) {
11
- const resolved = await this.resolve(source, importer, {
12
- ...options,
13
- skipSelf: true,
14
- });
15
- /**
16
- * The reason we're using endsWith here is because the resolved id
17
- * will be the absolute path to the file. We want to check if the
18
- * file ends with the file we're trying to replace, which will be essentially
19
- * the path from the root of our workspace.
20
- */
21
- const mappedReplacements = replacements.map((fr) => {
22
- const frSSR = fr;
23
- const frWith = fr;
24
- return {
25
- ...fr,
26
- ssr: frSSR.ssr
27
- ? isAbsolute(frSSR.ssr)
28
- ? frSSR.ssr
29
- : resolve(workspaceRoot, frSSR.ssr)
30
- : '',
31
- with: frWith.with
32
- ? isAbsolute(frWith.with)
33
- ? frWith.with
34
- : resolve(workspaceRoot, frWith.with)
35
- : '',
36
- };
37
- });
38
- const foundReplace = mappedReplacements.find((replacement) => resolved?.id?.endsWith(replacement.replace));
39
- if (foundReplace) {
40
- try {
41
- if (this.environment.name === 'ssr' && foundReplace.ssr) {
42
- // return new file id for ssr
43
- return {
44
- id: foundReplace.ssr,
45
- };
46
- }
47
- else if (foundReplace.ssr) {
48
- return null;
49
- }
50
- // return new file id
51
- return {
52
- id: foundReplace.with,
53
- };
54
- }
55
- catch (err) {
56
- console.error(err);
57
- return null;
58
- }
59
- }
60
- return null;
61
- },
62
- };
1
+ import { isAbsolute, resolve } from "node:path";
2
+ //#region packages/vite-plugin-angular/src/lib/plugins/file-replacements.plugin.ts
3
+ function replaceFiles(replacements, workspaceRoot) {
4
+ if (!replacements?.length) return false;
5
+ return {
6
+ name: "rollup-plugin-replace-files",
7
+ enforce: "pre",
8
+ async resolveId(source, importer, options) {
9
+ const resolved = await this.resolve(source, importer, {
10
+ ...options,
11
+ skipSelf: true
12
+ });
13
+ const foundReplace = replacements.map((fr) => {
14
+ const frSSR = fr;
15
+ const frWith = fr;
16
+ return {
17
+ ...fr,
18
+ ssr: frSSR.ssr ? isAbsolute(frSSR.ssr) ? frSSR.ssr : resolve(workspaceRoot, frSSR.ssr) : "",
19
+ with: frWith.with ? isAbsolute(frWith.with) ? frWith.with : resolve(workspaceRoot, frWith.with) : ""
20
+ };
21
+ }).find((replacement) => resolved?.id?.endsWith(replacement.replace));
22
+ if (foundReplace) try {
23
+ if (this.environment.name === "ssr" && foundReplace.ssr) return { id: foundReplace.ssr };
24
+ else if (foundReplace.ssr) return null;
25
+ return { id: foundReplace.with };
26
+ } catch (err) {
27
+ console.error(err);
28
+ return null;
29
+ }
30
+ return null;
31
+ }
32
+ };
63
33
  }
34
+ //#endregion
35
+ export { replaceFiles };
36
+
64
37
  //# sourceMappingURL=file-replacements.plugin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"file-replacements.plugin.js","sourceRoot":"","sources":["../../../../../../packages/vite-plugin-angular/src/lib/plugins/file-replacements.plugin.ts"],"names":[],"mappings":"AAAA,qGAAqG;AACrG,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGhD,MAAM,UAAU,YAAY,CAC1B,YAA+B,EAC/B,aAAqB;IAErB,IAAI,CAAC,YAAY,EAAE,MAAM,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO;QACL,IAAI,EAAE,6BAA6B;QACnC,OAAO,EAAE,KAAK;QACd,KAAK,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO;YACvC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE;gBACpD,GAAG,OAAO;gBACV,QAAQ,EAAE,IAAI;aACf,CAAC,CAAC;YACH;;;;;eAKG;YACH,MAAM,kBAAkB,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,EAAmB,EAAE,EAAE;gBAClE,MAAM,KAAK,GAAG,EAAwB,CAAC;gBACvC,MAAM,MAAM,GAAG,EAAyB,CAAC;gBAEzC,OAAO;oBACL,GAAG,EAAE;oBACL,GAAG,EAAE,KAAK,CAAC,GAAG;wBACZ,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC;4BACrB,CAAC,CAAC,KAAK,CAAC,GAAG;4BACX,CAAC,CAAC,OAAO,CAAC,aAAa,EAAE,KAAK,CAAC,GAAG,CAAC;wBACrC,CAAC,CAAC,EAAE;oBACN,IAAI,EAAE,MAAM,CAAC,IAAI;wBACf,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC;4BACvB,CAAC,CAAC,MAAM,CAAC,IAAI;4BACb,CAAC,CAAC,OAAO,CAAC,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC;wBACvC,CAAC,CAAC,EAAE;iBACP,CAAC;YACJ,CAAC,CAAC,CAAC;YACH,MAAM,YAAY,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAC3D,QAAQ,EAAE,EAAE,EAAE,QAAQ,CAAC,WAAW,CAAC,OAAO,CAAC,CAC5C,CAAC;YACF,IAAI,YAAY,EAAE,CAAC;gBACjB,IAAI,CAAC;oBACH,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,KAAK,KAAK,IAAI,YAAY,CAAC,GAAG,EAAE,CAAC;wBACxD,6BAA6B;wBAC7B,OAAO;4BACL,EAAE,EAAE,YAAY,CAAC,GAAG;yBACrB,CAAC;oBACJ,CAAC;yBAAM,IAAI,YAAY,CAAC,GAAG,EAAE,CAAC;wBAC5B,OAAO,IAAI,CAAC;oBACd,CAAC;oBAED,qBAAqB;oBACrB,OAAO;wBACL,EAAE,EAAE,YAAY,CAAC,IAAI;qBACtB,CAAC;gBACJ,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;oBACnB,OAAO,IAAI,CAAC;gBACd,CAAC;YACH,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"file-replacements.plugin.js","names":[],"sources":["../../../../../../packages/vite-plugin-angular/src/lib/plugins/file-replacements.plugin.ts"],"sourcesContent":["// source: https://github.com/Myrmod/vitejs-theming/blob/master/build-plugins/rollup/replace-files.js\nimport { isAbsolute, resolve } from 'node:path';\nimport { Plugin } from 'vite';\n\nexport function replaceFiles(\n replacements: FileReplacement[],\n workspaceRoot: string,\n): Plugin | false {\n if (!replacements?.length) {\n return false;\n }\n\n return {\n name: 'rollup-plugin-replace-files',\n enforce: 'pre',\n async resolveId(source, importer, options) {\n const resolved = await this.resolve(source, importer, {\n ...options,\n skipSelf: true,\n });\n /**\n * The reason we're using endsWith here is because the resolved id\n * will be the absolute path to the file. We want to check if the\n * file ends with the file we're trying to replace, which will be essentially\n * the path from the root of our workspace.\n */\n const mappedReplacements = replacements.map((fr: FileReplacement) => {\n const frSSR = fr as FileReplacementSSR;\n const frWith = fr as FileReplacementWith;\n\n return {\n ...fr,\n ssr: frSSR.ssr\n ? isAbsolute(frSSR.ssr)\n ? frSSR.ssr\n : resolve(workspaceRoot, frSSR.ssr)\n : '',\n with: frWith.with\n ? isAbsolute(frWith.with)\n ? frWith.with\n : resolve(workspaceRoot, frWith.with)\n : '',\n };\n });\n const foundReplace = mappedReplacements.find((replacement) =>\n resolved?.id?.endsWith(replacement.replace),\n );\n if (foundReplace) {\n try {\n if (this.environment.name === 'ssr' && foundReplace.ssr) {\n // return new file id for ssr\n return {\n id: foundReplace.ssr,\n };\n } else if (foundReplace.ssr) {\n return null;\n }\n\n // return new file id\n return {\n id: foundReplace.with,\n };\n } catch (err) {\n console.error(err);\n return null;\n }\n }\n return null;\n },\n };\n}\n\nexport type FileReplacement = FileReplacementWith | FileReplacementSSR;\n\nexport interface FileReplacementBase {\n replace: string;\n}\nexport interface FileReplacementWith extends FileReplacementBase {\n with: string;\n}\n\nexport interface FileReplacementSSR extends FileReplacementBase {\n ssr: string;\n}\n"],"mappings":";;AAIA,SAAgB,aACd,cACA,eACgB;AAChB,KAAI,CAAC,cAAc,OACjB,QAAO;AAGT,QAAO;EACL,MAAM;EACN,SAAS;EACT,MAAM,UAAU,QAAQ,UAAU,SAAS;GACzC,MAAM,WAAW,MAAM,KAAK,QAAQ,QAAQ,UAAU;IACpD,GAAG;IACH,UAAU;IACX,CAAC;GAyBF,MAAM,eAlBqB,aAAa,KAAK,OAAwB;IACnE,MAAM,QAAQ;IACd,MAAM,SAAS;AAEf,WAAO;KACL,GAAG;KACH,KAAK,MAAM,MACP,WAAW,MAAM,IAAI,GACnB,MAAM,MACN,QAAQ,eAAe,MAAM,IAAI,GACnC;KACJ,MAAM,OAAO,OACT,WAAW,OAAO,KAAK,GACrB,OAAO,OACP,QAAQ,eAAe,OAAO,KAAK,GACrC;KACL;KACD,CACsC,MAAM,gBAC5C,UAAU,IAAI,SAAS,YAAY,QAAQ,CAC5C;AACD,OAAI,aACF,KAAI;AACF,QAAI,KAAK,YAAY,SAAS,SAAS,aAAa,IAElD,QAAO,EACL,IAAI,aAAa,KAClB;aACQ,aAAa,IACtB,QAAO;AAIT,WAAO,EACL,IAAI,aAAa,MAClB;YACM,KAAK;AACZ,YAAQ,MAAM,IAAI;AAClB,WAAO;;AAGX,UAAO;;EAEV"}
@@ -1,25 +1,25 @@
1
- import { JavaScriptTransformer } from './utils/devkit.js';
2
- export function routerPlugin() {
3
- const javascriptTransformer = new JavaScriptTransformer({ jit: true }, 1);
4
- /**
5
- * Transforms Angular packages the didn't get picked up by Vite's pre-optimization.
6
- */
7
- return {
8
- name: 'analogjs-router-optimization',
9
- enforce: 'pre',
10
- apply: 'serve',
11
- transform: {
12
- filter: {
13
- id: /fesm(.*?)\.mjs/,
14
- },
15
- async handler(_code, id) {
16
- const path = id.split('?')[0];
17
- const contents = await javascriptTransformer.transformFile(path);
18
- return {
19
- code: Buffer.from(contents).toString('utf-8'),
20
- };
21
- },
22
- },
23
- };
1
+ import { jt } from "./utils/devkit.js";
2
+ //#region packages/vite-plugin-angular/src/lib/router-plugin.ts
3
+ function routerPlugin() {
4
+ const javascriptTransformer = new jt({ jit: true }, 1);
5
+ /**
6
+ * Transforms Angular packages the didn't get picked up by Vite's pre-optimization.
7
+ */
8
+ return {
9
+ name: "analogjs-router-optimization",
10
+ enforce: "pre",
11
+ apply: "serve",
12
+ transform: {
13
+ filter: { id: /fesm(.*?)\.mjs/ },
14
+ async handler(_code, id) {
15
+ const path = id.split("?")[0];
16
+ const contents = await javascriptTransformer.transformFile(path);
17
+ return { code: Buffer.from(contents).toString("utf-8") };
18
+ }
19
+ }
20
+ };
24
21
  }
22
+ //#endregion
23
+ export { routerPlugin };
24
+
25
25
  //# sourceMappingURL=router-plugin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"router-plugin.js","sourceRoot":"","sources":["../../../../../packages/vite-plugin-angular/src/lib/router-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,MAAM,UAAU,YAAY;IAC1B,MAAM,qBAAqB,GAAG,IAAI,qBAAqB,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;IAE1E;;OAEG;IACH,OAAO;QACL,IAAI,EAAE,8BAA8B;QACpC,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,OAAO;QACd,SAAS,EAAE;YACT,MAAM,EAAE;gBACN,EAAE,EAAE,gBAAgB;aACrB;YACD,KAAK,CAAC,OAAO,CAAC,KAAa,EAAE,EAAU;gBACrC,MAAM,IAAI,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC9B,MAAM,QAAQ,GAAG,MAAM,qBAAqB,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;gBAEjE,OAAO;oBACL,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC;iBAC9C,CAAC;YACJ,CAAC;SACF;KACF,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"router-plugin.js","names":[],"sources":["../../../../../packages/vite-plugin-angular/src/lib/router-plugin.ts"],"sourcesContent":["import type { Plugin } from 'vite';\nimport { JavaScriptTransformer } from './utils/devkit.js';\n\nexport function routerPlugin(): Plugin {\n const javascriptTransformer = new JavaScriptTransformer({ jit: true }, 1);\n\n /**\n * Transforms Angular packages the didn't get picked up by Vite's pre-optimization.\n */\n return {\n name: 'analogjs-router-optimization',\n enforce: 'pre',\n apply: 'serve',\n transform: {\n filter: {\n id: /fesm(.*?)\\.mjs/,\n },\n async handler(_code: string, id: string) {\n const path = id.split('?')[0];\n const contents = await javascriptTransformer.transformFile(path);\n\n return {\n code: Buffer.from(contents).toString('utf-8'),\n };\n },\n },\n };\n}\n"],"mappings":";;AAGA,SAAgB,eAAuB;CACrC,MAAM,wBAAwB,IAAI,GAAsB,EAAE,KAAK,MAAM,EAAE,EAAE;;;;AAKzE,QAAO;EACL,MAAM;EACN,SAAS;EACT,OAAO;EACP,WAAW;GACT,QAAQ,EACN,IAAI,kBACL;GACD,MAAM,QAAQ,OAAe,IAAY;IACvC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC;IAC3B,MAAM,WAAW,MAAM,sBAAsB,cAAc,KAAK;AAEhE,WAAO,EACL,MAAM,OAAO,KAAK,SAAS,CAAC,SAAS,QAAQ,EAC9C;;GAEJ;EACF"}
@@ -1,8 +1,5 @@
1
1
  {
2
2
  "name": "@analogjs/vite-plugin-angular-tools",
3
3
  "version": "0.0.1",
4
- "main": "src/index.js",
5
- "types": "./src/index.d.ts",
6
- "module": "./src/index.js",
7
- "type": "module"
8
- }
4
+ "main": "src/index.js"
5
+ }
@@ -1,41 +1,34 @@
1
- import { createBuilder, targetFromTargetString, } from '@angular-devkit/architect';
1
+ import { createBuilder, targetFromTargetString } from "@angular-devkit/architect";
2
+ //#region packages/vite-plugin-angular-tools/src/builders/vite/vite-build.impl.ts
2
3
  async function viteBuilder(options, context) {
3
- const { createBuilder } = await Function('return import("vite")')();
4
- if (!context.target) {
5
- throw new Error('Builder must be executed with a target');
6
- }
7
- const projectConfig = await context.getProjectMetadata(context.target);
8
- const projectName = context.target.project;
9
- const configuration = context.target.configuration || 'production';
10
- const buildTargetSpecifier = `::${configuration}`;
11
- const buildTarget = targetFromTargetString(buildTargetSpecifier, projectName, 'build');
12
- const browserBuilderName = await context.getBuilderNameForTarget(buildTarget);
13
- const rawBuildOptions = await context.getTargetOptions(buildTarget);
14
- const buildOptions = await context.validateOptions(rawBuildOptions, browserBuilderName);
15
- const buildConfig = {
16
- configFile: options.configFile,
17
- root: projectConfig.root,
18
- mode: (process.env.NODE_ENV ??
19
- buildOptions.mode ??
20
- configuration),
21
- build: {
22
- outDir: options.outputPath,
23
- sourcemap: !!buildOptions.sourcemap,
24
- },
25
- };
26
- try {
27
- const builder = await createBuilder(buildConfig, false);
28
- await builder.buildApp();
29
- return {
30
- success: true,
31
- };
32
- }
33
- catch (e) {
34
- console.error(e);
35
- return {
36
- success: false,
37
- };
38
- }
4
+ const { createBuilder } = await Function("return import(\"vite\")")();
5
+ if (!context.target) throw new Error("Builder must be executed with a target");
6
+ const projectConfig = await context.getProjectMetadata(context.target);
7
+ const projectName = context.target.project;
8
+ const configuration = context.target.configuration || "production";
9
+ const buildTarget = targetFromTargetString(`::${configuration}`, projectName, "build");
10
+ const browserBuilderName = await context.getBuilderNameForTarget(buildTarget);
11
+ const rawBuildOptions = await context.getTargetOptions(buildTarget);
12
+ const buildOptions = await context.validateOptions(rawBuildOptions, browserBuilderName);
13
+ const buildConfig = {
14
+ configFile: options.configFile,
15
+ root: projectConfig.root,
16
+ mode: process.env.NODE_ENV ?? buildOptions.mode ?? configuration,
17
+ build: {
18
+ outDir: options.outputPath,
19
+ sourcemap: !!buildOptions.sourcemap
20
+ }
21
+ };
22
+ try {
23
+ await (await createBuilder(buildConfig, false)).buildApp();
24
+ return { success: true };
25
+ } catch (e) {
26
+ console.error(e);
27
+ return { success: false };
28
+ }
39
29
  }
40
- export default createBuilder(viteBuilder);
30
+ var vite_build_impl_default = createBuilder(viteBuilder);
31
+ //#endregion
32
+ export { vite_build_impl_default as default };
33
+
41
34
  //# sourceMappingURL=vite-build.impl.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"vite-build.impl.js","sourceRoot":"","sources":["../../../../../../../../../packages/vite-plugin-angular-tools/src/builders/vite/vite-build.impl.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,aAAa,EACb,sBAAsB,GACvB,MAAM,2BAA2B,CAAC;AAInC,KAAK,UAAU,WAAW,CACxB,OAAwB,EACxB,OAAuB;IAEvB,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,QAAQ,CAAC,uBAAuB,CAAC,EAAE,CAAC;IACpE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;IACD,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACvE,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC;IAC3C,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,aAAa,IAAI,YAAY,CAAC;IACnE,MAAM,oBAAoB,GAAG,KAAK,aAAa,EAAE,CAAC;IAClD,MAAM,WAAW,GAAG,sBAAsB,CACxC,oBAAoB,EACpB,WAAW,EACX,OAAO,CACR,CAAC;IAEF,MAAM,kBAAkB,GAAG,MAAM,OAAO,CAAC,uBAAuB,CAAC,WAAW,CAAC,CAAC;IAC9E,MAAM,eAAe,GAAG,MAAM,OAAO,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC;IACpE,MAAM,YAAY,GAAG,MAAM,OAAO,CAAC,eAAe,CAChD,eAAe,EACf,kBAAkB,CACnB,CAAC;IAEF,MAAM,WAAW,GAAiB;QAChC,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,IAAI,EAAE,aAAa,CAAC,IAAc;QAClC,IAAI,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ;YACzB,YAAY,CAAC,IAAI;YACjB,aAAa,CAAW;QAC1B,KAAK,EAAE;YACL,MAAM,EAAE,OAAO,CAAC,UAAU;YAC1B,SAAS,EAAE,CAAC,CAAC,YAAY,CAAC,SAAS;SACpC;KACF,CAAC;IAEF,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;QACxD,MAAM,OAAO,CAAC,QAAQ,EAAE,CAAC;QAEzB,OAAO;YACL,OAAO,EAAE,IAAI;SACd,CAAC;IACJ,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACjB,OAAO;YACL,OAAO,EAAE,KAAK;SACf,CAAC;IACJ,CAAC;AACH,CAAC;AAED,eAAe,aAAa,CAAC,WAAW,CAAQ,CAAC"}
1
+ {"version":3,"file":"vite-build.impl.js","names":[],"sources":["../../../../../../../../../packages/vite-plugin-angular-tools/src/builders/vite/vite-build.impl.ts"],"sourcesContent":["import {\n BuilderContext,\n BuilderOutput,\n createBuilder,\n targetFromTargetString,\n} from '@angular-devkit/architect';\nimport type { InlineConfig } from 'vite';\nimport { ViteBuildSchema } from './schema';\n\nasync function viteBuilder(\n options: ViteBuildSchema,\n context: BuilderContext,\n): Promise<BuilderOutput> {\n const { createBuilder } = await Function('return import(\"vite\")')();\n if (!context.target) {\n throw new Error('Builder must be executed with a target');\n }\n const projectConfig = await context.getProjectMetadata(context.target);\n const projectName = context.target.project;\n const configuration = context.target.configuration || 'production';\n const buildTargetSpecifier = `::${configuration}`;\n const buildTarget = targetFromTargetString(\n buildTargetSpecifier,\n projectName,\n 'build',\n );\n\n const browserBuilderName = await context.getBuilderNameForTarget(buildTarget);\n const rawBuildOptions = await context.getTargetOptions(buildTarget);\n const buildOptions = await context.validateOptions(\n rawBuildOptions,\n browserBuilderName,\n );\n\n const buildConfig: InlineConfig = {\n configFile: options.configFile,\n root: projectConfig.root as string,\n mode: (process.env.NODE_ENV ??\n buildOptions.mode ??\n configuration) as string,\n build: {\n outDir: options.outputPath,\n sourcemap: !!buildOptions.sourcemap,\n },\n };\n\n try {\n const builder = await createBuilder(buildConfig, false);\n await builder.buildApp();\n\n return {\n success: true,\n };\n } catch (e) {\n console.error(e);\n return {\n success: false,\n };\n }\n}\n\nexport default createBuilder(viteBuilder) as any;\n"],"mappings":";;AASA,eAAe,YACb,SACA,SACwB;CACxB,MAAM,EAAE,kBAAkB,MAAM,SAAS,0BAAwB,EAAE;AACnE,KAAI,CAAC,QAAQ,OACX,OAAM,IAAI,MAAM,yCAAyC;CAE3D,MAAM,gBAAgB,MAAM,QAAQ,mBAAmB,QAAQ,OAAO;CACtE,MAAM,cAAc,QAAQ,OAAO;CACnC,MAAM,gBAAgB,QAAQ,OAAO,iBAAiB;CAEtD,MAAM,cAAc,uBADS,KAAK,iBAGhC,aACA,QACD;CAED,MAAM,qBAAqB,MAAM,QAAQ,wBAAwB,YAAY;CAC7E,MAAM,kBAAkB,MAAM,QAAQ,iBAAiB,YAAY;CACnE,MAAM,eAAe,MAAM,QAAQ,gBACjC,iBACA,mBACD;CAED,MAAM,cAA4B;EAChC,YAAY,QAAQ;EACpB,MAAM,cAAc;EACpB,MAAA,QAAA,IAAA,YACE,aAAa,QACb;EACF,OAAO;GACL,QAAQ,QAAQ;GAChB,WAAW,CAAC,CAAC,aAAa;GAC3B;EACF;AAED,KAAI;AAEF,SADgB,MAAM,cAAc,aAAa,MAAM,EACzC,UAAU;AAExB,SAAO,EACL,SAAS,MACV;UACM,GAAG;AACV,UAAQ,MAAM,EAAE;AAChB,SAAO,EACL,SAAS,OACV;;;AAIL,IAAA,0BAAe,cAAc,YAAY"}
@@ -1,65 +1,57 @@
1
- import { createBuilder, targetFromTargetString, } from '@angular-devkit/architect';
1
+ import { createBuilder, targetFromTargetString } from "@angular-devkit/architect";
2
+ //#region packages/vite-plugin-angular-tools/src/builders/vite-dev-server/dev-server.impl.ts
2
3
  async function viteDevServerBuilder(options, context) {
3
- const { createServer } = await Function('return import("vite")')();
4
- if (!context.target) {
5
- throw new Error('Builder must be executed with a target');
6
- }
7
- const projectConfig = await context.getProjectMetadata(context.target);
8
- const projectName = context.target.project;
9
- const buildTargetSpecifier = options.buildTarget ?? `::development`;
10
- const buildTarget = targetFromTargetString(buildTargetSpecifier, projectName, 'build');
11
- const browserBuilderName = await context.getBuilderNameForTarget(buildTarget);
12
- const rawBuildOptions = await context.getTargetOptions(buildTarget);
13
- const buildOptions = await context.validateOptions(rawBuildOptions, browserBuilderName);
14
- const serverConfig = {
15
- configFile: buildOptions.configFile,
16
- root: projectConfig.root,
17
- mode: (process.env.NODE_ENV ??
18
- buildOptions.mode ??
19
- 'development'),
20
- build: {
21
- sourcemap: !!buildOptions.sourcemap,
22
- },
23
- server: {
24
- hmr: options?.hmr,
25
- port: options?.port,
26
- },
27
- };
28
- try {
29
- const server = await createServer(serverConfig);
30
- await runViteDevServer(server);
31
- const resolvedUrls = [
32
- ...server.resolvedUrls.local,
33
- ...server.resolvedUrls.network,
34
- ];
35
- await new Promise((resolve) => {
36
- process.once('SIGINT', () => resolve());
37
- process.once('SIGTERM', () => resolve());
38
- process.once('exit', () => resolve());
39
- });
40
- return {
41
- success: true,
42
- baseUrl: resolvedUrls[0] ?? '',
43
- };
44
- }
45
- catch (e) {
46
- console.error(e);
47
- return {
48
- success: false,
49
- baseUrl: '',
50
- };
51
- }
4
+ const { createServer } = await Function("return import(\"vite\")")();
5
+ if (!context.target) throw new Error("Builder must be executed with a target");
6
+ const projectConfig = await context.getProjectMetadata(context.target);
7
+ const projectName = context.target.project;
8
+ const buildTarget = targetFromTargetString(options.buildTarget ?? `::development`, projectName, "build");
9
+ const browserBuilderName = await context.getBuilderNameForTarget(buildTarget);
10
+ const rawBuildOptions = await context.getTargetOptions(buildTarget);
11
+ const buildOptions = await context.validateOptions(rawBuildOptions, browserBuilderName);
12
+ const serverConfig = {
13
+ configFile: buildOptions.configFile,
14
+ root: projectConfig.root,
15
+ mode: process.env.NODE_ENV ?? buildOptions.mode ?? "development",
16
+ build: { sourcemap: !!buildOptions.sourcemap },
17
+ server: {
18
+ hmr: options?.hmr,
19
+ port: options?.port
20
+ }
21
+ };
22
+ try {
23
+ const server = await createServer(serverConfig);
24
+ await runViteDevServer(server);
25
+ const resolvedUrls = [...server.resolvedUrls.local, ...server.resolvedUrls.network];
26
+ await new Promise((resolve) => {
27
+ process.once("SIGINT", () => resolve());
28
+ process.once("SIGTERM", () => resolve());
29
+ process.once("exit", () => resolve());
30
+ });
31
+ return {
32
+ success: true,
33
+ baseUrl: resolvedUrls[0] ?? ""
34
+ };
35
+ } catch (e) {
36
+ console.error(e);
37
+ return {
38
+ success: false,
39
+ baseUrl: ""
40
+ };
41
+ }
52
42
  }
53
- // vite ViteDevServer
54
43
  async function runViteDevServer(server) {
55
- await server.listen();
56
- server.printUrls();
57
- const processOnExit = async () => {
58
- await server.close();
59
- };
60
- process.once('SIGINT', processOnExit);
61
- process.once('SIGTERM', processOnExit);
62
- process.once('exit', processOnExit);
44
+ await server.listen();
45
+ server.printUrls();
46
+ const processOnExit = async () => {
47
+ await server.close();
48
+ };
49
+ process.once("SIGINT", processOnExit);
50
+ process.once("SIGTERM", processOnExit);
51
+ process.once("exit", processOnExit);
63
52
  }
64
- export default createBuilder(viteDevServerBuilder);
53
+ var dev_server_impl_default = createBuilder(viteDevServerBuilder);
54
+ //#endregion
55
+ export { dev_server_impl_default as default };
56
+
65
57
  //# sourceMappingURL=dev-server.impl.js.map