File tree Expand file tree Collapse file tree 2 files changed +17
-11
lines changed Expand file tree Collapse file tree 2 files changed +17
-11
lines changed Original file line number Diff line number Diff line change @@ -76,7 +76,7 @@ export function sourcemapVisualizer(options?: Options): Plugin {
7676 async buildEnd ( ) {
7777 try {
7878 const filename = `${ outDir } /${ reportName } ` ;
79- const html = generateHTML ( results , filename ) ;
79+ const html = generateHTML ( results ) ;
8080 await fs . writeFile ( filename , html , "utf8" ) ;
8181 } catch ( error ) {
8282 console . error ( error ) ;
@@ -86,7 +86,7 @@ export function sourcemapVisualizer(options?: Options): Plugin {
8686 } ;
8787}
8888
89- function generateHTML ( results : Result [ ] , root : string ) {
89+ function generateHTML ( results : Result [ ] ) {
9090 // prettier-ignore
9191 return `
9292<!DOCTYPE html>
@@ -102,7 +102,7 @@ function generateHTML(results: Result[], root: string) {
102102<body>
103103 <main>
104104 <h1>
105- <a href="${ root } ">Vite Source Map Visualizer</a>
105+ <a href="# ">Vite Source Map Visualizer</a>
106106 </h1>
107107
108108 <button id="menu" title="Toggle file list">
@@ -130,7 +130,7 @@ function generateHTML(results: Result[], root: string) {
130130 ${ results . map ( ( result ) => `
131131 <tr>
132132 <td>
133- <a href="${ root } ?filename= ${ result . filename } #${ result . hash } ">
133+ <a href="#${ result . hash } ">
134134 ${ escapeHTML ( result . filename ) }
135135 </a>
136136 </td>
Original file line number Diff line number Diff line change @@ -23,18 +23,24 @@ export function script() {
2323 fileList . open = ! fileList . open ;
2424 } ) ;
2525
26- const url = new URL ( window . location . href ) ;
27- const filename = url . searchParams . get ( "filename" ) ;
26+ initializePage ( ) ;
27+ addEventListener ( "hashchange" , initializePage ) ;
2828
29- if ( filename ) {
29+ function initializePage ( ) {
30+ const fileList = document . querySelector ( "details#files" as "details" ) ! ;
3031 const iframe = document . querySelector (
3132 "iframe#source-map-visualizer" as "iframe"
3233 ) ! ;
33- iframe . src = `https://evanw.github.io/source-map-visualization${ url . hash } ` ;
34- iframe . style . display = "block" ;
3534
36- const fileList = document . querySelector ( "details#files" as "details" ) ! ;
37- fileList . open = false ;
35+ if ( window . location . hash ) {
36+ iframe . src = `https://evanw.github.io/source-map-visualization${ window . location . hash } ` ;
37+ iframe . style . display = "block" ;
38+ fileList . open = false ;
39+ } else {
40+ iframe . src = "" ;
41+ iframe . style . display = "none" ;
42+ fileList . open = true ;
43+ }
3844 }
3945}
4046/* v8 ignore stop */
You can’t perform that action at this time.
0 commit comments