@reckona/mreact-router 0.0.118 → 0.0.120
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 +2 -2
- package/dist/build.d.ts +2 -1
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +32 -0
- package/dist/build.js.map +1 -1
- package/dist/bundle-pipeline.d.ts +3 -3
- package/dist/bundle-pipeline.d.ts.map +1 -1
- package/dist/bundle-pipeline.js.map +1 -1
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +1 -0
- package/dist/render.js.map +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +11 -11
- package/src/build.ts +47 -1
- package/src/bundle-pipeline.ts +2 -2
- package/src/render.ts +2 -0
- package/src/types.ts +1 -0
package/README.md
CHANGED
|
@@ -95,7 +95,7 @@ client-only code. Navigation observers are available from
|
|
|
95
95
|
|
|
96
96
|
## Route Module Exports
|
|
97
97
|
|
|
98
|
-
- `loader(context)` returns data passed to the page component, or may return or throw a `Response` for redirects and custom responses.
|
|
98
|
+
- `loader(context)` returns data passed to the page component, or may return or throw a `Response` for redirects and custom responses. The context includes `params`, `queryClient`, `request`, and adapter `env` when one is provided.
|
|
99
99
|
- `metadata` injects title, OpenGraph, viewport, and related head tags. Use `RouteMetadata` to type the object; `openGraph.image` and `openGraph.images` accept URL scalars or Next-style image objects with a required `url` field.
|
|
100
100
|
- `generateMetadata(context)` may compute route metadata from resolved loader data, params, and the current request. Static `metadata` is still used as the fallback and base object.
|
|
101
101
|
- `generateStaticParams()` returns dynamic route params to prerender and can import modules transformed by configured Vite plugins.
|
|
@@ -324,7 +324,7 @@ For Cloudflare Workers, `mreact-router build --target=cloudflare` emits `.mreact
|
|
|
324
324
|
|
|
325
325
|
For Cloudflare Pages advanced mode, run `mreact-router package cloudflare-pages --from .mreact --out .mreact/pages` after `mreact-router build --target=cloudflare`, then deploy with `wrangler pages deploy .mreact/pages`. The package command creates a Pages output directory with bundled `_worker.js`, `_mreact/client/*` static route assets, root public assets, and `mreact-cloudflare-pages-artifact.json`. Pages provides the `ASSETS` binding to `_worker.js`; mreact's generated worker reads that binding and serves only generated client manifest assets, route-linked CSS, and public files. The package step bundles the generated Worker entry, route registry, route chunks, and router adapter code, so application deploy scripts do not need to copy `worker.mjs` manually or decide whether Wrangler should bundle package imports. If your Worker graph includes dependencies that import Node builtins such as `node:util` or bare `util`, configure Cloudflare Pages with the `nodejs_compat` compatibility flag so the packaged Worker can use Cloudflare's Node.js compatibility runtime.
|
|
326
326
|
|
|
327
|
-
User Vite plugins from the project config are forwarded into router bundle builds after the `mreact-router` plugin itself is removed, so MDX-style syntax transforms and custom content loaders can participate in server, client, Cloudflare, and prerender bundles. Client assets, route stylesheet assets imported by pages/layouts/templates, and copied public assets are served only when they appear in the generated manifest allow-list. Dynamic routes resolve modules through a build-time registry keyed by `route.file`, not by constructing module ids from request input. Generated Cloudflare route modules preserve app-router layout/template shells and named slots for both string and `stream = true` pages, including route-local `<Await>` boundaries and local server-component imports. Generated Cloudflare server route modules dispatch method exports such as `GET`, `POST`, and `ALL` with decoded dynamic params plus `context.env`, `context.context`, `context.request`, and `context.route`, so handlers can use Worker bindings directly. The Cloudflare adapter marks streamed HTML with `Cache-Control: no-transform` and `Content-Encoding: identity` so Workers compression does not gzip-buffer the first shell before placeholders can paint. Pass `onResponse` to add cross-cutting response headers to rendered, static, asset, reload, not-found, and error responses. If a generated Cloudflare route module cannot produce the `data-mreact-route-id` marker contract required by client navigation, the adapter returns a reload signal for `x-mreact-navigation: 1` requests so the browser performs a normal document navigation without first buffering the full HTML response.
|
|
327
|
+
User Vite plugins from the project config are forwarded into router bundle builds after the `mreact-router` plugin itself is removed, so MDX-style syntax transforms and custom content loaders can participate in server, client, Cloudflare, and prerender bundles. Vite `define` values are also forwarded into generated Cloudflare server bundles, including `import.meta.env.*` aliases and plain define identifiers used by loaders and route handlers. Client assets, route stylesheet assets imported by pages/layouts/templates, and copied public assets are served only when they appear in the generated manifest allow-list. Dynamic routes resolve modules through a build-time registry keyed by `route.file`, not by constructing module ids from request input. Generated Cloudflare route modules preserve app-router layout/template shells and named slots for both string and `stream = true` pages, including route-local `<Await>` boundaries and local server-component imports. Generated Cloudflare server route modules dispatch method exports such as `GET`, `POST`, and `ALL` with decoded dynamic params plus `context.env`, `context.context`, `context.request`, and `context.route`, so handlers can use Worker bindings directly. The Cloudflare adapter marks streamed HTML with `Cache-Control: no-transform` and `Content-Encoding: identity` so Workers compression does not gzip-buffer the first shell before placeholders can paint. Pass `onResponse` to add cross-cutting response headers to rendered, static, asset, reload, not-found, and error responses. If a generated Cloudflare route module cannot produce the `data-mreact-route-id` marker contract required by client navigation, the adapter returns a reload signal for `x-mreact-navigation: 1` requests so the browser performs a normal document navigation without first buffering the full HTML response.
|
|
328
328
|
|
|
329
329
|
For AWS Lambda, use `createPreloadedAwsLambdaRequestHandler()` with API Gateway
|
|
330
330
|
HTTP API v2 or Lambda Function URL payload format 2.0:
|
package/dist/build.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export interface BuildAppOptions extends AppRouterProjectOptions {
|
|
|
8
8
|
onBuildPhaseTiming?: ((timing: BuildAppPhaseTiming) => void) | undefined;
|
|
9
9
|
outDir: string;
|
|
10
10
|
targets?: readonly AppRouterBuildTarget[] | undefined;
|
|
11
|
-
viteConfig?: Pick<UserConfig, "plugins"> | undefined;
|
|
11
|
+
viteConfig?: Pick<UserConfig, "define" | "plugins"> | undefined;
|
|
12
12
|
}
|
|
13
13
|
export type BuildAppPhase = "scan" | "collectFiles" | "analyzeSources" | "validate" | "prepareOutput" | "publicAssets" | "serverActionManifest" | "serverModules" | "importPolicy" | "serverModuleArtifacts" | "clientBundles" | "navigationRuntime" | "prerender" | "cloudflare" | "writeManifests" | "adapterArtifacts";
|
|
14
14
|
export interface BuildAppPhaseTiming {
|
|
@@ -139,6 +139,7 @@ interface RouteRequestModuleBatchEntry {
|
|
|
139
139
|
}
|
|
140
140
|
export declare function __buildCloudflareRouteLoaderModuleBatchForTests(options: {
|
|
141
141
|
cacheDir?: string | undefined;
|
|
142
|
+
define?: UserConfig["define"] | undefined;
|
|
142
143
|
projectRoot: string;
|
|
143
144
|
routes: readonly {
|
|
144
145
|
filename: string;
|
package/dist/build.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAwCA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAI5C,OAAO,EAGL,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EAG1B,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAGnD,OAAO,EAAqC,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AA2BnG,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAarD,MAAM,WAAW,eAAgB,SAAQ,uBAAuB;IAC9D,kBAAkB,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,mBAAmB,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IACzE,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,SAAS,oBAAoB,EAAE,GAAG,SAAS,CAAC;IACtD,UAAU,CAAC,EAAE,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC,GAAG,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAwCA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAI5C,OAAO,EAGL,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EAG1B,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,cAA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BAA4B,EAAE,CAAC;IACjD,YAAY,CAAC,EAAE,qBAAqB,GAAG,SAAS,CAAC;IACjD,WAAW,CAAC,EAAE,SAAS,YAAY,EAAE,GAAG,SAAS,CAAC;CACnD,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAUlC;AAwID,UAAU,4BAA4B;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,QAAQ,GAAG,UAAU,CAAC;CAC9B;AAu0CD,wBAAsB,+CAA+C,CAAC,OAAO,EAAE;IAC7E,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,MAAM,CAAC,EAAE,UAAU,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAC;IAC1C,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,SAAS;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACzD,WAAW,CAAC,EAAE,SAAS,YAAY,EAAE,GAAG,SAAS,CAAC;CACnD,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAYlC;AAs6BD,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,+BAA+B,GACvC,OAAO,CAAC,yBAAyB,CAAC,CA4CpC;AA2DD,wBAAsB,8BAA8B,CAClD,OAAO,EAAE,qCAAqC,GAC7C,OAAO,CAAC,+BAA+B,CAAC,CAsD1C"}
|
package/dist/build.js
CHANGED
|
@@ -38,6 +38,7 @@ export async function buildApp(options) {
|
|
|
38
38
|
const routes = timingSink === undefined
|
|
39
39
|
? await scanAppRoutes({ appDir: project.routesDir })
|
|
40
40
|
: await timeBuildPhase(timingSink, "scan", () => scanAppRoutes({ appDir: project.routesDir }));
|
|
41
|
+
const viteDefine = options.viteConfig?.define;
|
|
41
42
|
const vitePlugins = options.viteConfig?.plugins;
|
|
42
43
|
const files = timingSink === undefined
|
|
43
44
|
? await collectBuildFiles(project.projectRoot, project.allowedSourceDirs, project.routesDir)
|
|
@@ -245,6 +246,7 @@ export async function buildApp(options) {
|
|
|
245
246
|
timingSink === undefined
|
|
246
247
|
? await writeCloudflareRouteModules({
|
|
247
248
|
cloudflareDir,
|
|
249
|
+
define: viteDefine,
|
|
248
250
|
files,
|
|
249
251
|
prerenderedRoutes,
|
|
250
252
|
projectRoot: project.projectRoot,
|
|
@@ -256,6 +258,7 @@ export async function buildApp(options) {
|
|
|
256
258
|
})
|
|
257
259
|
: await timeBuildPhase(timingSink, "cloudflare", () => writeCloudflareRouteModules({
|
|
258
260
|
cloudflareDir,
|
|
261
|
+
define: viteDefine,
|
|
259
262
|
files,
|
|
260
263
|
prerenderedRoutes,
|
|
261
264
|
projectRoot: project.projectRoot,
|
|
@@ -1569,6 +1572,7 @@ async function writeCloudflareRouteModules(options) {
|
|
|
1569
1572
|
await mkdir(routesDir, { recursive: true });
|
|
1570
1573
|
const serverRouteModules = await buildCloudflareServerRouteModuleBatch({
|
|
1571
1574
|
cacheDir: options.cacheDir,
|
|
1575
|
+
define: options.define,
|
|
1572
1576
|
routes: requiredRoutes
|
|
1573
1577
|
.filter(({ route }) => route.kind === "server" || route.kind === "metadata")
|
|
1574
1578
|
.map(({ route, routeId }) => ({ filename: route.file, routeId })),
|
|
@@ -1577,6 +1581,7 @@ async function writeCloudflareRouteModules(options) {
|
|
|
1577
1581
|
});
|
|
1578
1582
|
const loaderRouteModules = await buildCloudflareRouteLoaderModuleBatch({
|
|
1579
1583
|
cacheDir: options.cacheDir,
|
|
1584
|
+
define: options.define,
|
|
1580
1585
|
routes: requiredRoutes
|
|
1581
1586
|
.filter(({ route, routeFile }) => route.kind === "page" && options.sourceAnalysis.byRouteFile.get(routeFile)?.hasLoader === true)
|
|
1582
1587
|
.map(({ route, routeId }) => ({ filename: route.file, routeId })),
|
|
@@ -1599,6 +1604,7 @@ async function writeCloudflareRouteModules(options) {
|
|
|
1599
1604
|
const stringShellComponentRouteIds = new Set(stringShellComponentRoutes.map((route) => route.routeId));
|
|
1600
1605
|
const directComponentModules = await buildCloudflareServerComponentModuleBatch({
|
|
1601
1606
|
cacheDir: options.cacheDir,
|
|
1607
|
+
define: options.define,
|
|
1602
1608
|
projectRoot: options.projectRoot,
|
|
1603
1609
|
routes: directComponentRoutes,
|
|
1604
1610
|
serverModules: options.serverModules,
|
|
@@ -1607,6 +1613,7 @@ async function writeCloudflareRouteModules(options) {
|
|
|
1607
1613
|
});
|
|
1608
1614
|
const stringShellComponentModules = await buildCloudflareStringRouteComponentModuleBatch({
|
|
1609
1615
|
cacheDir: options.cacheDir,
|
|
1616
|
+
define: options.define,
|
|
1610
1617
|
projectRoot: options.projectRoot,
|
|
1611
1618
|
routes: stringShellComponentRoutes,
|
|
1612
1619
|
serverModules: options.serverModules,
|
|
@@ -1658,6 +1665,7 @@ async function writeCloudflareRouteModules(options) {
|
|
|
1658
1665
|
const componentOutput = serverOutput === "stream"
|
|
1659
1666
|
? await buildCloudflareStreamRouteComponentModule({
|
|
1660
1667
|
cacheDir: options.cacheDir,
|
|
1668
|
+
define: options.define,
|
|
1661
1669
|
filename: route.file,
|
|
1662
1670
|
projectRoot: options.projectRoot,
|
|
1663
1671
|
routesDir: options.routesDir,
|
|
@@ -1667,6 +1675,7 @@ async function writeCloudflareRouteModules(options) {
|
|
|
1667
1675
|
})
|
|
1668
1676
|
: await buildCloudflareStringRouteComponentModule({
|
|
1669
1677
|
cacheDir: options.cacheDir,
|
|
1678
|
+
define: options.define,
|
|
1670
1679
|
filename: route.file,
|
|
1671
1680
|
projectRoot: options.projectRoot,
|
|
1672
1681
|
routesDir: options.routesDir,
|
|
@@ -1822,6 +1831,7 @@ async function buildCloudflareServerComponentModuleBatch(options) {
|
|
|
1822
1831
|
const bundleEntries = await Promise.all(options.routes.map(async (route) => {
|
|
1823
1832
|
const metadataModule = await buildCloudflareRouteMetadataExportModule({
|
|
1824
1833
|
cacheDir: options.cacheDir,
|
|
1834
|
+
define: options.define,
|
|
1825
1835
|
filename: route.filename,
|
|
1826
1836
|
hasMetadata: buildSourceAnalysisForFile(options.sourceAnalysis, options.projectRoot, route.filename)?.hasMetadata,
|
|
1827
1837
|
root: options.projectRoot,
|
|
@@ -1844,6 +1854,7 @@ async function buildCloudflareServerComponentModuleBatch(options) {
|
|
|
1844
1854
|
const output = await bundleRouterModules({
|
|
1845
1855
|
cacheDir: options.cacheDir,
|
|
1846
1856
|
chunkFileNames: "routes/chunks/[name].[hash].mjs",
|
|
1857
|
+
define: options.define,
|
|
1847
1858
|
entries: bundleEntries,
|
|
1848
1859
|
entryFileNames: "routes/[name].[hash].mjs",
|
|
1849
1860
|
minify: true,
|
|
@@ -1889,6 +1900,7 @@ async function buildCloudflareStringRouteComponentModuleBatch(options) {
|
|
|
1889
1900
|
const pageMetadataId = `mreact:metadata:${route.routeId}:page`;
|
|
1890
1901
|
const pageMetadataModule = await buildCloudflareRouteMetadataExportModule({
|
|
1891
1902
|
cacheDir: options.cacheDir,
|
|
1903
|
+
define: options.define,
|
|
1892
1904
|
filename: route.filename,
|
|
1893
1905
|
hasMetadata: buildSourceAnalysisForFile(options.sourceAnalysis, options.projectRoot, route.filename)?.hasMetadata,
|
|
1894
1906
|
root: options.projectRoot,
|
|
@@ -1908,6 +1920,7 @@ async function buildCloudflareStringRouteComponentModuleBatch(options) {
|
|
|
1908
1920
|
const shellMetadataId = `mreact:metadata:${route.routeId}:shell:${index}`;
|
|
1909
1921
|
const shellMetadataModule = await buildCloudflareRouteMetadataExportModule({
|
|
1910
1922
|
cacheDir: options.cacheDir,
|
|
1923
|
+
define: options.define,
|
|
1911
1924
|
filename: shell.file,
|
|
1912
1925
|
hasMetadata: buildSourceAnalysisForFile(options.sourceAnalysis, options.projectRoot, shell.file)?.hasMetadata,
|
|
1913
1926
|
root: options.projectRoot,
|
|
@@ -1939,6 +1952,7 @@ async function buildCloudflareStringRouteComponentModuleBatch(options) {
|
|
|
1939
1952
|
const output = await bundleRouterModules({
|
|
1940
1953
|
cacheDir: options.cacheDir,
|
|
1941
1954
|
chunkFileNames: "routes/chunks/[name].[hash].mjs",
|
|
1955
|
+
define: options.define,
|
|
1942
1956
|
entries: bundleEntries,
|
|
1943
1957
|
entryFileNames: "routes/[name].[hash].mjs",
|
|
1944
1958
|
minify: true,
|
|
@@ -2047,6 +2061,7 @@ ${cloudflareShellRuntimeSource()}`;
|
|
|
2047
2061
|
async function buildCloudflareServerComponentModule(options) {
|
|
2048
2062
|
const metadataModule = await buildCloudflareRouteMetadataExportModule({
|
|
2049
2063
|
cacheDir: options.cacheDir,
|
|
2064
|
+
define: options.define,
|
|
2050
2065
|
filename: options.filename,
|
|
2051
2066
|
hasMetadata: buildSourceAnalysisForFile(options.sourceAnalysis, options.projectRoot, options.filename)?.hasMetadata,
|
|
2052
2067
|
root: options.projectRoot,
|
|
@@ -2057,6 +2072,7 @@ async function buildCloudflareServerComponentModule(options) {
|
|
|
2057
2072
|
entry,
|
|
2058
2073
|
filename: `${options.filename}.mreact-cloudflare-component.js`,
|
|
2059
2074
|
cacheDir: options.cacheDir,
|
|
2075
|
+
define: options.define,
|
|
2060
2076
|
modules: metadataModule === undefined
|
|
2061
2077
|
? new Map()
|
|
2062
2078
|
: new Map([["mreact:metadata", metadataModule]]),
|
|
@@ -2090,6 +2106,7 @@ async function buildCloudflareStringRouteComponentModule(options) {
|
|
|
2090
2106
|
if (shellFiles.length === 0) {
|
|
2091
2107
|
return buildCloudflareServerComponentModule({
|
|
2092
2108
|
cacheDir: options.cacheDir,
|
|
2109
|
+
define: options.define,
|
|
2093
2110
|
filename: options.filename,
|
|
2094
2111
|
projectRoot: options.projectRoot,
|
|
2095
2112
|
serverModules: options.serverModules,
|
|
@@ -2100,6 +2117,7 @@ async function buildCloudflareStringRouteComponentModule(options) {
|
|
|
2100
2117
|
}
|
|
2101
2118
|
const pageModule = await buildCloudflareComponentExportModule({
|
|
2102
2119
|
cacheDir: options.cacheDir,
|
|
2120
|
+
define: options.define,
|
|
2103
2121
|
filename: options.filename,
|
|
2104
2122
|
projectRoot: options.projectRoot,
|
|
2105
2123
|
serverModules: options.serverModules,
|
|
@@ -2109,6 +2127,7 @@ async function buildCloudflareStringRouteComponentModule(options) {
|
|
|
2109
2127
|
});
|
|
2110
2128
|
const shellModules = await Promise.all(shellFiles.map((shell) => buildCloudflareComponentExportModule({
|
|
2111
2129
|
cacheDir: options.cacheDir,
|
|
2130
|
+
define: options.define,
|
|
2112
2131
|
filename: shell.file,
|
|
2113
2132
|
projectRoot: options.projectRoot,
|
|
2114
2133
|
serverModules: options.serverModules,
|
|
@@ -2171,6 +2190,7 @@ ${cloudflareShellRuntimeSource()}`;
|
|
|
2171
2190
|
return bundleCloudflareVirtualModule({
|
|
2172
2191
|
entry,
|
|
2173
2192
|
cacheDir: options.cacheDir,
|
|
2193
|
+
define: options.define,
|
|
2174
2194
|
filename: `${options.filename}.mreact-cloudflare-string-route.js`,
|
|
2175
2195
|
modules: new Map([
|
|
2176
2196
|
["mreact:page", pageModule],
|
|
@@ -2185,6 +2205,7 @@ ${cloudflareShellRuntimeSource()}`;
|
|
|
2185
2205
|
async function buildCloudflareStreamRouteComponentModule(options) {
|
|
2186
2206
|
const pageModule = await buildCloudflareComponentExportModule({
|
|
2187
2207
|
cacheDir: options.cacheDir,
|
|
2208
|
+
define: options.define,
|
|
2188
2209
|
filename: options.filename,
|
|
2189
2210
|
projectRoot: options.projectRoot,
|
|
2190
2211
|
serverModules: options.serverModules,
|
|
@@ -2195,6 +2216,7 @@ async function buildCloudflareStreamRouteComponentModule(options) {
|
|
|
2195
2216
|
const shellFiles = await cloudflareShellFilesForPage(options.routesDir, options.filename);
|
|
2196
2217
|
const shellModules = await Promise.all(shellFiles.map((shell) => buildCloudflareComponentExportModule({
|
|
2197
2218
|
cacheDir: options.cacheDir,
|
|
2219
|
+
define: options.define,
|
|
2198
2220
|
filename: shell.file,
|
|
2199
2221
|
projectRoot: options.projectRoot,
|
|
2200
2222
|
serverModules: options.serverModules,
|
|
@@ -2275,6 +2297,7 @@ ${cloudflareShellRuntimeSource()}`;
|
|
|
2275
2297
|
return bundleCloudflareVirtualModule({
|
|
2276
2298
|
entry,
|
|
2277
2299
|
cacheDir: options.cacheDir,
|
|
2300
|
+
define: options.define,
|
|
2278
2301
|
filename: `${options.filename}.mreact-cloudflare-stream-route.js`,
|
|
2279
2302
|
modules: new Map([
|
|
2280
2303
|
["mreact:page", pageModule],
|
|
@@ -2584,6 +2607,7 @@ function escapeHtml(value) {
|
|
|
2584
2607
|
async function buildCloudflareComponentExportModule(options) {
|
|
2585
2608
|
const metadataModule = await buildCloudflareRouteMetadataExportModule({
|
|
2586
2609
|
cacheDir: options.cacheDir,
|
|
2610
|
+
define: options.define,
|
|
2587
2611
|
filename: options.filename,
|
|
2588
2612
|
hasMetadata: buildSourceAnalysisForFile(options.sourceAnalysis, options.projectRoot, options.filename)?.hasMetadata,
|
|
2589
2613
|
root: options.projectRoot,
|
|
@@ -2601,6 +2625,7 @@ export const slots = routeModule.slots;`;
|
|
|
2601
2625
|
return bundleCloudflareVirtualModule({
|
|
2602
2626
|
entry,
|
|
2603
2627
|
cacheDir: options.cacheDir,
|
|
2628
|
+
define: options.define,
|
|
2604
2629
|
filename: `${options.filename}.mreact-cloudflare-${options.serverOutput}-component.js`,
|
|
2605
2630
|
modules: metadataModule === undefined
|
|
2606
2631
|
? new Map()
|
|
@@ -2628,6 +2653,7 @@ async function writeCloudflareBatchedRouteModuleChunks(cloudflareDir, modules) {
|
|
|
2628
2653
|
async function buildCloudflareRouteLoaderModuleBatch(options) {
|
|
2629
2654
|
return await bundleCloudflareModuleBatch({
|
|
2630
2655
|
cacheDir: options.cacheDir,
|
|
2656
|
+
define: options.define,
|
|
2631
2657
|
entries: options.routes.map((route) => ({
|
|
2632
2658
|
code: cloudflareRouteLoaderModuleEntry(route.filename),
|
|
2633
2659
|
filename: `${route.filename}.mreact-cloudflare-loader.js`,
|
|
@@ -2641,6 +2667,7 @@ async function buildCloudflareRouteLoaderModuleBatch(options) {
|
|
|
2641
2667
|
export async function __buildCloudflareRouteLoaderModuleBatchForTests(options) {
|
|
2642
2668
|
const output = await buildCloudflareRouteLoaderModuleBatch({
|
|
2643
2669
|
cacheDir: options.cacheDir,
|
|
2670
|
+
define: options.define,
|
|
2644
2671
|
root: options.projectRoot,
|
|
2645
2672
|
routes: options.routes,
|
|
2646
2673
|
vitePlugins: options.vitePlugins,
|
|
@@ -2650,6 +2677,7 @@ export async function __buildCloudflareRouteLoaderModuleBatchForTests(options) {
|
|
|
2650
2677
|
async function buildCloudflareServerRouteModuleBatch(options) {
|
|
2651
2678
|
return await bundleCloudflareModuleBatch({
|
|
2652
2679
|
cacheDir: options.cacheDir,
|
|
2680
|
+
define: options.define,
|
|
2653
2681
|
entries: options.routes.map((route) => ({
|
|
2654
2682
|
code: cloudflareServerRouteModuleEntry(route.filename),
|
|
2655
2683
|
filename: `${route.filename}.mreact-cloudflare-server-route.js`,
|
|
@@ -2667,6 +2695,7 @@ async function bundleCloudflareModuleBatch(options) {
|
|
|
2667
2695
|
const output = await bundleRouterModules({
|
|
2668
2696
|
cacheDir: options.cacheDir,
|
|
2669
2697
|
chunkFileNames: "routes/chunks/[name].[hash].mjs",
|
|
2698
|
+
define: options.define,
|
|
2670
2699
|
entries: options.entries,
|
|
2671
2700
|
entryFileNames: "routes/[name].[hash].mjs",
|
|
2672
2701
|
minify: true,
|
|
@@ -2706,6 +2735,7 @@ export const metadata = routeMetadataModule.metadata;`;
|
|
|
2706
2735
|
return bundleCloudflareModule({
|
|
2707
2736
|
entry,
|
|
2708
2737
|
cacheDir: options.cacheDir,
|
|
2738
|
+
define: options.define,
|
|
2709
2739
|
filename: `${options.filename}.mreact-cloudflare-metadata.js`,
|
|
2710
2740
|
plugins: [cloudflareWorkspaceRuntimePlugin()],
|
|
2711
2741
|
resolveDir: dirname(options.filename),
|
|
@@ -2731,6 +2761,7 @@ async function bundleCloudflareModule(options) {
|
|
|
2731
2761
|
const output = await bundleRouterModule({
|
|
2732
2762
|
cacheDir: options.cacheDir,
|
|
2733
2763
|
code: options.entry,
|
|
2764
|
+
define: options.define,
|
|
2734
2765
|
filename: options.filename,
|
|
2735
2766
|
minify: true,
|
|
2736
2767
|
platform: "node",
|
|
@@ -2749,6 +2780,7 @@ async function bundleCloudflareModule(options) {
|
|
|
2749
2780
|
async function bundleCloudflareVirtualModule(options) {
|
|
2750
2781
|
return bundleCloudflareModule({
|
|
2751
2782
|
cacheDir: options.cacheDir,
|
|
2783
|
+
define: options.define,
|
|
2752
2784
|
entry: options.entry,
|
|
2753
2785
|
filename: options.filename,
|
|
2754
2786
|
plugins: [
|