@cloudflare/vite-plugin 0.0.4 → 0.0.6

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 CHANGED
@@ -466,6 +466,13 @@ The value of `MY_VAR` will therefore be `'Production var'`.
466
466
  If you run `vite build --mode staging` then the 'staging' Vite mode will be used and the 'staging' Cloudflare environment will be selected.
467
467
  The value of `MY_VAR` will therefore be `'Staging var'`.
468
468
 
469
+ ## Secrets
470
+
471
+ Secrets can be provided to your Worker in local development using a [`.dev.vars`](https://developers.cloudflare.com/workers/configuration/secrets/#local-development-with-secrets) file. If you are using [Cloudflare Environments](#cloudflare-environments) then the relevant `.dev.vars` file will be selected. For example, `CLOUDFLARE_ENV=staging vite dev` will load `.dev.vars.staging` if it exists and fall back to `.dev.vars`.
472
+
473
+ > [!NOTE]
474
+ > The `vite build` command copies the relevant `.dev.vars[.env-name]` file to the output directory. This is only used when running `vite preview` and is not deployed with your Worker.
475
+
469
476
  ## Migrating from `wrangler dev`
470
477
 
471
478
  Migrating from `wrangler dev` is a simple process and you can follow the instructions in the [Quick start](#quick-start) to get started.
@@ -2359,7 +2359,10 @@ var vs = (t, e) => {
2359
2359
  return 0;
2360
2360
  };
2361
2361
  var ks = (t) => [...t.slice(16, 16 + 16)].map((n) => n.toString(16).padStart(2, "0")).join("");
2362
- var Ut = (t) => ({ html_handling: t?.html_handling ?? "auto-trailing-slash", not_found_handling: t?.not_found_handling ?? "none", serve_directly: t?.serve_directly ?? true });
2362
+ var Ut = (t) => {
2363
+ let e;
2364
+ return t?.run_worker_first !== void 0 ? e = t?.run_worker_first : t?.serve_directly !== void 0 ? e = !t.serve_directly : e = false, { html_handling: t?.html_handling ?? "auto-trailing-slash", not_found_handling: t?.not_found_handling ?? "none", run_worker_first: e, serve_directly: !e };
2365
+ };
2363
2366
  var Zn = "public, max-age=0, must-revalidate";
2364
2367
  function Qn(t, e, n) {
2365
2368
  let r = new Headers({ "Content-Type": e, ETag: `"${t}"` });
package/dist/index.js CHANGED
@@ -1637,10 +1637,13 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
1637
1637
  ];
1638
1638
  const userWorkers = resolvedPluginConfig.type === "workers" ? Object.entries(resolvedPluginConfig.workers).map(
1639
1639
  ([environmentName, workerConfig]) => {
1640
- const miniflareWorkerOptions = unstable_getMiniflareWorkerOptions({
1641
- ...workerConfig,
1642
- assets: void 0
1643
- });
1640
+ const miniflareWorkerOptions = unstable_getMiniflareWorkerOptions(
1641
+ {
1642
+ ...workerConfig,
1643
+ assets: void 0
1644
+ },
1645
+ resolvedPluginConfig.cloudflareEnv
1646
+ );
1644
1647
  const { ratelimits, ...workerOptions } = miniflareWorkerOptions.workerOptions;
1645
1648
  return {
1646
1649
  ...workerOptions,
@@ -2064,20 +2067,21 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
2064
2067
  const configPaths = /* @__PURE__ */ new Set();
2065
2068
  const persistState = pluginConfig.persistState ?? true;
2066
2069
  const root = userConfig.root ? path5.resolve(userConfig.root) : process.cwd();
2067
- const { CLOUDFLARE_ENV } = vite5.loadEnv(viteEnv.mode, root, "");
2070
+ const { CLOUDFLARE_ENV: cloudflareEnv } = vite5.loadEnv(
2071
+ viteEnv.mode,
2072
+ root,
2073
+ /* prefixes */
2074
+ ""
2075
+ );
2068
2076
  const configPath = pluginConfig.configPath ? path5.resolve(root, pluginConfig.configPath) : findWranglerConfig(root);
2069
2077
  assert6(
2070
2078
  configPath,
2071
2079
  `Config not found. Have you created a wrangler.json(c) or wrangler.toml file?`
2072
2080
  );
2073
- const entryWorkerResolvedConfig = getWorkerConfig(
2074
- configPath,
2075
- CLOUDFLARE_ENV,
2076
- {
2077
- visitedConfigPaths: configPaths,
2078
- isEntryWorker: true
2079
- }
2080
- );
2081
+ const entryWorkerResolvedConfig = getWorkerConfig(configPath, cloudflareEnv, {
2082
+ visitedConfigPaths: configPaths,
2083
+ isEntryWorker: true
2084
+ });
2081
2085
  if (entryWorkerResolvedConfig.type === "assets-only") {
2082
2086
  return {
2083
2087
  type: "assets-only",
@@ -2086,7 +2090,8 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
2086
2090
  persistState,
2087
2091
  rawConfigs: {
2088
2092
  entryWorker: entryWorkerResolvedConfig
2089
- }
2093
+ },
2094
+ cloudflareEnv
2090
2095
  };
2091
2096
  }
2092
2097
  const entryWorkerConfig = entryWorkerResolvedConfig.config;
@@ -2098,7 +2103,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
2098
2103
  for (const auxiliaryWorker of pluginConfig.auxiliaryWorkers ?? []) {
2099
2104
  const workerResolvedConfig = getWorkerConfig(
2100
2105
  path5.resolve(root, auxiliaryWorker.configPath),
2101
- CLOUDFLARE_ENV,
2106
+ cloudflareEnv,
2102
2107
  {
2103
2108
  visitedConfigPaths: configPaths
2104
2109
  }
@@ -2126,7 +2131,8 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
2126
2131
  rawConfigs: {
2127
2132
  entryWorker: entryWorkerResolvedConfig,
2128
2133
  auxiliaryWorkers: auxiliaryWorkersResolvedConfigs
2129
- }
2134
+ },
2135
+ cloudflareEnv
2130
2136
  };
2131
2137
  }
2132
2138
 
@@ -2317,13 +2323,28 @@ function cloudflare2(pluginConfig = {}) {
2317
2323
  );
2318
2324
  }
2319
2325
  config = workerConfig;
2326
+ if (workerConfig.configPath) {
2327
+ const dotDevDotVarsContent = getDotDevDotVarsContent(
2328
+ workerConfig.configPath,
2329
+ resolvedPluginConfig.cloudflareEnv
2330
+ );
2331
+ if (dotDevDotVarsContent) {
2332
+ this.emitFile({
2333
+ type: "asset",
2334
+ fileName: ".dev.vars",
2335
+ source: dotDevDotVarsContent
2336
+ });
2337
+ }
2338
+ }
2320
2339
  } else if (this.environment.name === "client") {
2321
2340
  const assetsOnlyConfig = resolvedPluginConfig.config;
2322
2341
  assetsOnlyConfig.assets.directory = ".";
2342
+ const filesToAssetsIgnore = ["wrangler.json", ".dev.vars"];
2323
2343
  this.emitFile({
2324
2344
  type: "asset",
2325
2345
  fileName: ".assetsignore",
2326
- source: "wrangler.json"
2346
+ source: `${filesToAssetsIgnore.join("\n")}
2347
+ `
2327
2348
  });
2328
2349
  config = assetsOnlyConfig;
2329
2350
  }
@@ -2403,6 +2424,17 @@ function cloudflare2(pluginConfig = {}) {
2403
2424
  }
2404
2425
  };
2405
2426
  }
2427
+ function getDotDevDotVarsContent(configPath, cloudflareEnv) {
2428
+ const configDir = path6.dirname(configPath);
2429
+ const defaultDotDevDotVarsPath = `${configDir}/.dev.vars`;
2430
+ const inputDotDevDotVarsPath = `${defaultDotDevDotVarsPath}${cloudflareEnv ? `.${cloudflareEnv}` : ""}`;
2431
+ const targetPath = fs4.existsSync(inputDotDevDotVarsPath) ? inputDotDevDotVarsPath : fs4.existsSync(defaultDotDevDotVarsPath) ? defaultDotDevDotVarsPath : null;
2432
+ if (targetPath) {
2433
+ const dotDevDotVarsContent = fs4.readFileSync(targetPath);
2434
+ return dotDevDotVarsContent;
2435
+ }
2436
+ return null;
2437
+ }
2406
2438
  export {
2407
2439
  cloudflare2 as cloudflare
2408
2440
  };
@@ -21,7 +21,7 @@ function stripInternalEnv(internalEnv) {
21
21
  return userEnv;
22
22
  }
23
23
 
24
- // ../../node_modules/.pnpm/vite@6.0.7_@types+node@18.19.59_jiti@2.4.2/node_modules/vite/dist/node/module-runner.js
24
+ // ../../node_modules/.pnpm/vite@6.0.7_@types+node@18.19.74_jiti@2.4.2/node_modules/vite/dist/node/module-runner.js
25
25
  var VALID_ID_PREFIX = "/@id/";
26
26
  var NULL_BYTE_PLACEHOLDER = "__x00__";
27
27
  var SOURCEMAPPING_URL = "sourceMa";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudflare/vite-plugin",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "Cloudflare plugin for Vite",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -36,19 +36,19 @@
36
36
  "@hattip/adapter-node": "^0.0.49",
37
37
  "unenv": "npm:unenv-nightly@2.0.0-20241218-183400-5d6aec3",
38
38
  "ws": "^8.18.0",
39
- "miniflare": "3.20250124.0"
39
+ "miniflare": "3.20250129.0"
40
40
  },
41
41
  "devDependencies": {
42
- "@cloudflare/workers-types": "^4.20250121.0",
42
+ "@cloudflare/workers-types": "^4.20250129.0",
43
43
  "@types/node": "^22.10.1",
44
44
  "@types/ws": "^8.5.13",
45
45
  "magic-string": "^0.30.12",
46
46
  "tsup": "8.3.0",
47
47
  "typescript": "^5.7.2",
48
48
  "vite": "^6.0.7",
49
- "@cloudflare/workers-shared": "0.12.5",
49
+ "@cloudflare/workers-shared": "0.13.0",
50
50
  "@cloudflare/workers-tsconfig": "0.0.0",
51
- "wrangler": "3.106.0"
51
+ "wrangler": "3.107.1"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "vite": "^6.0.7",