Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support custom loginfo with server mode #520

Merged
merged 5 commits into from Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/BundleAnalyzerPlugin.js
Expand Up @@ -23,6 +23,7 @@ class BundleAnalyzerPlugin {
logLevel: 'info',
// deprecated
startAnalyzer: true,
logInfo: utils.defaultLogInfo,
...opts,
analyzerPort: 'analyzerPort' in opts ? (opts.analyzerPort === 'auto' ? 0 : opts.analyzerPort) : 8888
};
Expand Down Expand Up @@ -107,7 +108,8 @@ class BundleAnalyzerPlugin {
bundleDir: this.getBundleDirFromCompiler(),
logger: this.logger,
defaultSizes: this.opts.defaultSizes,
excludeAssets: this.opts.excludeAssets
excludeAssets: this.opts.excludeAssets,
logInfo: this.opts.logInfo
});
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/utils.js
Expand Up @@ -53,6 +53,15 @@ exports.defaultTitle = function () {
return `${process.env.npm_package_name || 'Webpack Bundle Analyzer'} [${currentTime}]`;
};

exports.defaultLogInfo = function (options) {
const {host, port} = options;
const url = `http://${host}:${port}`;
return (
`${bold("Webpack Bundle Analyzer")} is started at ${bold(url)}\n` +
`Use ${bold("Ctrl+C")} to close it`
);
southorange0929 marked this conversation as resolved.
Show resolved Hide resolved
};

/**
* Calls opener on a URI, but silently try / catches it.
*/
Expand Down
8 changes: 6 additions & 2 deletions src/viewer.js
Expand Up @@ -39,7 +39,8 @@ async function startServer(bundleStats, opts) {
logger = new Logger(),
defaultSizes = 'parsed',
excludeAssets = null,
reportTitle
reportTitle,
logInfo
} = opts || {};

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

const url = `http://${host}:${server.address().port}`;
const url = logInfo({
host,
port: server.address().port
});

logger.info(
`${bold('Webpack Bundle Analyzer')} is started at ${bold(url)}\n` +
Expand Down
3 changes: 2 additions & 1 deletion test/viewer.js
Expand Up @@ -16,7 +16,8 @@ describe('WebSocket server', function () {
const options = {
openBrowser: false,
logger: new Logger('silent'),
port: 0
port: 0,
logInfo: () => ''
};

startServer(bundleStats, options)
Expand Down