@aklinker1/aframe 0.4.5 → 0.4.7

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/README.md CHANGED
@@ -83,7 +83,7 @@ bun add -D puppeteer vite
83
83
  "aframe": "bun node_modules/@aklinker1/aframe/bin/aframe.ts",
84
84
  "dev": "bun --silent aframe",
85
85
  "build": "bun --silent aframe build",
86
- "preview": "bun --cwd .output --env-file ../.env server-entry.js",
86
+ "preview": "bun .output/server-entry.js",
87
87
  },
88
88
  "dependencies": {
89
89
  "@aklinker1/aframe": "latest",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aklinker1/aframe",
3
- "version": "0.4.5",
3
+ "version": "0.4.7",
4
4
  "packageManager": "bun@1.2.5",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,4 +1,5 @@
1
1
  import type { BunFile } from "bun";
2
+ import { resolve } from "node:path";
2
3
 
3
4
  const headers = {
4
5
  "Cache-Control": "max-age=31536000",
@@ -8,6 +9,8 @@ export interface AframeServer {
8
9
  listen(port: number): void | never;
9
10
  }
10
11
 
12
+ const publicDir = resolve(import.meta.dir, import.meta.publicDir);
13
+
11
14
  /**
12
15
  * Fetches a file from the `public` directory.
13
16
  */
@@ -21,14 +24,11 @@ export function fetchStatic(options?: {
21
24
  return async (request) => {
22
25
  const path = new URL(request.url).pathname.replace(/\/+$/, "");
23
26
 
24
- const paths = [
25
- `${import.meta.publicDir}${path}`,
26
- `${import.meta.publicDir}${path}/index.html`,
27
- ];
27
+ const paths = [`${publicDir}${path}`, `${publicDir}${path}/index.html`];
28
28
 
29
29
  // Only fallback on the root HTML file when building application
30
30
  if (import.meta.command === "build") {
31
- paths.push(`${import.meta.publicDir}/index.html`);
31
+ paths.push(`${publicDir}/index.html`);
32
32
  }
33
33
 
34
34
  for (const path of paths) {
package/src/config.ts CHANGED
@@ -5,6 +5,11 @@ import type { LaunchOptions } from "puppeteer";
5
5
 
6
6
  export type UserConfig = {
7
7
  vite?: vite.UserConfigExport;
8
+ /**
9
+ * Paths for vite to proxy to the backend during development.
10
+ * @default ["/api"]
11
+ */
12
+ proxyPaths?: string[];
8
13
  prerenderedRoutes?: string[];
9
14
  prerenderer?: PrerendererConfig | false;
10
15
  };
@@ -78,8 +83,8 @@ export async function resolveConfig(
78
83
  if (typeof viteConfig === "function") {
79
84
  viteConfig = await viteConfig({ command, mode });
80
85
  }
81
- // Apply opinionated config that can be overwritten
82
86
 
87
+ // Apply opinionated config that can be overwritten
83
88
  viteConfig = vite.mergeConfig<vite.InlineConfig, vite.InlineConfig>(
84
89
  // Defaults
85
90
  {
@@ -93,6 +98,14 @@ export async function resolveConfig(
93
98
  );
94
99
 
95
100
  // Override required config
101
+ const proxyPaths = userConfig.proxyPaths ?? ["/api"];
102
+ const proxy: Record<string, string | vite.ProxyOptions> = {};
103
+ proxyPaths.forEach((path) => {
104
+ proxy[path] = {
105
+ target: `http://localhost:${serverPort}`,
106
+ changeOrigin: true,
107
+ };
108
+ });
96
109
  viteConfig = vite.mergeConfig<vite.InlineConfig, vite.InlineConfig>(
97
110
  // Defaults
98
111
  viteConfig,
@@ -109,12 +122,7 @@ export async function resolveConfig(
109
122
  server: {
110
123
  port: appPort,
111
124
  strictPort: true,
112
- proxy: {
113
- "/api": {
114
- target: `http://localhost:${serverPort}`,
115
- changeOrigin: true,
116
- },
117
- },
125
+ proxy,
118
126
  },
119
127
  },
120
128
  );
package/src/env.d.ts CHANGED
@@ -2,6 +2,12 @@ import "vite/client";
2
2
 
3
3
  declare global {
4
4
  interface ImportMeta {
5
+ /**
6
+ * Absolute path or relative path (relative to main server file, not CWD).
7
+ * This ensures the public directory path is constant regardless of the CWD.
8
+ * It allows dev mode, production builds, and preview mode to all run from
9
+ * any working directory.
10
+ */
5
11
  publicDir: string;
6
12
  command: string;
7
13
  }