Skip to content

fix: sourcemapPlugin uses NODE_ENV instead of Vite mode for nightly detection #280

Description

@edelauna

Bug

webview-ui/src/vite-plugins/sourcemapPlugin.ts uses process.env.NODE_ENV to determine whether to use the nightly output directory:

const mode = process.env.NODE_ENV

if (mode === "nightly") {
    outDir = path.resolve("../apps/vscode-nightly/build/webview-ui/build")
} else {
    outDir = path.resolve("../src/webview-ui/build")
}

When running vite build --mode nightly, Vite sets NODE_ENV=production (not nightly). This means nightly builds have their source maps post-processed in ../src/webview-ui/build instead of ../apps/vscode-nightly/build/webview-ui/build.

Fix

The plugin should accept the Vite mode via its config hook or as a parameter from the calling code, rather than reading NODE_ENV. For example:

export function sourcemapPlugin(): Plugin {
    let buildMode: string

    return {
        name: "vite-plugin-sourcemap",
        apply: "build",
        configResolved(config) {
            buildMode = config.mode
        },
        closeBundle: {
            order: "post",
            handler: async () => {
                const outDir = buildMode === "nightly"
                    ? path.resolve("../apps/vscode-nightly/build/webview-ui/build")
                    : path.resolve("../src/webview-ui/build")
                // ...
            },
        },
    }
}

Found during

Review of #214 (Vite 8 migration).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions