Skip to content

Commit

Permalink
separate sourcemap flags for client and server
Browse files Browse the repository at this point in the history
  • Loading branch information
pcattori committed Jan 30, 2024
1 parent 074f4ef commit 104658d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 58 deletions.
20 changes: 7 additions & 13 deletions .changeset/curly-camels-applaud.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@
"@remix-run/dev": patch
---

Vite: add `--sourcemap` flag to `remix vite:build`
Vite: add `--sourcemapClient` and `--sourcemapServer` flags to `remix vite:build`

- `--sourcemap` enables source maps for client and server
- `--sourcemap=client` enables source maps for client and server
- `--sourcemap=server` enables source maps for client and server
- `--sourcemapClient`
- `--sourcemapClient=inline`
- `--sourcemapClient=hidden`

Also supports `inline` and `hidden` variants:

- `--sourcemap=inline`
- `--sourcemap=client-inline`
- `--sourcemap=server-inline`

- `--sourcemap=hidden`
- `--sourcemap=client-hidden`
- `--sourcemap=server-hidden`
- `--sourcemapServer`
- `--sourcemapServer=inline`
- `--sourcemapServer=hidden`

See https://vitejs.dev/config/build-options.html#build-sourcemap
7 changes: 6 additions & 1 deletion packages/remix-dev/cli/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,12 @@ export async function run(argv: string[] = process.argv.slice(2)) {
"--open": isBooleanFlag("--open") ? Boolean : String,
"--strictPort": Boolean,
"--profile": Boolean,
"--sourcemap": isBooleanFlag("--sourcemap") ? Boolean : String,
"--sourcemapClient": isBooleanFlag("--sourcemapClient")
? Boolean
: String,
"--sourcemapServer": isBooleanFlag("--sourcemapServer")
? Boolean
: String,
}
: {
// Non Vite commands
Expand Down
49 changes: 5 additions & 44 deletions packages/remix-dev/vite/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,38 +217,6 @@ async function cleanServerBuildDirectory(
}
}

type Sourcemap =
| boolean
| "inline"
| "hidden"
| "client"
| "client-inline"
| "client-hidden"
| "server"
| "server-inline"
| "server-hidden";

function resolveSourcemap(
sourcemap: Sourcemap,
ssr: boolean
): boolean | "inline" | "hidden" {
if (typeof sourcemap === "boolean") return sourcemap;
if (sourcemap.startsWith("client")) {
if (ssr) return false;
if (sourcemap === "client") return true;
if (sourcemap === "client-inline") return "inline";
if (sourcemap === "client-hidden") return "hidden";
}
if (sourcemap.startsWith("server")) {
if (!ssr) return false;
if (sourcemap === "server") return true;
if (sourcemap === "server-inline") return "inline";
if (sourcemap === "server-hidden") return "hidden";
}
console.warn(`Unrecognized sourcemap setting "${sourcemap}"`);
return false;
}

export interface ViteBuildOptions {
assetsInlineLimit?: number;
clearScreen?: boolean;
Expand All @@ -259,16 +227,8 @@ export interface ViteBuildOptions {
minify?: Vite.BuildOptions["minify"];
mode?: string;
profile?: boolean;
sourcemap?:
| boolean
| "inline"
| "hidden"
| "client"
| "client-inline"
| "client-hidden"
| "server"
| "server-inline"
| "server-hidden";
sourcemapClient?: boolean | "inline" | "hidden";
sourcemapServer?: boolean | "inline" | "hidden";
}

export async function build(
Expand All @@ -282,7 +242,8 @@ export async function build(
logLevel,
minify,
mode,
sourcemap = false,
sourcemapClient = false,
sourcemapServer = false,
}: ViteBuildOptions
) {
// Ensure Vite's ESM build is preloaded at the start of the process
Expand All @@ -308,7 +269,7 @@ export async function build(
emptyOutDir,
minify,
ssr,
sourcemap: resolveSourcemap(sourcemap, ssr),
sourcemap: ssr ? sourcemapServer : sourcemapClient,
},
optimizeDeps: { force },
clearScreen,
Expand Down

0 comments on commit 104658d

Please sign in to comment.