@statoscope/webpack-plugin
Advanced tools
Comparing version 5.8.0 to 5.9.0
@@ -6,5 +6,4 @@ /// <reference types="node" /> | ||
import { Compilation, Compiler } from 'webpack'; | ||
import { StatsDescriptor } from '@statoscope/stats'; | ||
import { Extension } from '@statoscope/stats/spec/extension'; | ||
import { CompressFunction } from '@statoscope/stats-extension-compressed/dist/generator'; | ||
import { Report } from '@statoscope/types/types/custom-report'; | ||
export declare type Options = { | ||
@@ -21,7 +20,4 @@ name?: string; | ||
compressor: false | 'gzip' | CompressFunction; | ||
reports?: Report<unknown, unknown>[]; | ||
}; | ||
export declare type StatoscopeMeta = { | ||
descriptor: StatsDescriptor; | ||
extensions: Extension<unknown>[]; | ||
}; | ||
export default class StatoscopeWebpackPlugin { | ||
@@ -28,0 +24,0 @@ options: Options; |
@@ -16,2 +16,4 @@ "use strict"; | ||
const normalizeCompilation_1 = __importDefault(require("@statoscope/webpack-model/dist/normalizeCompilation")); | ||
const utils_1 = require("@statoscope/report-writer/dist/utils"); | ||
const generator_1 = __importDefault(require("@statoscope/stats-extension-custom-reports/dist/generator")); | ||
class StatoscopeWebpackPlugin { | ||
@@ -27,2 +29,3 @@ constructor(options = {}) { | ||
watchMode: false, | ||
reports: [], | ||
...options, | ||
@@ -41,8 +44,12 @@ }; | ||
apply(compiler) { | ||
var _a, _b, _c; | ||
const { options } = this; | ||
const context = (_c = (_b = (_a = options.statsOptions) === null || _a === void 0 ? void 0 : _a.context) !== null && _b !== void 0 ? _b : | ||
// @ts-ignore | ||
compiler.options.stats.context) !== null && _c !== void 0 ? _c : compiler.context; | ||
const packageInfoExtension = new webpack_stats_extension_package_info_1.default(); | ||
// @ts-ignore | ||
packageInfoExtension.handleCompiler(compiler); | ||
packageInfoExtension.handleCompiler(compiler, context); | ||
compiler.hooks.done.tapAsync('Statoscope Webpack Plugin', async (stats, cb) => { | ||
var _a; | ||
var _a, _b; | ||
if (compiler.watchMode && !options.watchMode) { | ||
@@ -57,2 +64,3 @@ return cb(); | ||
extensions: [], | ||
context, | ||
}; | ||
@@ -67,3 +75,14 @@ statsObj.__statoscope = statoscopeMeta; | ||
} | ||
const webpackStatsStream = json_ext_1.stringifyStream(statsObj); | ||
const reports = (_a = this.options.reports) !== null && _a !== void 0 ? _a : []; | ||
if (reports.length) { | ||
const generator = new generator_1.default(); | ||
for (const report of reports) { | ||
if (typeof report.data === 'function') { | ||
report.data = await report.data(); | ||
} | ||
generator.handleReport(report); | ||
} | ||
statoscopeMeta.extensions.push(generator.get()); | ||
} | ||
const webpackStatsStream = (0, json_ext_1.stringifyStream)(statsObj, (0, utils_1.makeReplacer)(context, '.', ['context', 'source'])); | ||
let statsFileOutputStream; | ||
@@ -78,6 +97,6 @@ let resolvedSaveStatsTo; | ||
} | ||
normalizeCompilation_1.default(statsObj); | ||
(0, normalizeCompilation_1.default)(statsObj); | ||
const statsForReport = this.getStatsForHTMLReport({ | ||
filename: resolvedSaveStatsTo, | ||
stream: json_ext_1.stringifyStream(statsObj), | ||
stream: (0, json_ext_1.stringifyStream)(statsObj, (0, utils_1.makeReplacer)(context, '.', ['context', 'source'])), | ||
}); | ||
@@ -88,9 +107,9 @@ const htmlReportPath = this.getHTMLReportPath(); | ||
try { | ||
await Promise.all([(_a = htmlReport.writer) === null || _a === void 0 ? void 0 : _a.write(), waitStreamEnd(htmlReport.stream)]); | ||
await Promise.all([(_b = htmlReport.writer) === null || _b === void 0 ? void 0 : _b.write(), waitStreamEnd(htmlReport.stream)]); | ||
if (options.open) { | ||
if (options.open === 'file') { | ||
open_1.default(resolvedHTMLReportPath); | ||
(0, open_1.default)(resolvedHTMLReportPath); | ||
} | ||
else { | ||
open_1.default(path_1.default.dirname(resolvedHTMLReportPath)); | ||
(0, open_1.default)(path_1.default.dirname(resolvedHTMLReportPath)); | ||
} | ||
@@ -149,3 +168,3 @@ } | ||
} | ||
return path_1.default.join(os_1.tmpdir(), defaultReportName); | ||
return path_1.default.join((0, os_1.tmpdir)(), defaultReportName); | ||
} | ||
@@ -152,0 +171,0 @@ } |
{ | ||
"name": "@statoscope/webpack-plugin", | ||
"version": "5.8.0", | ||
"version": "5.9.0", | ||
"description": "Helpers for webpack part of Statoscope", | ||
@@ -22,12 +22,14 @@ "main": "./dist/index.js", | ||
"@discoveryjs/json-ext": "^0.5.5", | ||
"@statoscope/report-writer": "5.8.0", | ||
"@statoscope/report-writer": "5.9.0", | ||
"@statoscope/stats": "5.7.0", | ||
"@statoscope/stats-extension-compressed": "5.7.1", | ||
"@statoscope/webpack-model": "5.8.0", | ||
"@statoscope/webpack-stats-extension-compressed": "5.7.1", | ||
"@statoscope/webpack-stats-extension-package-info": "5.7.1", | ||
"@statoscope/webpack-ui": "5.8.0", | ||
"@statoscope/stats-extension-compressed": "5.9.0", | ||
"@statoscope/stats-extension-custom-reports": "5.9.0", | ||
"@statoscope/types": "5.9.0", | ||
"@statoscope/webpack-model": "5.9.0", | ||
"@statoscope/webpack-stats-extension-compressed": "5.9.0", | ||
"@statoscope/webpack-stats-extension-package-info": "5.9.0", | ||
"@statoscope/webpack-ui": "5.9.0", | ||
"@types/node": "^12.20.15", | ||
"@types/webpack": "^5.28.0", | ||
"open": "^8.0.4" | ||
"open": "^8.2.1" | ||
}, | ||
@@ -37,3 +39,3 @@ "peerDependencies": { | ||
}, | ||
"gitHead": "d7b10e373e8352a955271fd8923778b68f23dfca" | ||
"gitHead": "f8e8a9cd721828a4bc53a2f808441d81e5fdbf84" | ||
} |
@@ -24,3 +24,3 @@ # Statoscope webpack-plugin | ||
There are some **optional** options. | ||
There are some options: | ||
@@ -40,2 +40,3 @@ ```js | ||
compressor: 'gzip', | ||
reports: [/* ... */] | ||
}); | ||
@@ -151,2 +152,37 @@ ``` | ||
### options.reports: Report | ||
List of custom reports that will be passed into the UI. | ||
See report format in [stats-extension-custom-reports readme](/packages/stats-extension-custom-reports/README.md). | ||
**Example:** | ||
```js | ||
new Statoscope({ | ||
reports: [ | ||
{ | ||
id: 'top-20-biggest-modules', | ||
name: 'Top 20 biggest modules', | ||
data: { some: { custom: 'data' } }, // or () => fetchAsyncData() | ||
view: [ | ||
'struct', | ||
{ | ||
data: `#.stats.compilations.( | ||
$compilation: $; | ||
modules.({ | ||
module: $, | ||
hash: $compilation.hash, | ||
size: getModuleSize($compilation.hash) | ||
}) | ||
).sort(size.size desc)[:20]`, | ||
view: 'list', | ||
item: 'module-item', | ||
}, | ||
], | ||
}, | ||
], | ||
}); | ||
``` | ||
## FAQ | ||
@@ -158,3 +194,3 @@ | ||
``` | ||
```jsonc | ||
stats: { | ||
@@ -171,3 +207,3 @@ all: false, // disable all the stats | ||
``` | ||
```jsonc | ||
stats: { | ||
@@ -185,3 +221,3 @@ all: false, // disable all the stats | ||
``` | ||
```jsonc | ||
stats: { | ||
@@ -199,3 +235,3 @@ all: false, // disable all the stats | ||
builtAt: true, // add build at time | ||
timings: true, // add build at time | ||
timings: true, // add timing information | ||
performance: true, // add info about oversized assets | ||
@@ -210,3 +246,3 @@ source: true, // add module sources (uses to find modules duplicates) | ||
``` | ||
```jsonc | ||
stats: { | ||
@@ -213,0 +249,0 @@ context: 'path/to/project/root' |
18792
217
248
14
+ Added@statoscope/types@5.9.0
+ Added@statoscope/helpers@5.9.0(transitive)
+ Added@statoscope/report-writer@5.9.0(transitive)
+ Added@statoscope/stats-extension-compressed@5.9.0(transitive)
+ Added@statoscope/stats-extension-custom-reports@5.9.0(transitive)
+ Added@statoscope/stats-extension-package-info@5.9.0(transitive)
+ Added@statoscope/stats-extension-stats-validation-result@5.9.0(transitive)
+ Added@statoscope/types@5.9.0(transitive)
+ Added@statoscope/webpack-model@5.9.0(transitive)
+ Added@statoscope/webpack-stats-extension-compressed@5.9.0(transitive)
+ Added@statoscope/webpack-stats-extension-package-info@5.9.0(transitive)
+ Added@statoscope/webpack-ui@5.9.0(transitive)
- Removed@statoscope/helpers@5.7.1(transitive)
- Removed@statoscope/report-writer@5.8.0(transitive)
- Removed@statoscope/stats-extension-compressed@5.7.1(transitive)
- Removed@statoscope/stats-extension-package-info@5.7.1(transitive)
- Removed@statoscope/stats-extension-stats-validation-result@5.7.1(transitive)
- Removed@statoscope/types@5.7.1(transitive)
- Removed@statoscope/webpack-model@5.8.0(transitive)
- Removed@statoscope/webpack-stats-extension-compressed@5.7.1(transitive)
- Removed@statoscope/webpack-stats-extension-package-info@5.7.1(transitive)
- Removed@statoscope/webpack-ui@5.8.0(transitive)
Updated@statoscope/webpack-stats-extension-package-info@5.9.0
Updated@statoscope/webpack-ui@5.9.0
Updatedopen@^8.2.1