Skip to content

Commit fcc5f4a

Browse files
committed
feat: add silent option
1 parent a32c510 commit fcc5f4a

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ Filename for the report. Defaults to `report.html`.
6363

6464
Directory for the output. Defaults to `.vite-source-map-visualizer`.
6565

66+
### `silent`
67+
68+
Silence plugin's verbose logging.
69+
6670
### `formatName`
6771

6872
Format name of the files:

src/plugin.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from "node:fs/promises";
22
import { join } from "node:path";
3-
import type { Plugin } from "vite";
3+
import type { Logger, Plugin } from "vite";
44

55
import { toVisualizer } from "./generate-link.js";
66
import { 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

2124
interface 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
*/
3033
export 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

Comments
 (0)