11import fs from "node:fs/promises" ;
22import { join } from "node:path" ;
3- import type { Plugin } from "vite" ;
3+ import type { Logger , Plugin } from "vite" ;
44
55import { toVisualizer } from "./generate-link.js" ;
66import { script , style } from "./report.js" ;
@@ -16,6 +16,9 @@ interface Options {
1616
1717 /** Format name of the transformed file */
1818 formatName ?: ( filename : string ) => string ;
19+
20+ /** Silence verbose logging. */
21+ silent ?: boolean ;
1922}
2023
2124interface Result {
@@ -28,6 +31,7 @@ interface Result {
2831 * Generate HTML report for inspecting the transformed files in https://evanw.github.io/source-map-visualization/
2932 */
3033export function sourcemapVisualizer ( options ?: Options ) : Plugin {
34+ let logger : Logger ;
3135 const results : Result [ ] = [ ] ;
3236
3337 const outDir = join (
@@ -37,6 +41,7 @@ export function sourcemapVisualizer(options?: Options): Plugin {
3741
3842 const reportName = options ?. filename || "report.html" ;
3943 const formatName = options ?. formatName || defaultFormatName ;
44+ const silent = options ?. silent || false ;
4045
4146 return {
4247 name : PLUGIN_NAME ,
@@ -48,6 +53,8 @@ export function sourcemapVisualizer(options?: Options): Plugin {
4853 } ,
4954
5055 configResolved ( config ) {
56+ logger = config . logger ;
57+
5158 try {
5259 const index = config . plugins . findIndex (
5360 ( plugin ) => plugin . name === PLUGIN_NAME
@@ -78,6 +85,10 @@ export function sourcemapVisualizer(options?: Options): Plugin {
7885 const filename = `${ outDir } /${ reportName } ` ;
7986 const html = generateHTML ( results ) ;
8087 await fs . writeFile ( filename , html , "utf8" ) ;
88+
89+ if ( ! silent ) {
90+ logger . info ( `Report written to ${ filename } ` ) ;
91+ }
8192 } catch ( error ) {
8293 console . error ( error ) ;
8394 throw error ;
0 commit comments