@rollup-extras/plugin-size 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/index.js +34 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
1
3
|
# @rollup-extras/plugin-size
|
|
2
4
|
|
|
3
5
|
Rollup plugin that reports the size of generated artifacts — raw, optionally minified, and compressed (gzip and/or brotli).
|
package/index.js
CHANGED
|
@@ -202,33 +202,57 @@ export default function (options) {
|
|
|
202
202
|
|
|
203
203
|
const flags = { gzip: normalizedOptions.gzip, brotli: normalizedOptions.brotli };
|
|
204
204
|
|
|
205
|
-
|
|
205
|
+
let currentStats = {};
|
|
206
|
+
|
|
207
|
+
let buildInputs = new WeakSet();
|
|
208
|
+
let reportComplete = false;
|
|
206
209
|
|
|
207
210
|
const instance = multiConfigPluginBase(false, pluginName, reportAndSave, onEachOutput);
|
|
208
211
|
|
|
209
|
-
if (
|
|
212
|
+
if (outputPlugin) {
|
|
213
|
+
const addInstance = instance.api.addInstance;
|
|
214
|
+
instance.api.addInstance = () => trackBuild(addInstance());
|
|
215
|
+
trackBuild(instance);
|
|
216
|
+
} else {
|
|
210
217
|
instance.buildStart = () => {
|
|
211
|
-
currentStats
|
|
212
|
-
currentStats.chunks = undefined;
|
|
213
|
-
currentStats.assets = undefined;
|
|
218
|
+
currentStats = {};
|
|
214
219
|
};
|
|
215
220
|
}
|
|
216
221
|
|
|
217
222
|
return instance;
|
|
218
223
|
|
|
224
|
+
function trackBuild(plugin) {
|
|
225
|
+
const renderStart = (plugin.renderStart);
|
|
226
|
+
plugin.renderStart = function (outputOptions, inputOptions) {
|
|
227
|
+
|
|
228
|
+
if (reportComplete && !buildInputs.has(inputOptions)) {
|
|
229
|
+
currentStats = {};
|
|
230
|
+
buildInputs = new WeakSet();
|
|
231
|
+
reportComplete = false;
|
|
232
|
+
}
|
|
233
|
+
buildInputs.add(inputOptions);
|
|
234
|
+
return renderStart.call(this, outputOptions, inputOptions);
|
|
235
|
+
};
|
|
236
|
+
return plugin;
|
|
237
|
+
}
|
|
238
|
+
|
|
219
239
|
async function onEachOutput(outputOptions, bundle) {
|
|
220
240
|
await collectStats(currentStats, outputOptions, bundle, flags, minifyFn);
|
|
221
241
|
}
|
|
222
242
|
|
|
223
243
|
async function reportAndSave() {
|
|
224
|
-
|
|
244
|
+
try {
|
|
245
|
+
const statsPath = resolve(process.cwd(), statsFile);
|
|
225
246
|
|
|
226
|
-
|
|
247
|
+
const previousStats = await loadPreviousStats(statsPath);
|
|
227
248
|
|
|
228
|
-
|
|
249
|
+
printReport(currentStats, previousStats, logger);
|
|
229
250
|
|
|
230
|
-
|
|
231
|
-
|
|
251
|
+
if (updateStats) {
|
|
252
|
+
await writeFile(statsPath, `${JSON.stringify(currentStats, null, 2)}\n`);
|
|
253
|
+
}
|
|
254
|
+
} finally {
|
|
255
|
+
reportComplete = true;
|
|
232
256
|
}
|
|
233
257
|
}
|
|
234
258
|
}
|
package/package.json
CHANGED