Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Clean sourcemaps in newer Vite versions #109

Merged
merged 2 commits into from
Feb 22, 2024
Merged
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
7 changes: 7 additions & 0 deletions src/prerender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export function PrerenderPlugin({
}: PrerenderPluginOptions = {}): Plugin {
const preloadHelperId = "vite/preload-helper";
let viteConfig = {} as ResolvedConfig;
let userEnabledSourceMaps: boolean | undefined;

renderTarget ||= "body";
additionalPrerenderRoutes ||= [];
Expand Down Expand Up @@ -118,6 +119,7 @@ export function PrerenderPlugin({
apply: "build",
enforce: "post",
configResolved(config) {
userEnabledSourceMaps = !!config.build.sourcemap;
// Enable sourcemaps for generating more actionable error messages
config.build.sourcemap = true;

Expand Down Expand Up @@ -219,6 +221,11 @@ export function PrerenderPlugin({

let prerenderEntry: OutputChunk | undefined;
for (const output of Object.keys(bundle)) {
// Clean up source maps if the user didn't enable them themselves
if (/\.map$/.test(output) && !userEnabledSourceMaps) {
delete bundle[output];
continue;
}
if (!/\.js$/.test(output) || bundle[output].type !== "chunk") continue;

await fs.writeFile(
Expand Down
Loading