@cloudflare/vite-plugin 0.0.0-ed3bc2f3b → 0.0.0-ed9162446

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.
Files changed (2) hide show
  1. package/dist/index.js +17 -14
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -1074,7 +1074,6 @@ import * as vite6 from "vite";
1074
1074
 
1075
1075
  // src/cloudflare-environment.ts
1076
1076
  import assert from "node:assert";
1077
- import { builtinModules } from "node:module";
1078
1077
  import * as vite2 from "vite";
1079
1078
 
1080
1079
  // src/constants.ts
@@ -1089,9 +1088,13 @@ var INIT_PATH = "/__vite_plugin_cloudflare_init__";
1089
1088
  var MODULE_PATTERN = `__CLOUDFLARE_MODULE__(${MODULE_TYPES.join("|")})__(.*?)__`;
1090
1089
 
1091
1090
  // src/utils.ts
1091
+ import { builtinModules } from "node:module";
1092
1092
  import * as path from "node:path";
1093
1093
  import { Request as MiniflareRequest } from "miniflare";
1094
1094
  import "vite";
1095
+ var nodeBuiltInModules = new Set(
1096
+ builtinModules.concat(builtinModules.map((m) => `node:${m}`))
1097
+ );
1095
1098
  function getOutputDirectory(userConfig, environmentName) {
1096
1099
  const rootOutputDirectory = userConfig.build?.outDir ?? "dist";
1097
1100
  return userConfig.environments?.[environmentName]?.build?.outDir ?? path.join(rootOutputDirectory, environmentName);
@@ -1207,7 +1210,11 @@ function createCloudflareEnvironmentOptions(workerConfig, userConfig, environmen
1207
1210
  // dependencies as not external
1208
1211
  noExternal: true,
1209
1212
  // We want to use `workerd` package exports if available (e.g. for postgres).
1210
- conditions: [...defaultConditions, "development|production"]
1213
+ conditions: [...defaultConditions, "development|production"],
1214
+ // The Cloudflare ones are proper builtins in the environment
1215
+ builtins: [...cloudflareBuiltInModules],
1216
+ // The Node.js ones are no proper builtins in the environment since we also polyfill them using unenv
1217
+ external: [...nodeBuiltInModules]
1211
1218
  },
1212
1219
  dev: {
1213
1220
  createEnvironment(name2, config) {
@@ -1229,8 +1236,7 @@ function createCloudflareEnvironmentOptions(workerConfig, userConfig, environmen
1229
1236
  // so the input value here serves both as the build input as well as the starting point for
1230
1237
  // dev pre-bundling crawling (were we not to set this input field we'd have to appropriately set
1231
1238
  // optimizeDeps.entries in the dev config)
1232
- input: workerConfig.main,
1233
- external: [...cloudflareBuiltInModules]
1239
+ input: workerConfig.main
1234
1240
  }
1235
1241
  },
1236
1242
  optimizeDeps: {
@@ -1238,9 +1244,8 @@ function createCloudflareEnvironmentOptions(workerConfig, userConfig, environmen
1238
1244
  noDiscovery: false,
1239
1245
  entries: workerConfig.main,
1240
1246
  exclude: [
1241
- ...cloudflareBuiltInModules,
1242
1247
  // we have to exclude all node modules to work in dev-mode not just the unenv externals...
1243
- ...builtinModules.concat(builtinModules.map((m) => `node:${m}`))
1248
+ ...nodeBuiltInModules
1244
1249
  ],
1245
1250
  esbuildOptions: {
1246
1251
  platform: "neutral",
@@ -1585,20 +1590,18 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
1585
1590
  );
1586
1591
  const [moduleId] = invokePayloadData.data;
1587
1592
  const moduleRE = new RegExp(MODULE_PATTERN);
1588
- if (moduleRE.test(moduleId)) {
1593
+ const shouldExternalize = (
1594
+ // Worker modules (CompiledWasm, Text, Data)
1595
+ moduleRE.test(moduleId) || // Node.js builtin node modules (they will be resolved to unenv aliases)
1596
+ nodeBuiltInModules.has(moduleId)
1597
+ );
1598
+ if (shouldExternalize) {
1589
1599
  const result2 = {
1590
1600
  externalize: moduleId,
1591
1601
  type: "module"
1592
1602
  };
1593
1603
  return MiniflareResponse.json({ result: result2 });
1594
1604
  }
1595
- if (moduleId.startsWith("cloudflare:")) {
1596
- const result2 = {
1597
- externalize: moduleId,
1598
- type: "builtin"
1599
- };
1600
- return MiniflareResponse.json({ result: result2 });
1601
- }
1602
1605
  const devEnvironment = viteDevServer.environments[environmentName];
1603
1606
  const result = await devEnvironment.hot.handleInvoke(payload);
1604
1607
  return MiniflareResponse.json(result);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudflare/vite-plugin",
3
- "version": "0.0.0-ed3bc2f3b",
3
+ "version": "0.0.0-ed9162446",
4
4
  "description": "Cloudflare plugin for Vite",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -37,7 +37,7 @@
37
37
  "@hattip/adapter-node": "^0.0.49",
38
38
  "unenv": "2.0.0-rc.1",
39
39
  "ws": "^8.18.0",
40
- "miniflare": "0.0.0-ed3bc2f3b"
40
+ "miniflare": "0.0.0-ed9162446"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@cloudflare/workers-types": "^4.20250204.0",
@@ -51,9 +51,9 @@
51
51
  "vite": "^6.1.0",
52
52
  "vitest": "~3.0.5",
53
53
  "@cloudflare/mock-npm-registry": "0.0.0",
54
- "@cloudflare/workers-shared": "0.0.0-ed3bc2f3b",
55
54
  "@cloudflare/workers-tsconfig": "0.0.0",
56
- "wrangler": "0.0.0-ed3bc2f3b"
55
+ "wrangler": "0.0.0-ed9162446",
56
+ "@cloudflare/workers-shared": "0.0.0-ed9162446"
57
57
  },
58
58
  "peerDependencies": {
59
59
  "vite": "^6.1.0",