@cloudflare/vite-plugin 0.0.8 → 0.1.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 CHANGED
@@ -1236,6 +1236,7 @@ function createCloudflareEnvironmentOptions(workerConfig, userConfig, environmen
1236
1236
  optimizeDeps: {
1237
1237
  // Note: ssr pre-bundling is opt-in and we need to enable it by setting `noDiscovery` to false
1238
1238
  noDiscovery: false,
1239
+ entries: workerConfig.main,
1239
1240
  exclude: [
1240
1241
  ...cloudflareBuiltInModules,
1241
1242
  // we have to exclude all node modules to work in dev-mode not just the unenv externals...
@@ -1321,33 +1322,33 @@ function writeDeployConfig(resolvedPluginConfig, resolvedViteConfig) {
1321
1322
  };
1322
1323
  fs.writeFileSync(deployConfigPath, JSON.stringify(deployConfig));
1323
1324
  } else {
1324
- const workerConfigPaths = Object.fromEntries(
1325
- Object.keys(resolvedPluginConfig.workers).map((environmentName) => {
1326
- const outputDirectory = resolvedViteConfig.environments[environmentName]?.build.outDir;
1327
- assert2(
1328
- outputDirectory,
1329
- `Unexpected error: ${environmentName} environment output directory is undefined`
1330
- );
1331
- return [
1332
- environmentName,
1333
- getRelativePathToWorkerConfig(
1334
- deployConfigDirectory,
1335
- resolvedViteConfig.root,
1336
- outputDirectory
1337
- )
1338
- ];
1339
- })
1340
- );
1341
- const { entryWorkerEnvironmentName } = resolvedPluginConfig;
1342
- const configPath = workerConfigPaths[entryWorkerEnvironmentName];
1325
+ let entryWorkerConfigPath;
1326
+ const auxiliaryWorkers = [];
1327
+ for (const environmentName of Object.keys(resolvedPluginConfig.workers)) {
1328
+ const outputDirectory = resolvedViteConfig.environments[environmentName]?.build.outDir;
1329
+ assert2(
1330
+ outputDirectory,
1331
+ `Unexpected error: ${environmentName} environment output directory is undefined`
1332
+ );
1333
+ const configPath = getRelativePathToWorkerConfig(
1334
+ deployConfigDirectory,
1335
+ resolvedViteConfig.root,
1336
+ outputDirectory
1337
+ );
1338
+ if (environmentName === resolvedPluginConfig.entryWorkerEnvironmentName) {
1339
+ entryWorkerConfigPath = configPath;
1340
+ } else {
1341
+ auxiliaryWorkers.push({ configPath });
1342
+ }
1343
+ }
1343
1344
  assert2(
1344
- configPath,
1345
- `Unexpected error: ${entryWorkerEnvironmentName} environment output directory is undefined`
1345
+ entryWorkerConfigPath,
1346
+ `Unexpected error: entryWorkerConfigPath is undefined`
1346
1347
  );
1347
- const auxiliaryWorkers = Object.entries(workerConfigPaths).filter(
1348
- ([environmentName]) => environmentName !== entryWorkerEnvironmentName
1349
- ).map(([_, configPath2]) => ({ configPath: configPath2 }));
1350
- const deployConfig = { configPath, auxiliaryWorkers };
1348
+ const deployConfig = {
1349
+ configPath: entryWorkerConfigPath,
1350
+ auxiliaryWorkers
1351
+ };
1351
1352
  fs.writeFileSync(deployConfigPath, JSON.stringify(deployConfig));
1352
1353
  }
1353
1354
  }
@@ -2304,7 +2305,6 @@ function cloudflare2(pluginConfig = {}) {
2304
2305
  )
2305
2306
  );
2306
2307
  }
2307
- writeDeployConfig(resolvedPluginConfig, resolvedViteConfig);
2308
2308
  }
2309
2309
  }
2310
2310
  };
@@ -2376,6 +2376,11 @@ function cloudflare2(pluginConfig = {}) {
2376
2376
  source: JSON.stringify(config)
2377
2377
  });
2378
2378
  },
2379
+ writeBundle() {
2380
+ if (this.environment.name === (resolvedPluginConfig.type === "assets-only" ? "client" : resolvedPluginConfig.entryWorkerEnvironmentName)) {
2381
+ writeDeployConfig(resolvedPluginConfig, resolvedViteConfig);
2382
+ }
2383
+ },
2379
2384
  handleHotUpdate(options) {
2380
2385
  if (resolvedPluginConfig.configPaths.has(options.file)) {
2381
2386
  options.server.restart();
@@ -2400,11 +2405,14 @@ function cloudflare2(pluginConfig = {}) {
2400
2405
  resolvedPluginConfig,
2401
2406
  miniflare
2402
2407
  );
2403
- const middleware = createMiddleware(({ request }) => {
2404
- return entryWorker.fetch(toMiniflareRequest(request), {
2405
- redirect: "manual"
2406
- });
2407
- });
2408
+ const middleware = createMiddleware(
2409
+ ({ request }) => {
2410
+ return entryWorker.fetch(toMiniflareRequest(request), {
2411
+ redirect: "manual"
2412
+ });
2413
+ },
2414
+ { alwaysCallNext: false }
2415
+ );
2408
2416
  handleWebSocket(
2409
2417
  viteDevServer.httpServer,
2410
2418
  entryWorker.fetch,
@@ -2423,11 +2431,14 @@ function cloudflare2(pluginConfig = {}) {
2423
2431
  pluginConfig.persistState ?? true
2424
2432
  )
2425
2433
  );
2426
- const middleware = createMiddleware(({ request }) => {
2427
- return miniflare2.dispatchFetch(toMiniflareRequest(request), {
2428
- redirect: "manual"
2429
- });
2430
- });
2434
+ const middleware = createMiddleware(
2435
+ ({ request }) => {
2436
+ return miniflare2.dispatchFetch(toMiniflareRequest(request), {
2437
+ redirect: "manual"
2438
+ });
2439
+ },
2440
+ { alwaysCallNext: false }
2441
+ );
2431
2442
  handleWebSocket(
2432
2443
  vitePreviewServer.httpServer,
2433
2444
  miniflare2.dispatchFetch,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudflare/vite-plugin",
3
- "version": "0.0.8",
3
+ "version": "0.1.0",
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": "3.20250204.0"
40
+ "miniflare": "3.20250204.1"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@cloudflare/workers-types": "^4.20250204.0",
@@ -47,9 +47,9 @@
47
47
  "tsup": "8.3.0",
48
48
  "typescript": "^5.7.2",
49
49
  "vite": "^6.1.0",
50
- "@cloudflare/workers-shared": "0.13.2",
50
+ "@cloudflare/workers-shared": "0.14.1",
51
51
  "@cloudflare/workers-tsconfig": "0.0.0",
52
- "wrangler": "3.108.0"
52
+ "wrangler": "3.109.0"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "vite": "^6.1.0",