Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export function createCloudflareEnvironmentOptions({
workerConfig,
userConfig,
mode,
command,
environmentName,
isEntryWorker,
isParentEnvironment,
Expand All @@ -200,6 +201,7 @@ export function createCloudflareEnvironmentOptions({
workerConfig: ResolvedWorkerConfig;
userConfig: vite.UserConfig;
mode: vite.ConfigEnv["mode"];
command: vite.ConfigEnv["command"];
environmentName: string;
isEntryWorker: boolean;
isParentEnvironment: boolean;
Expand Down Expand Up @@ -236,6 +238,10 @@ export function createCloudflareEnvironmentOptions({
createEnvironment(name, config) {
return new vite.BuildEnvironment(name, config);
},
sourcemap:
workerConfig.upload_source_maps === true && command === "build"
? true
: undefined,
target,
emitAssets: true,
manifest: isEntryWorker,
Expand Down
13 changes: 10 additions & 3 deletions packages/vite-plugin-cloudflare/src/plugins/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { createPlugin, debuglog, getOutputDirectory } from "../utils";
import { validateWorkerEnvironmentOptions } from "../vite-config";
import { getWarningForWorkersConfigs } from "../workers-configs";
import type { PluginContext } from "../context";
import type { EnvironmentOptions, UserConfig } from "vite";
import type { ConfigEnv, EnvironmentOptions, UserConfig } from "vite";

/**
* Plugin to handle configuration and config file watching
Expand Down Expand Up @@ -48,7 +48,12 @@ export const configPlugin = createPlugin("config", (ctx) => {
deny: [...defaultDeniedFiles, ".dev.vars", ".dev.vars.*"],
},
},
environments: getEnvironmentsConfig(ctx, userConfig, env.mode),
environments: getEnvironmentsConfig(
ctx,
userConfig,
env.mode,
env.command
),
builder: {
buildApp:
userConfig.builder?.buildApp ??
Expand Down Expand Up @@ -144,7 +149,8 @@ export const configPlugin = createPlugin("config", (ctx) => {
function getEnvironmentsConfig(
ctx: PluginContext,
userConfig: UserConfig,
mode: string
mode: ConfigEnv["mode"],
command: ConfigEnv["command"]
): Record<string, EnvironmentOptions> | undefined {
if (ctx.resolvedPluginConfig.type !== "workers") {
return undefined;
Expand All @@ -164,6 +170,7 @@ function getEnvironmentsConfig(
workerConfig: worker.config,
userConfig,
mode,
command,
hasNodeJsCompat: ctx.getNodeJsCompat(environmentName) !== undefined,
};

Expand Down