@cloudflare/vite-plugin 1.11.7 → 1.12.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.js +61 -30
- package/package.json +10 -11
package/dist/index.js
CHANGED
|
@@ -753,9 +753,6 @@ var generateStaticRoutingRuleMatcher = (rules) => ({ request: request2 }) => {
|
|
|
753
753
|
return false;
|
|
754
754
|
};
|
|
755
755
|
|
|
756
|
-
// src/index.ts
|
|
757
|
-
import replace from "@rollup/plugin-replace";
|
|
758
|
-
|
|
759
756
|
// ../../node_modules/.pnpm/@jridgewell+sourcemap-codec@1.5.0/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
|
|
760
757
|
var comma = ",".charCodeAt(0);
|
|
761
758
|
var semicolon = ";".charCodeAt(0);
|
|
@@ -1821,7 +1818,7 @@ var MagicString = class _MagicString {
|
|
|
1821
1818
|
};
|
|
1822
1819
|
|
|
1823
1820
|
// src/index.ts
|
|
1824
|
-
import { Miniflare } from "miniflare";
|
|
1821
|
+
import { CoreHeaders, Miniflare } from "miniflare";
|
|
1825
1822
|
import colors4 from "picocolors";
|
|
1826
1823
|
import * as vite6 from "vite";
|
|
1827
1824
|
|
|
@@ -13443,7 +13440,7 @@ var WORKER_ENTRY_PATH_HEADER = "__VITE_WORKER_ENTRY_PATH__";
|
|
|
13443
13440
|
|
|
13444
13441
|
// src/utils.ts
|
|
13445
13442
|
import * as path6 from "node:path";
|
|
13446
|
-
import { createRequest, sendResponse } from "@
|
|
13443
|
+
import { createRequest, sendResponse } from "@remix-run/node-fetch-server";
|
|
13447
13444
|
import {
|
|
13448
13445
|
Request as MiniflareRequest,
|
|
13449
13446
|
Response as MiniflareResponse
|
|
@@ -13576,7 +13573,14 @@ var cloudflareBuiltInModules = [
|
|
|
13576
13573
|
];
|
|
13577
13574
|
var defaultConditions = ["workerd", "worker", "module", "browser"];
|
|
13578
13575
|
var target = "es2022";
|
|
13579
|
-
function createCloudflareEnvironmentOptions(
|
|
13576
|
+
function createCloudflareEnvironmentOptions({
|
|
13577
|
+
workerConfig,
|
|
13578
|
+
userConfig,
|
|
13579
|
+
mode,
|
|
13580
|
+
environmentName,
|
|
13581
|
+
isEntryWorker
|
|
13582
|
+
}) {
|
|
13583
|
+
const define = getProcessEnvReplacements(workerConfig, mode);
|
|
13580
13584
|
return {
|
|
13581
13585
|
resolve: {
|
|
13582
13586
|
// Note: in order for ssr pre-bundling to take effect we need to ask vite to treat all
|
|
@@ -13587,6 +13591,7 @@ function createCloudflareEnvironmentOptions(workerConfig, userConfig, environmen
|
|
|
13587
13591
|
// The Cloudflare ones are proper builtins in the environment
|
|
13588
13592
|
builtins: [...cloudflareBuiltInModules]
|
|
13589
13593
|
},
|
|
13594
|
+
define,
|
|
13590
13595
|
dev: {
|
|
13591
13596
|
createEnvironment(name, config) {
|
|
13592
13597
|
return new CloudflareDevEnvironment(name, config);
|
|
@@ -13598,8 +13603,8 @@ function createCloudflareEnvironmentOptions(workerConfig, userConfig, environmen
|
|
|
13598
13603
|
},
|
|
13599
13604
|
target,
|
|
13600
13605
|
emitAssets: true,
|
|
13601
|
-
manifest:
|
|
13602
|
-
outDir: getOutputDirectory(userConfig,
|
|
13606
|
+
manifest: isEntryWorker,
|
|
13607
|
+
outDir: getOutputDirectory(userConfig, environmentName),
|
|
13603
13608
|
copyPublicDir: false,
|
|
13604
13609
|
ssr: true,
|
|
13605
13610
|
rollupOptions: {
|
|
@@ -13629,11 +13634,26 @@ function createCloudflareEnvironmentOptions(workerConfig, userConfig, environmen
|
|
|
13629
13634
|
".cjs",
|
|
13630
13635
|
".cts",
|
|
13631
13636
|
".ctx"
|
|
13632
|
-
]
|
|
13637
|
+
],
|
|
13638
|
+
define
|
|
13633
13639
|
}
|
|
13634
13640
|
},
|
|
13635
|
-
//
|
|
13636
|
-
keepProcessEnv:
|
|
13641
|
+
// We manually set `process.env` replacements using `define`
|
|
13642
|
+
keepProcessEnv: true
|
|
13643
|
+
};
|
|
13644
|
+
}
|
|
13645
|
+
function getProcessEnvReplacements(workerConfig, mode) {
|
|
13646
|
+
const nodeEnv = process.env.NODE_ENV || mode;
|
|
13647
|
+
const nodeEnvReplacements = {
|
|
13648
|
+
"process.env.NODE_ENV": JSON.stringify(nodeEnv),
|
|
13649
|
+
"global.process.env.NODE_ENV": JSON.stringify(nodeEnv),
|
|
13650
|
+
"globalThis.process.env.NODE_ENV": JSON.stringify(nodeEnv)
|
|
13651
|
+
};
|
|
13652
|
+
return isNodeCompat(workerConfig) ? nodeEnvReplacements : {
|
|
13653
|
+
...nodeEnvReplacements,
|
|
13654
|
+
"process.env": "{}",
|
|
13655
|
+
"global.process.env": "{}",
|
|
13656
|
+
"globalThis.process.env": "{}"
|
|
13637
13657
|
};
|
|
13638
13658
|
}
|
|
13639
13659
|
function initRunners(resolvedPluginConfig, viteDevServer, miniflare2) {
|
|
@@ -15282,6 +15302,7 @@ async function getDevMiniflareOptions(config) {
|
|
|
15282
15302
|
inspectorPort: inspectorPort === false ? void 0 : inspectorPort,
|
|
15283
15303
|
unsafeInspectorProxy: inspectorPort !== false,
|
|
15284
15304
|
unsafeDevRegistryPath: getDefaultDevRegistryPath(),
|
|
15305
|
+
unsafeTriggerHandlers: true,
|
|
15285
15306
|
handleRuntimeStdio(stdout, stderr) {
|
|
15286
15307
|
const decoder = new TextDecoder();
|
|
15287
15308
|
stdout.forEach((data2) => logger.info(decoder.decode(data2)));
|
|
@@ -15495,6 +15516,7 @@ async function getPreviewMiniflareOptions(config) {
|
|
|
15495
15516
|
inspectorPort: inspectorPort === false ? void 0 : inspectorPort,
|
|
15496
15517
|
unsafeInspectorProxy: inspectorPort !== false,
|
|
15497
15518
|
unsafeDevRegistryPath: getDefaultDevRegistryPath(),
|
|
15519
|
+
unsafeTriggerHandlers: true,
|
|
15498
15520
|
handleRuntimeStdio(stdout, stderr) {
|
|
15499
15521
|
const decoder = new TextDecoder();
|
|
15500
15522
|
stdout.forEach((data2) => logger.info(decoder.decode(data2)));
|
|
@@ -16033,7 +16055,7 @@ ${[
|
|
|
16033
16055
|
}
|
|
16034
16056
|
|
|
16035
16057
|
// src/websockets.ts
|
|
16036
|
-
import { createHeaders } from "@
|
|
16058
|
+
import { createHeaders } from "@remix-run/node-fetch-server";
|
|
16037
16059
|
import { coupleWebSocket } from "miniflare";
|
|
16038
16060
|
import { WebSocketServer } from "ws";
|
|
16039
16061
|
function handleWebSocket(httpServer, getFetcher) {
|
|
@@ -16124,14 +16146,13 @@ function cloudflare(pluginConfig = {}) {
|
|
|
16124
16146
|
([environmentName, workerConfig]) => {
|
|
16125
16147
|
return [
|
|
16126
16148
|
environmentName,
|
|
16127
|
-
createCloudflareEnvironmentOptions(
|
|
16149
|
+
createCloudflareEnvironmentOptions({
|
|
16128
16150
|
workerConfig,
|
|
16129
16151
|
userConfig,
|
|
16130
|
-
|
|
16131
|
-
|
|
16132
|
-
|
|
16133
|
-
|
|
16134
|
-
)
|
|
16152
|
+
mode: env2.mode,
|
|
16153
|
+
environmentName,
|
|
16154
|
+
isEntryWorker: resolvedPluginConfig.type === "workers" && environmentName === resolvedPluginConfig.entryWorkerEnvironmentName
|
|
16155
|
+
})
|
|
16135
16156
|
];
|
|
16136
16157
|
}
|
|
16137
16158
|
)
|
|
@@ -16613,18 +16634,6 @@ if (import.meta.hot) {
|
|
|
16613
16634
|
configEnvironment(name) {
|
|
16614
16635
|
if (isNodeCompat(getWorkerConfig2(name))) {
|
|
16615
16636
|
return {
|
|
16616
|
-
build: {
|
|
16617
|
-
rollupOptions: {
|
|
16618
|
-
plugins: [
|
|
16619
|
-
replace({
|
|
16620
|
-
"process.env.NODE_ENV": JSON.stringify(
|
|
16621
|
-
process.env.NODE_ENV ?? "production"
|
|
16622
|
-
),
|
|
16623
|
-
preventAssignment: true
|
|
16624
|
-
})
|
|
16625
|
-
]
|
|
16626
|
-
}
|
|
16627
|
-
},
|
|
16628
16637
|
resolve: {
|
|
16629
16638
|
builtins: [...nodeCompatExternals]
|
|
16630
16639
|
},
|
|
@@ -16843,6 +16852,28 @@ if (import.meta.hot) {
|
|
|
16843
16852
|
}
|
|
16844
16853
|
}
|
|
16845
16854
|
}
|
|
16855
|
+
},
|
|
16856
|
+
// Plugin to handle cron/email/etc triggers
|
|
16857
|
+
{
|
|
16858
|
+
name: "vite-plugin-cloudflare:trigger-handlers",
|
|
16859
|
+
enforce: "pre",
|
|
16860
|
+
async configureServer(viteDevServer) {
|
|
16861
|
+
assertIsNotPreview(resolvedPluginConfig);
|
|
16862
|
+
if (resolvedPluginConfig.type === "workers") {
|
|
16863
|
+
const entryWorkerConfig = getEntryWorkerConfig(resolvedPluginConfig);
|
|
16864
|
+
assert12(entryWorkerConfig, `No entry Worker config`);
|
|
16865
|
+
const entryWorkerName = entryWorkerConfig.name;
|
|
16866
|
+
viteDevServer.middlewares.use("/cdn-cgi/", (req, res, next) => {
|
|
16867
|
+
const requestHandler = createRequestHandler((request2) => {
|
|
16868
|
+
assert12(miniflare, `Miniflare not defined`);
|
|
16869
|
+
request2.headers.set(CoreHeaders.ROUTE_OVERRIDE, entryWorkerName);
|
|
16870
|
+
return miniflare.dispatchFetch(request2, { redirect: "manual" });
|
|
16871
|
+
});
|
|
16872
|
+
req.url = req.originalUrl;
|
|
16873
|
+
requestHandler(req, res, next);
|
|
16874
|
+
});
|
|
16875
|
+
}
|
|
16876
|
+
}
|
|
16846
16877
|
}
|
|
16847
16878
|
];
|
|
16848
16879
|
function getWorkerConfig2(environmentName) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudflare/vite-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"description": "Cloudflare plugin for Vite",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -33,19 +33,18 @@
|
|
|
33
33
|
"dist"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@
|
|
37
|
-
"@rollup/plugin-replace": "^6.0.1",
|
|
36
|
+
"@remix-run/node-fetch-server": "^0.8.0",
|
|
38
37
|
"get-port": "^7.1.0",
|
|
39
38
|
"picocolors": "^1.1.1",
|
|
40
39
|
"tinyglobby": "^0.2.12",
|
|
41
40
|
"unenv": "2.0.0-rc.19",
|
|
42
41
|
"ws": "8.18.0",
|
|
43
|
-
"@cloudflare/unenv-preset": "2.6.
|
|
44
|
-
"
|
|
45
|
-
"
|
|
42
|
+
"@cloudflare/unenv-preset": "2.6.3",
|
|
43
|
+
"miniflare": "4.20250823.0",
|
|
44
|
+
"wrangler": "4.33.0"
|
|
46
45
|
},
|
|
47
46
|
"devDependencies": {
|
|
48
|
-
"@cloudflare/workers-types": "^4.
|
|
47
|
+
"@cloudflare/workers-types": "^4.20250823.0",
|
|
49
48
|
"@types/node": "^22.10.1",
|
|
50
49
|
"@types/ws": "^8.5.13",
|
|
51
50
|
"magic-string": "^0.30.12",
|
|
@@ -54,14 +53,14 @@
|
|
|
54
53
|
"typescript": "^5.8.3",
|
|
55
54
|
"vite": "7.0.0",
|
|
56
55
|
"vitest": "~3.2.0",
|
|
57
|
-
"@cloudflare/mock-npm-registry": "0.0.0",
|
|
58
56
|
"@cloudflare/containers-shared": "0.2.10",
|
|
59
|
-
"@cloudflare/
|
|
60
|
-
"@cloudflare/workers-tsconfig": "0.0.0"
|
|
57
|
+
"@cloudflare/mock-npm-registry": "0.0.0",
|
|
58
|
+
"@cloudflare/workers-tsconfig": "0.0.0",
|
|
59
|
+
"@cloudflare/workers-shared": "0.18.6"
|
|
61
60
|
},
|
|
62
61
|
"peerDependencies": {
|
|
63
62
|
"vite": "^6.1.0 || ^7.0.0",
|
|
64
|
-
"wrangler": "^4.
|
|
63
|
+
"wrangler": "^4.33.0"
|
|
65
64
|
},
|
|
66
65
|
"publishConfig": {
|
|
67
66
|
"access": "public"
|