Skip to content

Commit 45b4db7

Browse files
author
southorange1228
committed
feat: support custom loginfo with server mode
1 parent 7d6039e commit 45b4db7

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

src/BundleAnalyzerPlugin.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class BundleAnalyzerPlugin {
2323
logLevel: 'info',
2424
// deprecated
2525
startAnalyzer: true,
26+
logInfo: utils.defaultLogInfo,
2627
...opts,
2728
analyzerPort: 'analyzerPort' in opts ? (opts.analyzerPort === 'auto' ? 0 : opts.analyzerPort) : 8888
2829
};
@@ -107,7 +108,8 @@ class BundleAnalyzerPlugin {
107108
bundleDir: this.getBundleDirFromCompiler(),
108109
logger: this.logger,
109110
defaultSizes: this.opts.defaultSizes,
110-
excludeAssets: this.opts.excludeAssets
111+
excludeAssets: this.opts.excludeAssets,
112+
logInfo: this.opts.logInfo
111113
});
112114
}
113115
}

src/utils.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ exports.defaultTitle = function () {
5353
return `${process.env.npm_package_name || 'Webpack Bundle Analyzer'} [${currentTime}]`;
5454
};
5555

56+
exports.defaultLogInfo = function (options) {
57+
const {host, port} = options;
58+
const url = `http://${host}:${port}`;
59+
return (
60+
`${bold("Webpack Bundle Analyzer")} is started at ${bold(url)}\n` +
61+
`Use ${bold("Ctrl+C")} to close it`
62+
);
63+
};
64+
5665
/**
5766
* Calls opener on a URI, but silently try / catches it.
5867
*/

src/viewer.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ async function startServer(bundleStats, opts) {
3939
logger = new Logger(),
4040
defaultSizes = 'parsed',
4141
excludeAssets = null,
42-
reportTitle
42+
reportTitle,
43+
logInfo
4344
} = opts || {};
4445

4546
const analyzerOpts = {logger, excludeAssets};
@@ -73,7 +74,10 @@ async function startServer(bundleStats, opts) {
7374
server.listen(port, host, () => {
7475
resolve();
7576

76-
const url = `http://${host}:${server.address().port}`;
77+
const url = logInfo({
78+
host,
79+
port: server.address().port
80+
});
7781

7882
logger.info(
7983
`${bold('Webpack Bundle Analyzer')} is started at ${bold(url)}\n` +

test/viewer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ describe('WebSocket server', function () {
1616
const options = {
1717
openBrowser: false,
1818
logger: new Logger('silent'),
19-
port: 0
19+
port: 0,
20+
logInfo: () => ''
2021
};
2122

2223
startServer(bundleStats, options)

0 commit comments

Comments
 (0)