update
This commit is contained in:
+16
-8
@@ -6,8 +6,6 @@ const {
|
||||
dirname
|
||||
} = require('path');
|
||||
|
||||
const _ = require('lodash');
|
||||
|
||||
const commander = require('commander');
|
||||
|
||||
const {
|
||||
@@ -20,29 +18,37 @@ const viewer = require('../viewer');
|
||||
|
||||
const Logger = require('../Logger');
|
||||
|
||||
const utils = require('../utils');
|
||||
|
||||
const SIZES = new Set(['stat', 'parsed', 'gzip']);
|
||||
const program = commander.version(require('../../package.json').version).usage(`<bundleStatsFile> [bundleDir] [options]
|
||||
|
||||
Arguments:
|
||||
|
||||
|
||||
bundleStatsFile Path to Webpack Stats JSON file.
|
||||
bundleDir Directory containing all generated bundles.
|
||||
You should provided it if you want analyzer to show you the real parsed module sizes.
|
||||
By default a directory of stats file is used.`).option('-m, --mode <mode>', 'Analyzer mode. Should be `server`,`static` or `json`.' + br('In `server` mode analyzer will start HTTP server to show bundle report.') + br('In `static` mode single HTML file with bundle report will be generated.') + br('In `json` mode single JSON file with bundle report will be generated.'), 'server').option( // Had to make `host` parameter optional in order to let `-h` flag output help message
|
||||
// Fixes https://github.com/webpack-contrib/webpack-bundle-analyzer/issues/239
|
||||
'-h, --host [host]', 'Host that will be used in `server` mode to start HTTP server.', '127.0.0.1').option('-p, --port <n>', 'Port that will be used in `server` mode to start HTTP server.', 8888).option('-r, --report <file>', 'Path to bundle report file that will be generated in `static` mode.').option('-s, --default-sizes <type>', 'Module sizes to show in treemap by default.' + br(`Possible values: ${[...SIZES].join(', ')}`), 'parsed').option('-O, --no-open', "Don't open report in default browser automatically.").option('-e, --exclude <regexp>', 'Assets that should be excluded from the report.' + br('Can be specified multiple times.'), array()).option('-l, --log-level <level>', 'Log level.' + br(`Possible values: ${[...Logger.levels].join(', ')}`), Logger.defaultLevel).parse(process.argv);
|
||||
'-h, --host [host]', 'Host that will be used in `server` mode to start HTTP server.', '127.0.0.1').option('-p, --port <n>', 'Port that will be used in `server` mode to start HTTP server.', 8888).option('-r, --report <file>', 'Path to bundle report file that will be generated in `static` mode.').option('-t, --title <title>', 'String to use in title element of html report.').option('-s, --default-sizes <type>', 'Module sizes to show in treemap by default.' + br(`Possible values: ${[...SIZES].join(', ')}`), 'parsed').option('-O, --no-open', "Don't open report in default browser automatically.").option('-e, --exclude <regexp>', 'Assets that should be excluded from the report.' + br('Can be specified multiple times.'), array()).option('-l, --log-level <level>', 'Log level.' + br(`Possible values: ${[...Logger.levels].join(', ')}`), Logger.defaultLevel).parse(process.argv);
|
||||
let [bundleStatsFile, bundleDir] = program.args;
|
||||
let {
|
||||
mode,
|
||||
host,
|
||||
port,
|
||||
report: reportFilename,
|
||||
title: reportTitle,
|
||||
defaultSizes,
|
||||
logLevel,
|
||||
open: openBrowser,
|
||||
exclude: excludeAssets,
|
||||
args: [bundleStatsFile, bundleDir]
|
||||
} = program;
|
||||
exclude: excludeAssets
|
||||
} = program.opts();
|
||||
const logger = new Logger(logLevel);
|
||||
|
||||
if (typeof reportTitle === 'undefined') {
|
||||
reportTitle = utils.defaultTitle;
|
||||
}
|
||||
|
||||
if (!bundleStatsFile) showHelp('Provide path to Webpack Stats file as first argument');
|
||||
|
||||
if (mode !== 'server' && mode !== 'static' && mode !== 'json') {
|
||||
@@ -74,6 +80,7 @@ if (mode === 'server') {
|
||||
port,
|
||||
host,
|
||||
defaultSizes,
|
||||
reportTitle,
|
||||
bundleDir,
|
||||
excludeAssets,
|
||||
logger: new Logger(logLevel)
|
||||
@@ -82,6 +89,7 @@ if (mode === 'server') {
|
||||
viewer.generateReport(bundleStats, {
|
||||
openBrowser,
|
||||
reportFilename: resolve(reportFilename || 'report.html'),
|
||||
reportTitle,
|
||||
defaultSizes,
|
||||
bundleDir,
|
||||
excludeAssets,
|
||||
@@ -103,7 +111,7 @@ function showHelp(error) {
|
||||
}
|
||||
|
||||
function br(str) {
|
||||
return `\n${_.repeat(' ', 28)}${str}`;
|
||||
return `\n${' '.repeat(28)}${str}`;
|
||||
}
|
||||
|
||||
function array() {
|
||||
|
||||
Reference in New Issue
Block a user