@qwik.dev/router 2.0.0-beta.9 → 2.0.0-rc.2
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/lib/adapters/azure-swa/vite/index.d.ts +2 -2
- package/lib/adapters/azure-swa/vite/index.mjs +44 -57
- package/lib/adapters/bun-server/vite/index.d.ts +2 -2
- package/lib/adapters/bun-server/vite/index.mjs +16 -22
- package/lib/adapters/cloud-run/vite/index.d.ts +2 -2
- package/lib/adapters/cloud-run/vite/index.mjs +15 -19
- package/lib/adapters/cloudflare-pages/vite/index.d.ts +2 -2
- package/lib/adapters/cloudflare-pages/vite/index.mjs +45 -76
- package/lib/adapters/deno-server/vite/index.d.ts +2 -2
- package/lib/adapters/deno-server/vite/index.mjs +25 -34
- package/lib/adapters/netlify-edge/vite/index.d.ts +2 -2
- package/lib/adapters/netlify-edge/vite/index.mjs +49 -89
- package/lib/adapters/node-server/vite/index.d.ts +2 -2
- package/lib/adapters/node-server/vite/index.mjs +16 -22
- package/lib/adapters/shared/vite/index.d.ts +9 -16
- package/lib/adapters/shared/vite/index.mjs +280 -293
- package/lib/adapters/ssg/vite/index.d.ts +1 -1
- package/lib/adapters/ssg/vite/index.mjs +13 -299
- package/lib/adapters/vercel-edge/vite/index.d.ts +3 -3
- package/lib/adapters/vercel-edge/vite/index.mjs +75 -79
- package/lib/chunks/dev-preloaded-route-loader.mjs +2 -0
- package/lib/chunks/format.mjs +24 -0
- package/lib/chunks/fs.mjs +143 -0
- package/lib/chunks/head.qwik.mjs +1570 -0
- package/lib/chunks/http-error.qwik.mjs +28 -0
- package/lib/chunks/pathname.mjs +58 -0
- package/lib/chunks/request-body-limit.mjs +27 -0
- package/lib/chunks/request-path.mjs +53 -0
- package/lib/chunks/route-trie-key.mjs +10 -0
- package/lib/chunks/routes.mjs +26 -0
- package/lib/chunks/server-error.mjs +38 -0
- package/lib/chunks/static-file.mjs +70 -0
- package/lib/chunks/system.mjs +271 -0
- package/lib/chunks/user-response.mjs +1878 -0
- package/lib/chunks/worker-thread.mjs +274 -0
- package/lib/index.d.ts +550 -182
- package/lib/index.qwik.mjs +1746 -2057
- package/lib/middleware/aws-lambda/index.d.ts +15 -17
- package/lib/middleware/aws-lambda/index.mjs +46 -50
- package/lib/middleware/azure-swa/index.mjs +85 -294
- package/lib/middleware/bun/index.d.ts +22 -5
- package/lib/middleware/bun/index.mjs +118 -201
- package/lib/middleware/cloudflare-pages/index.d.ts +2 -0
- package/lib/middleware/cloudflare-pages/index.mjs +103 -101
- package/lib/middleware/deno/index.d.ts +22 -5
- package/lib/middleware/deno/index.mjs +103 -191
- package/lib/middleware/firebase/index.mjs +22 -31
- package/lib/middleware/netlify-edge/index.d.ts +2 -0
- package/lib/middleware/netlify-edge/index.mjs +64 -80
- package/lib/middleware/node/index.d.ts +17 -5
- package/lib/middleware/node/index.mjs +298 -269
- package/lib/middleware/request-handler/index.d.ts +259 -58
- package/lib/middleware/request-handler/index.mjs +108 -1730
- package/lib/middleware/vercel-edge/index.d.ts +2 -0
- package/lib/middleware/vercel-edge/index.mjs +77 -100
- package/lib/modules.d.ts +7 -4
- package/lib/service-worker/index.mjs +14 -0
- package/lib/ssg/index.d.ts +50 -26
- package/lib/ssg/index.mjs +257 -43
- package/lib/vite/index.d.ts +59 -11
- package/lib/vite/index.mjs +2534 -27536
- package/modules.d.ts +7 -4
- package/package.json +53 -70
- package/lib/adapters/azure-swa/vite/index.cjs +0 -96
- package/lib/adapters/bun-server/vite/index.cjs +0 -50
- package/lib/adapters/cloud-run/vite/index.cjs +0 -47
- package/lib/adapters/cloudflare-pages/vite/index.cjs +0 -115
- package/lib/adapters/deno-server/vite/index.cjs +0 -62
- package/lib/adapters/netlify-edge/vite/index.cjs +0 -130
- package/lib/adapters/node-server/vite/index.cjs +0 -50
- package/lib/adapters/shared/vite/index.cjs +0 -338
- package/lib/adapters/ssg/vite/index.cjs +0 -339
- package/lib/adapters/vercel-edge/vite/index.cjs +0 -118
- package/lib/index.qwik.cjs +0 -2112
- package/lib/middleware/node/index.cjs +0 -310
- package/lib/middleware/request-handler/index.cjs +0 -1766
- package/lib/service-worker.cjs +0 -17
- package/lib/service-worker.mjs +0 -15
- package/lib/ssg/deno.mjs +0 -8
- package/lib/ssg/index.cjs +0 -67
- package/lib/ssg/node.cjs +0 -1128
- package/lib/ssg/node.mjs +0 -1090
- package/lib/vite/index.cjs +0 -27607
|
@@ -1,339 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// packages/qwik-router/src/adapters/ssg/vite/index.ts
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
ssgAdapter: () => ssgAdapter,
|
|
34
|
-
staticAdapter: () => staticAdapter
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(index_exports);
|
|
37
|
-
|
|
38
|
-
// packages/qwik-router/src/adapters/shared/vite/index.ts
|
|
39
|
-
var import_node_path2 = require("node:path");
|
|
40
|
-
|
|
41
|
-
// packages/qwik-router/src/adapters/shared/vite/post-build.ts
|
|
42
|
-
var import_request_handler = require("@qwik.dev/router/middleware/request-handler");
|
|
43
|
-
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
44
|
-
var import_node_path = require("node:path");
|
|
45
|
-
async function postBuild(clientOutDir, serverOutDir, pathName, userStaticPaths, cleanStatic) {
|
|
46
|
-
if (pathName && !pathName.endsWith("/")) {
|
|
47
|
-
pathName += "/";
|
|
48
|
-
}
|
|
49
|
-
const ignorePathnames = /* @__PURE__ */ new Set([
|
|
50
|
-
pathName + "/" + (globalThis.__QWIK_BUILD_DIR__ || "build") + "/",
|
|
51
|
-
pathName + "/" + (globalThis.__QWIK_ASSETS_DIR__ || "assets") + "/"
|
|
52
|
-
]);
|
|
53
|
-
const staticPaths = new Set(userStaticPaths.map(normalizeTrailingSlash));
|
|
54
|
-
const notFounds = [];
|
|
55
|
-
const loadItem = async (fsDir, fsName, pathname) => {
|
|
56
|
-
pathname = normalizeTrailingSlash(pathname);
|
|
57
|
-
if (ignorePathnames.has(pathname)) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
const fsPath = (0, import_node_path.join)(fsDir, fsName);
|
|
61
|
-
if (fsName === "index.html" || fsName === "q-data.json") {
|
|
62
|
-
if (!staticPaths.has(pathname) && cleanStatic) {
|
|
63
|
-
await import_node_fs.default.promises.unlink(fsPath);
|
|
64
|
-
}
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
if (fsName === "404.html") {
|
|
68
|
-
const notFoundHtml = await import_node_fs.default.promises.readFile(fsPath, "utf-8");
|
|
69
|
-
notFounds.push([pathname, notFoundHtml]);
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
const stat = await import_node_fs.default.promises.stat(fsPath);
|
|
73
|
-
if (stat.isDirectory()) {
|
|
74
|
-
await loadDir(fsPath, pathname + fsName + "/");
|
|
75
|
-
} else if (stat.isFile()) {
|
|
76
|
-
staticPaths.add(pathname + fsName);
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
const loadDir = async (fsDir, pathname) => {
|
|
80
|
-
const itemNames = await import_node_fs.default.promises.readdir(fsDir);
|
|
81
|
-
await Promise.all(itemNames.map((i) => loadItem(fsDir, i, pathname)));
|
|
82
|
-
};
|
|
83
|
-
if (import_node_fs.default.existsSync(clientOutDir)) {
|
|
84
|
-
await loadDir(clientOutDir, pathName);
|
|
85
|
-
}
|
|
86
|
-
const notFoundPathsCode = createNotFoundPathsCode(pathName, notFounds);
|
|
87
|
-
const staticPathsCode = createStaticPathsCode(staticPaths);
|
|
88
|
-
await injectStatics(staticPathsCode, notFoundPathsCode, serverOutDir);
|
|
89
|
-
}
|
|
90
|
-
function normalizeTrailingSlash(pathname) {
|
|
91
|
-
if (!pathname.endsWith("/")) {
|
|
92
|
-
return pathname + "/";
|
|
93
|
-
}
|
|
94
|
-
return pathname;
|
|
95
|
-
}
|
|
96
|
-
function createNotFoundPathsCode(basePathname, notFounds) {
|
|
97
|
-
notFounds.sort((a, b) => {
|
|
98
|
-
if (a[0].length > b[0].length) {
|
|
99
|
-
return -1;
|
|
100
|
-
}
|
|
101
|
-
if (a[0].length < b[0].length) {
|
|
102
|
-
return 1;
|
|
103
|
-
}
|
|
104
|
-
if (a[0] < b[0]) {
|
|
105
|
-
return -1;
|
|
106
|
-
}
|
|
107
|
-
if (a[0] > b[0]) {
|
|
108
|
-
return 1;
|
|
109
|
-
}
|
|
110
|
-
return 0;
|
|
111
|
-
});
|
|
112
|
-
if (!notFounds.some((r) => r[0] === basePathname)) {
|
|
113
|
-
const html = (0, import_request_handler.getErrorHtml)(404, "Resource Not Found");
|
|
114
|
-
notFounds.push([basePathname, html]);
|
|
115
|
-
}
|
|
116
|
-
return JSON.stringify(notFounds, null, 2).slice(1, -1);
|
|
117
|
-
}
|
|
118
|
-
function createStaticPathsCode(staticPaths) {
|
|
119
|
-
return JSON.stringify(Array.from(new Set(staticPaths)).sort()).slice(1, -1);
|
|
120
|
-
}
|
|
121
|
-
var injectStatics = async (staticPathsCode, notFoundPathsCode, outDir) => {
|
|
122
|
-
const promises = /* @__PURE__ */ new Set();
|
|
123
|
-
const doReplace = async (path) => {
|
|
124
|
-
const code = await import_node_fs.default.promises.readFile(path, "utf-8");
|
|
125
|
-
let replaced = false;
|
|
126
|
-
const newCode = code.replace(
|
|
127
|
-
/(['"])__QWIK_ROUTER_(STATIC_PATHS|NOT_FOUND)_ARRAY__\1/g,
|
|
128
|
-
(_, _quote, type) => {
|
|
129
|
-
replaced = true;
|
|
130
|
-
return type === "STATIC_PATHS" ? staticPathsCode : notFoundPathsCode;
|
|
131
|
-
}
|
|
132
|
-
);
|
|
133
|
-
if (replaced) {
|
|
134
|
-
await import_node_fs.default.promises.writeFile(path, newCode);
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
const walk = async (dir) => {
|
|
138
|
-
const entries = await import_node_fs.default.promises.readdir(dir, { withFileTypes: true });
|
|
139
|
-
for (const entry of entries) {
|
|
140
|
-
if (entry.isDirectory()) {
|
|
141
|
-
await walk((0, import_node_path.join)(dir, entry.name));
|
|
142
|
-
} else if (entry.name.endsWith("js")) {
|
|
143
|
-
const p = doReplace((0, import_node_path.join)(dir, entry.name)).finally(() => {
|
|
144
|
-
promises.delete(p);
|
|
145
|
-
});
|
|
146
|
-
promises.add(p);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
await walk(outDir);
|
|
151
|
-
await Promise.all(promises);
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
// packages/qwik-router/src/adapters/shared/vite/index.ts
|
|
155
|
-
function viteAdapter(opts) {
|
|
156
|
-
let qwikRouterPlugin = null;
|
|
157
|
-
let qwikVitePlugin = null;
|
|
158
|
-
let serverOutDir = null;
|
|
159
|
-
let renderModulePath = null;
|
|
160
|
-
let qwikRouterConfigModulePath = null;
|
|
161
|
-
let isSsrBuild = false;
|
|
162
|
-
const outputEntries = [];
|
|
163
|
-
const plugin = {
|
|
164
|
-
name: `vite-plugin-qwik-router-ssg-${opts.name}`,
|
|
165
|
-
enforce: "post",
|
|
166
|
-
apply: "build",
|
|
167
|
-
config(config) {
|
|
168
|
-
if (typeof opts.config === "function") {
|
|
169
|
-
config = opts.config(config);
|
|
170
|
-
}
|
|
171
|
-
config.define = {
|
|
172
|
-
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || "production"),
|
|
173
|
-
...config.define
|
|
174
|
-
};
|
|
175
|
-
return config;
|
|
176
|
-
},
|
|
177
|
-
configResolved(config) {
|
|
178
|
-
var _a, _b, _c;
|
|
179
|
-
isSsrBuild = !!config.build.ssr;
|
|
180
|
-
if (isSsrBuild) {
|
|
181
|
-
qwikRouterPlugin = config.plugins.find(
|
|
182
|
-
(p) => p.name === "vite-plugin-qwik-router"
|
|
183
|
-
);
|
|
184
|
-
if (!qwikRouterPlugin) {
|
|
185
|
-
throw new Error("Missing vite-plugin-qwik-router");
|
|
186
|
-
}
|
|
187
|
-
qwikVitePlugin = config.plugins.find(
|
|
188
|
-
(p) => p.name === "vite-plugin-qwik"
|
|
189
|
-
);
|
|
190
|
-
if (!qwikVitePlugin) {
|
|
191
|
-
throw new Error("Missing vite-plugin-qwik");
|
|
192
|
-
}
|
|
193
|
-
serverOutDir = config.build.outDir;
|
|
194
|
-
if (((_a = config.build) == null ? void 0 : _a.ssr) !== true) {
|
|
195
|
-
throw new Error(
|
|
196
|
-
`"build.ssr" must be set to "true" in order to use the "${opts.name}" adapter.`
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
if (!((_c = (_b = config.build) == null ? void 0 : _b.rollupOptions) == null ? void 0 : _c.input)) {
|
|
200
|
-
throw new Error(
|
|
201
|
-
`"build.rollupOptions.input" must be set in order to use the "${opts.name}" adapter.`
|
|
202
|
-
);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
},
|
|
206
|
-
buildStart() {
|
|
207
|
-
if (isSsrBuild && opts.ssg !== null) {
|
|
208
|
-
const { srcDir } = qwikVitePlugin.api.getOptions();
|
|
209
|
-
this.emitFile({
|
|
210
|
-
id: "@qwik-router-config",
|
|
211
|
-
type: "chunk",
|
|
212
|
-
fileName: "@qwik-router-config.js"
|
|
213
|
-
});
|
|
214
|
-
this.emitFile({
|
|
215
|
-
id: `${srcDir}/entry.ssr`,
|
|
216
|
-
type: "chunk",
|
|
217
|
-
fileName: "entry.ssr.js"
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
},
|
|
221
|
-
generateBundle(_, bundles) {
|
|
222
|
-
if (isSsrBuild) {
|
|
223
|
-
outputEntries.length = 0;
|
|
224
|
-
for (const fileName in bundles) {
|
|
225
|
-
const chunk = bundles[fileName];
|
|
226
|
-
if (chunk.type === "chunk" && chunk.isEntry) {
|
|
227
|
-
outputEntries.push(fileName);
|
|
228
|
-
if (chunk.name === "entry.ssr") {
|
|
229
|
-
renderModulePath = (0, import_node_path2.join)(serverOutDir, fileName);
|
|
230
|
-
} else if (chunk.name === "@qwik-router-config") {
|
|
231
|
-
qwikRouterConfigModulePath = (0, import_node_path2.join)(serverOutDir, fileName);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
},
|
|
237
|
-
closeBundle: {
|
|
238
|
-
sequential: true,
|
|
239
|
-
async handler() {
|
|
240
|
-
var _a;
|
|
241
|
-
if (isSsrBuild && serverOutDir && (qwikRouterPlugin == null ? void 0 : qwikRouterPlugin.api) && (qwikVitePlugin == null ? void 0 : qwikVitePlugin.api)) {
|
|
242
|
-
const staticPaths = opts.staticPaths || [];
|
|
243
|
-
const routes = qwikRouterPlugin.api.getRoutes();
|
|
244
|
-
const basePathname = qwikRouterPlugin.api.getBasePathname();
|
|
245
|
-
const clientOutDir = qwikVitePlugin.api.getClientOutDir();
|
|
246
|
-
const clientPublicOutDir = qwikVitePlugin.api.getClientPublicOutDir();
|
|
247
|
-
const assetsDir = qwikVitePlugin.api.getAssetsDir();
|
|
248
|
-
const rootDir = qwikVitePlugin.api.getRootDir() ?? void 0;
|
|
249
|
-
if (opts.ssg !== null && renderModulePath && qwikRouterConfigModulePath && clientOutDir && clientPublicOutDir) {
|
|
250
|
-
let ssgOrigin = ((_a = opts.ssg) == null ? void 0 : _a.origin) ?? opts.origin;
|
|
251
|
-
if (!ssgOrigin) {
|
|
252
|
-
ssgOrigin = `https://yoursite.qwik.dev`;
|
|
253
|
-
}
|
|
254
|
-
if (ssgOrigin.length > 0 && !/:\/\//.test(ssgOrigin)) {
|
|
255
|
-
ssgOrigin = `https://${ssgOrigin}`;
|
|
256
|
-
}
|
|
257
|
-
if (ssgOrigin.startsWith("//")) {
|
|
258
|
-
ssgOrigin = `https:${ssgOrigin}`;
|
|
259
|
-
}
|
|
260
|
-
try {
|
|
261
|
-
ssgOrigin = new URL(ssgOrigin).origin;
|
|
262
|
-
} catch {
|
|
263
|
-
this.warn(
|
|
264
|
-
`Invalid "origin" option: "${ssgOrigin}". Using default origin: "https://yoursite.qwik.dev"`
|
|
265
|
-
);
|
|
266
|
-
ssgOrigin = `https://yoursite.qwik.dev`;
|
|
267
|
-
}
|
|
268
|
-
const staticGenerate = await import("../../../ssg/index.cjs");
|
|
269
|
-
const generateOpts = {
|
|
270
|
-
maxWorkers: opts.maxWorkers,
|
|
271
|
-
basePathname,
|
|
272
|
-
outDir: clientPublicOutDir,
|
|
273
|
-
rootDir,
|
|
274
|
-
...opts.ssg,
|
|
275
|
-
origin: ssgOrigin,
|
|
276
|
-
renderModulePath,
|
|
277
|
-
qwikRouterConfigModulePath
|
|
278
|
-
};
|
|
279
|
-
const staticGenerateResult = await staticGenerate.generate(generateOpts);
|
|
280
|
-
if (staticGenerateResult.errors > 0) {
|
|
281
|
-
const err = new Error(
|
|
282
|
-
`Error while running SSG from "${opts.name}" adapter. At least one path failed to render.`
|
|
283
|
-
);
|
|
284
|
-
err.stack = void 0;
|
|
285
|
-
this.error(err);
|
|
286
|
-
}
|
|
287
|
-
staticPaths.push(...staticGenerateResult.staticPaths);
|
|
288
|
-
}
|
|
289
|
-
await postBuild(
|
|
290
|
-
clientPublicOutDir,
|
|
291
|
-
serverOutDir,
|
|
292
|
-
assetsDir ? (0, import_node_path2.join)(basePathname, assetsDir) : basePathname,
|
|
293
|
-
staticPaths,
|
|
294
|
-
!!opts.cleanStaticGenerated
|
|
295
|
-
);
|
|
296
|
-
if (typeof opts.generate === "function") {
|
|
297
|
-
await opts.generate({
|
|
298
|
-
outputEntries,
|
|
299
|
-
serverOutDir,
|
|
300
|
-
clientOutDir,
|
|
301
|
-
clientPublicOutDir,
|
|
302
|
-
basePathname,
|
|
303
|
-
routes,
|
|
304
|
-
assetsDir,
|
|
305
|
-
warn: (message) => this.warn(message),
|
|
306
|
-
error: (message) => this.error(message)
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
this.warn(
|
|
310
|
-
`
|
|
311
|
-
==============================================
|
|
312
|
-
Note: Make sure that you are serving the built files with proper cache headers.
|
|
313
|
-
See https://qwik.dev/docs/deployments/#cache-headers for more information.
|
|
314
|
-
==============================================`
|
|
315
|
-
);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
};
|
|
320
|
-
return plugin;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
// packages/qwik-router/src/adapters/ssg/vite/index.ts
|
|
324
|
-
function ssgAdapter(opts) {
|
|
325
|
-
return viteAdapter({
|
|
326
|
-
name: "static-site-generation",
|
|
327
|
-
origin: opts.origin,
|
|
328
|
-
ssg: {
|
|
329
|
-
include: ["/*"],
|
|
330
|
-
...opts
|
|
331
|
-
}
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
var staticAdapter = ssgAdapter;
|
|
335
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
336
|
-
0 && (module.exports = {
|
|
337
|
-
ssgAdapter,
|
|
338
|
-
staticAdapter
|
|
339
|
-
});
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// packages/qwik-router/src/adapters/vercel-edge/vite/index.ts
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
vercelEdgeAdapter: () => vercelEdgeAdapter
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(index_exports);
|
|
36
|
-
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
37
|
-
var import_node_path = require("node:path");
|
|
38
|
-
var import_vite = require("../../shared/vite/index.cjs");
|
|
39
|
-
function vercelEdgeAdapter(opts = {}) {
|
|
40
|
-
var _a;
|
|
41
|
-
return (0, import_vite.viteAdapter)({
|
|
42
|
-
name: "vercel-edge",
|
|
43
|
-
origin: ((_a = process == null ? void 0 : process.env) == null ? void 0 : _a.VERCEL_URL) || "https://yoursitename.vercel.app",
|
|
44
|
-
ssg: opts.ssg,
|
|
45
|
-
staticPaths: opts.staticPaths,
|
|
46
|
-
cleanStaticGenerated: true,
|
|
47
|
-
config(config) {
|
|
48
|
-
var _a2;
|
|
49
|
-
const outDir = ((_a2 = config.build) == null ? void 0 : _a2.outDir) || (0, import_node_path.join)(".vercel", "output", "functions", "_qwik-router.func");
|
|
50
|
-
return {
|
|
51
|
-
resolve: {
|
|
52
|
-
conditions: opts.target === "node" ? ["node", "import", "module", "browser", "default"] : ["edge-light", "webworker", "worker", "browser", "module", "main"]
|
|
53
|
-
},
|
|
54
|
-
ssr: {
|
|
55
|
-
target: opts.target === "node" ? "node" : "webworker",
|
|
56
|
-
noExternal: true
|
|
57
|
-
},
|
|
58
|
-
build: {
|
|
59
|
-
ssr: true,
|
|
60
|
-
outDir,
|
|
61
|
-
rollupOptions: {
|
|
62
|
-
output: {
|
|
63
|
-
format: "es",
|
|
64
|
-
hoistTransitiveImports: false
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
publicDir: false
|
|
69
|
-
};
|
|
70
|
-
},
|
|
71
|
-
async generate({ clientPublicOutDir, serverOutDir, basePathname, outputEntries }) {
|
|
72
|
-
const vercelOutputDir = (0, import_vite.getParentDir)(serverOutDir, "output");
|
|
73
|
-
if (opts.outputConfig !== false) {
|
|
74
|
-
const vercelOutputConfig = {
|
|
75
|
-
routes: [
|
|
76
|
-
{ handle: "filesystem" },
|
|
77
|
-
{
|
|
78
|
-
src: basePathname + ".*",
|
|
79
|
-
dest: "/_qwik-router"
|
|
80
|
-
}
|
|
81
|
-
],
|
|
82
|
-
version: 3
|
|
83
|
-
};
|
|
84
|
-
await import_node_fs.default.promises.writeFile(
|
|
85
|
-
(0, import_node_path.join)(vercelOutputDir, "config.json"),
|
|
86
|
-
JSON.stringify(vercelOutputConfig, null, 2)
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
let entrypoint = opts.vcConfigEntryPoint;
|
|
90
|
-
if (!entrypoint) {
|
|
91
|
-
if (outputEntries.some((n) => n === "entry.vercel-edge.mjs")) {
|
|
92
|
-
entrypoint = "entry.vercel-edge.mjs";
|
|
93
|
-
} else {
|
|
94
|
-
entrypoint = "entry.vercel-edge.js";
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
const vcConfigPath = (0, import_node_path.join)(serverOutDir, ".vc-config.json");
|
|
98
|
-
const vcConfig = {
|
|
99
|
-
runtime: "edge",
|
|
100
|
-
entrypoint,
|
|
101
|
-
envVarsInUse: opts.vcConfigEnvVarsInUse
|
|
102
|
-
};
|
|
103
|
-
await import_node_fs.default.promises.writeFile(vcConfigPath, JSON.stringify(vcConfig, null, 2));
|
|
104
|
-
let vercelStaticDir = (0, import_node_path.join)(vercelOutputDir, "static");
|
|
105
|
-
const basePathnameParts = basePathname.split("/").filter((p) => p.length > 0);
|
|
106
|
-
if (basePathnameParts.length > 0) {
|
|
107
|
-
vercelStaticDir = (0, import_node_path.join)(vercelStaticDir, ...basePathnameParts);
|
|
108
|
-
}
|
|
109
|
-
await import_node_fs.default.promises.rm(vercelStaticDir, { recursive: true, force: true });
|
|
110
|
-
await import_node_fs.default.promises.mkdir((0, import_node_path.dirname)(vercelStaticDir), { recursive: true });
|
|
111
|
-
await import_node_fs.default.promises.rename(clientPublicOutDir, vercelStaticDir);
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
116
|
-
0 && (module.exports = {
|
|
117
|
-
vercelEdgeAdapter
|
|
118
|
-
});
|