@lovable.dev/vite-tanstack-config 2.6.1 → 2.6.2-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -30,11 +30,92 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
- defineConfig: () => defineConfig
33
+ defineConfig: () => defineConfig,
34
+ lovableAssetsProxyPlugin: () => lovableAssetsProxyPlugin
34
35
  });
35
36
  module.exports = __toCommonJS(src_exports);
36
37
  var import_lovable_tagger = require("lovable-tagger");
37
38
  var import_vite = require("vite");
39
+
40
+ // src/assetsProxyPlugin.ts
41
+ var import_node_https = __toESM(require("https"), 1);
42
+ var ASSET_RE = /^\/__l5e\/assets-v1\//;
43
+ var PREVIEW_HOST_ENV = "LOVABLE_PREVIEW_HOST";
44
+ var HOP_BY_HOP = /* @__PURE__ */ new Set([
45
+ "host",
46
+ "connection",
47
+ "keep-alive",
48
+ "proxy-authenticate",
49
+ "proxy-authorization",
50
+ "te",
51
+ "trailer",
52
+ "transfer-encoding",
53
+ "upgrade",
54
+ "content-length",
55
+ "cookie"
56
+ ]);
57
+ function pickRequestHeaders(src) {
58
+ const out = {};
59
+ for (const [k, v] of Object.entries(src)) {
60
+ if (v === void 0)
61
+ continue;
62
+ if (HOP_BY_HOP.has(k.toLowerCase()))
63
+ continue;
64
+ out[k] = v;
65
+ }
66
+ return out;
67
+ }
68
+ function lovableAssetsProxyPlugin() {
69
+ const previewHost = process.env[PREVIEW_HOST_ENV]?.trim();
70
+ return {
71
+ name: "lovable:assets-proxy",
72
+ apply: "serve",
73
+ configureServer(server) {
74
+ if (!previewHost)
75
+ return;
76
+ const middleware = (req, res, next) => {
77
+ const url = req.url ?? "";
78
+ if (!ASSET_RE.test(url))
79
+ return next();
80
+ const upstream = import_node_https.default.request(
81
+ {
82
+ host: previewHost,
83
+ port: 443,
84
+ method: req.method,
85
+ path: url,
86
+ headers: { ...pickRequestHeaders(req.headers), host: previewHost }
87
+ },
88
+ (upRes) => {
89
+ res.statusCode = upRes.statusCode ?? 502;
90
+ for (const [k, v] of Object.entries(upRes.headers)) {
91
+ if (v === void 0)
92
+ continue;
93
+ if (HOP_BY_HOP.has(k.toLowerCase()))
94
+ continue;
95
+ res.setHeader(k, v);
96
+ }
97
+ upRes.pipe(res);
98
+ }
99
+ );
100
+ upstream.on("error", (err) => {
101
+ server.config.logger.warn(
102
+ `[@lovable.dev/vite-tanstack-config] asset proxy ${url} \u2192 ${previewHost} failed: ${err.message}`
103
+ );
104
+ if (!res.headersSent) {
105
+ res.statusCode = 502;
106
+ res.end();
107
+ } else {
108
+ res.destroy(err);
109
+ }
110
+ });
111
+ req.pipe(upstream);
112
+ };
113
+ server.middlewares.use(middleware);
114
+ }
115
+ };
116
+ }
117
+
118
+ // src/index.ts
38
119
  var SANDBOX_ENV_VAR = "DEV_SERVER__PROJECT_PATH";
39
120
  var LOVABLE_SANDBOX_ENV_VAR = "LOVABLE_SANDBOX";
40
121
  function isSandboxEnvironment() {
@@ -627,6 +708,9 @@ function defineConfig(configOrOptions = {}) {
627
708
  const { devServerBridgePlugin } = await import("@lovable.dev/vite-plugin-dev-server-bridge");
628
709
  internalPlugins.push(devServerBridgePlugin());
629
710
  }
711
+ if (command === "serve") {
712
+ internalPlugins.push(lovableAssetsProxyPlugin());
713
+ }
630
714
  if (command === "serve" && mode === "development") {
631
715
  internalPlugins.push((0, import_lovable_tagger.componentTagger)());
632
716
  }
@@ -695,5 +779,6 @@ function defineConfig(configOrOptions = {}) {
695
779
  }
696
780
  // Annotate the CommonJS export names for ESM import in node:
697
781
  0 && (module.exports = {
698
- defineConfig
782
+ defineConfig,
783
+ lovableAssetsProxyPlugin
699
784
  });
package/dist/index.d.cts CHANGED
@@ -1,4 +1,15 @@
1
- import { PluginOption, UserConfig, ConfigEnv, UserConfigFnObject, UserConfigFnPromise, UserConfigFn } from 'vite';
1
+ import { Plugin, PluginOption, UserConfig, ConfigEnv, UserConfigFnObject, UserConfigFnPromise, UserConfigFn } from 'vite';
2
+
3
+ /**
4
+ * Forwards `/__l5e/assets-v1/*` requests from the Vite dev server to the
5
+ * Lovable preview proxy so assets resolve when the page is loaded directly
6
+ * from the sandbox dev server (e.g. `localhost:8080`) instead of via
7
+ * `*.lovable.app` / `*.lovableproject.com`.
8
+ *
9
+ * No-op unless `LOVABLE_PREVIEW_HOST` is set (host only, no scheme), e.g.
10
+ * `id-preview--<project-id>.lovable.app`.
11
+ */
12
+ declare function lovableAssetsProxyPlugin(): Plugin;
2
13
 
3
14
  interface LovableViteTanstackOptions {
4
15
  plugins?: PluginOption[];
@@ -59,4 +70,4 @@ declare function defineConfig(config: UserConfigFnPromise): (env: ConfigEnv) =>
59
70
  declare function defineConfig(config: UserConfigFn): (env: ConfigEnv) => Promise<UserConfig>;
60
71
  declare function defineConfig(options?: LovableViteTanstackOptions): (env: ConfigEnv) => Promise<UserConfig>;
61
72
 
62
- export { type LovableViteTanstackOptions, defineConfig };
73
+ export { type LovableViteTanstackOptions, defineConfig, lovableAssetsProxyPlugin };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,15 @@
1
- import { PluginOption, UserConfig, ConfigEnv, UserConfigFnObject, UserConfigFnPromise, UserConfigFn } from 'vite';
1
+ import { Plugin, PluginOption, UserConfig, ConfigEnv, UserConfigFnObject, UserConfigFnPromise, UserConfigFn } from 'vite';
2
+
3
+ /**
4
+ * Forwards `/__l5e/assets-v1/*` requests from the Vite dev server to the
5
+ * Lovable preview proxy so assets resolve when the page is loaded directly
6
+ * from the sandbox dev server (e.g. `localhost:8080`) instead of via
7
+ * `*.lovable.app` / `*.lovableproject.com`.
8
+ *
9
+ * No-op unless `LOVABLE_PREVIEW_HOST` is set (host only, no scheme), e.g.
10
+ * `id-preview--<project-id>.lovable.app`.
11
+ */
12
+ declare function lovableAssetsProxyPlugin(): Plugin;
2
13
 
3
14
  interface LovableViteTanstackOptions {
4
15
  plugins?: PluginOption[];
@@ -59,4 +70,4 @@ declare function defineConfig(config: UserConfigFnPromise): (env: ConfigEnv) =>
59
70
  declare function defineConfig(config: UserConfigFn): (env: ConfigEnv) => Promise<UserConfig>;
60
71
  declare function defineConfig(options?: LovableViteTanstackOptions): (env: ConfigEnv) => Promise<UserConfig>;
61
72
 
62
- export { type LovableViteTanstackOptions, defineConfig };
73
+ export { type LovableViteTanstackOptions, defineConfig, lovableAssetsProxyPlugin };
package/dist/index.js CHANGED
@@ -1,6 +1,86 @@
1
1
  // src/index.ts
2
2
  import { componentTagger } from "lovable-tagger";
3
3
  import { mergeConfig, loadEnv } from "vite";
4
+
5
+ // src/assetsProxyPlugin.ts
6
+ import https from "https";
7
+ var ASSET_RE = /^\/__l5e\/assets-v1\//;
8
+ var PREVIEW_HOST_ENV = "LOVABLE_PREVIEW_HOST";
9
+ var HOP_BY_HOP = /* @__PURE__ */ new Set([
10
+ "host",
11
+ "connection",
12
+ "keep-alive",
13
+ "proxy-authenticate",
14
+ "proxy-authorization",
15
+ "te",
16
+ "trailer",
17
+ "transfer-encoding",
18
+ "upgrade",
19
+ "content-length",
20
+ "cookie"
21
+ ]);
22
+ function pickRequestHeaders(src) {
23
+ const out = {};
24
+ for (const [k, v] of Object.entries(src)) {
25
+ if (v === void 0)
26
+ continue;
27
+ if (HOP_BY_HOP.has(k.toLowerCase()))
28
+ continue;
29
+ out[k] = v;
30
+ }
31
+ return out;
32
+ }
33
+ function lovableAssetsProxyPlugin() {
34
+ const previewHost = process.env[PREVIEW_HOST_ENV]?.trim();
35
+ return {
36
+ name: "lovable:assets-proxy",
37
+ apply: "serve",
38
+ configureServer(server) {
39
+ if (!previewHost)
40
+ return;
41
+ const middleware = (req, res, next) => {
42
+ const url = req.url ?? "";
43
+ if (!ASSET_RE.test(url))
44
+ return next();
45
+ const upstream = https.request(
46
+ {
47
+ host: previewHost,
48
+ port: 443,
49
+ method: req.method,
50
+ path: url,
51
+ headers: { ...pickRequestHeaders(req.headers), host: previewHost }
52
+ },
53
+ (upRes) => {
54
+ res.statusCode = upRes.statusCode ?? 502;
55
+ for (const [k, v] of Object.entries(upRes.headers)) {
56
+ if (v === void 0)
57
+ continue;
58
+ if (HOP_BY_HOP.has(k.toLowerCase()))
59
+ continue;
60
+ res.setHeader(k, v);
61
+ }
62
+ upRes.pipe(res);
63
+ }
64
+ );
65
+ upstream.on("error", (err) => {
66
+ server.config.logger.warn(
67
+ `[@lovable.dev/vite-tanstack-config] asset proxy ${url} \u2192 ${previewHost} failed: ${err.message}`
68
+ );
69
+ if (!res.headersSent) {
70
+ res.statusCode = 502;
71
+ res.end();
72
+ } else {
73
+ res.destroy(err);
74
+ }
75
+ });
76
+ req.pipe(upstream);
77
+ };
78
+ server.middlewares.use(middleware);
79
+ }
80
+ };
81
+ }
82
+
83
+ // src/index.ts
4
84
  var SANDBOX_ENV_VAR = "DEV_SERVER__PROJECT_PATH";
5
85
  var LOVABLE_SANDBOX_ENV_VAR = "LOVABLE_SANDBOX";
6
86
  function isSandboxEnvironment() {
@@ -593,6 +673,9 @@ function defineConfig(configOrOptions = {}) {
593
673
  const { devServerBridgePlugin } = await import("@lovable.dev/vite-plugin-dev-server-bridge");
594
674
  internalPlugins.push(devServerBridgePlugin());
595
675
  }
676
+ if (command === "serve") {
677
+ internalPlugins.push(lovableAssetsProxyPlugin());
678
+ }
596
679
  if (command === "serve" && mode === "development") {
597
680
  internalPlugins.push(componentTagger());
598
681
  }
@@ -660,5 +743,6 @@ function defineConfig(configOrOptions = {}) {
660
743
  };
661
744
  }
662
745
  export {
663
- defineConfig
746
+ defineConfig,
747
+ lovableAssetsProxyPlugin
664
748
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lovable.dev/vite-tanstack-config",
3
- "version": "2.6.1",
3
+ "version": "2.6.2-rc.0",
4
4
  "description": "Vite config wrapper for Lovable TanStack Start projects",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",