File tree Expand file tree Collapse file tree 2 files changed +58
-5
lines changed Expand file tree Collapse file tree 2 files changed +58
-5
lines changed Original file line number Diff line number Diff line change 11# vite-plugin-source-map-visualizer
22
3+ <a href =" https://www.npmjs.com/package/vite-plugin-source-map-visualizer " >
4+ <img alt="version" src="https://img.shields.io/npm/v/vite-plugin-source-map-visualizer" />
5+ </a >
6+
7+ [ Installation] ( #installation ) | [ Configuration] ( #configuration ) | [ Credits] ( #credits )
8+
39> Vite plugin for generating source map visualizations of transform results
410
11+ ` vite-plugin-source-map-visualizer ` is a Vite plugin for inspecting source maps of the transformed files. It generates HTML report that provides quick way for seeing how the tranformed files look in [ source-map-visualization] ( https://github.com/evanw/source-map-visualization ) . See [ live example] ( https://ariperkkio.github.io/vite-plugin-source-map-visualizer/ ) .
12+
13+ For more detailed plugin debugging tool you might want to check [ ` vite-plugin-inspect ` ] ( https://github.com/antfu-collective/vite-plugin-inspect ) instead.
14+
15+ <br />
516<img src =" https://github.com/user-attachments/assets/e22e1559-9b5f-48a2-912d-b3f59c6be9cd " width =" 420px " />
17+ <br />
18+ <br />
619
7- ## Install
20+ ## Installation
821
922``` bash
1023$ npm install --save-dev vite-plugin-source-map-visualizer
@@ -26,7 +39,31 @@ Run Vite and check `.vite-source-map-visualizer/report.html`:
2639 └── report.html
2740```
2841
42+ ## Configuration
43+
44+ You can pass options to the plugin as function arguments:
45+
46+ ``` ts
47+ export default defineConfig ({
48+ plugins: [
49+ sourcemapVisualizer ({
50+ filename: " my-report.html" ,
51+ }),
52+ ],
53+ });
54+ ```
55+
56+ ### ` filename `
57+
58+ Filename for the report. Defaults to ` report.html ` .
59+
60+ ### ` outDir `
61+
62+ Directory for the output. Defaults to ` .vite-source-map-visualizer ` .
63+
2964## Credits
3065
66+ Special thanks to:
67+
3168- [ ` vite-plugin-inspect ` ] ( https://github.com/antfu-collective/vite-plugin-inspect ) from [ @antfu ] ( https://github.com/antfu )
3269- [ source-map-visualization] ( https://github.com/evanw/source-map-visualization ) from [ @evanw ] ( https://github.com/evanw )
Original file line number Diff line number Diff line change @@ -5,17 +5,33 @@ import type { Plugin } from "vite";
55import { toVisualizer } from "./generate-link.js" ;
66import { script , style } from "./report.js" ;
77
8+ interface Options {
9+ /** Filename for the report. Defaults to `report.html` */
10+ filename ?: string ;
11+
12+ /** Directory for the output. Defaults to `.vite-source-map-visualizer` */
13+ outDir ?: string ;
14+ }
15+
816interface Result {
917 filename : string ;
1018 hash : string ;
1119 ssr : boolean ;
1220}
1321
14- const outDir = join ( process . cwd ( ) , ".vite-source-map-visualizer" ) ;
15-
16- export function sourcemapVisualizer ( ) : Plugin {
22+ /**
23+ * Generate HTML report for inspecting the transformed files in https://evanw.github.io/source-map-visualization/
24+ */
25+ export function sourcemapVisualizer ( options ?: Options ) : Plugin {
1726 const results : Result [ ] = [ ] ;
1827
28+ const outDir = join (
29+ process . cwd ( ) ,
30+ options ?. outDir || ".vite-source-map-visualizer"
31+ ) ;
32+
33+ const reportName = options ?. filename || "report.html" ;
34+
1935 return {
2036 name : "source-map-visualizer" ,
2137 enforce : "post" ,
@@ -34,7 +50,7 @@ export function sourcemapVisualizer(): Plugin {
3450 } ,
3551
3652 async buildEnd ( ) {
37- const filename = `${ outDir } /report.html ` ;
53+ const filename = `${ outDir } /${ reportName } ` ;
3854 const html = generateHTML ( results , filename ) ;
3955 await fs . writeFile ( filename , html , "utf8" ) ;
4056 } ,
You can’t perform that action at this time.
0 commit comments