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 {
76
76
async buildEnd ( ) {
77
77
try {
78
78
const filename = `${ outDir } /${ reportName } ` ;
79
- const html = generateHTML ( results , filename ) ;
79
+ const html = generateHTML ( results ) ;
80
80
await fs . writeFile ( filename , html , "utf8" ) ;
81
81
} catch ( error ) {
82
82
console . error ( error ) ;
@@ -86,7 +86,7 @@ export function sourcemapVisualizer(options?: Options): Plugin {
86
86
} ;
87
87
}
88
88
89
- function generateHTML ( results : Result [ ] , root : string ) {
89
+ function generateHTML ( results : Result [ ] ) {
90
90
// prettier-ignore
91
91
return `
92
92
<!DOCTYPE html>
@@ -102,7 +102,7 @@ function generateHTML(results: Result[], root: string) {
102
102
<body>
103
103
<main>
104
104
<h1>
105
- <a href="${ root } ">Vite Source Map Visualizer</a>
105
+ <a href="# ">Vite Source Map Visualizer</a>
106
106
</h1>
107
107
108
108
<button id="menu" title="Toggle file list">
@@ -130,7 +130,7 @@ function generateHTML(results: Result[], root: string) {
130
130
${ results . map ( ( result ) => `
131
131
<tr>
132
132
<td>
133
- <a href="${ root } ?filename= ${ result . filename } #${ result . hash } ">
133
+ <a href="#${ result . hash } ">
134
134
${ escapeHTML ( result . filename ) }
135
135
</a>
136
136
</td>
Original file line number Diff line number Diff line change @@ -23,18 +23,24 @@ export function script() {
23
23
fileList . open = ! fileList . open ;
24
24
} ) ;
25
25
26
- const url = new URL ( window . location . href ) ;
27
- const filename = url . searchParams . get ( "filename" ) ;
26
+ initializePage ( ) ;
27
+ addEventListener ( "hashchange" , initializePage ) ;
28
28
29
- if ( filename ) {
29
+ function initializePage ( ) {
30
+ const fileList = document . querySelector ( "details#files" as "details" ) ! ;
30
31
const iframe = document . querySelector (
31
32
"iframe#source-map-visualizer" as "iframe"
32
33
) ! ;
33
- iframe . src = `https://evanw.github.io/source-map-visualization${ url . hash } ` ;
34
- iframe . style . display = "block" ;
35
34
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
+ }
38
44
}
39
45
}
40
46
/* v8 ignore stop */
You can’t perform that action at this time.
0 commit comments