mirror of
https://github.com/tenrok/OverlayScrollbars.git
synced 2026-06-22 11:10:37 +03:00
rewrite build size comparison
This commit is contained in:
@@ -54,7 +54,6 @@
|
|||||||
"rollup-plugin-livereload": "^2.0.0",
|
"rollup-plugin-livereload": "^2.0.0",
|
||||||
"rollup-plugin-prettier": "^2.1.0",
|
"rollup-plugin-prettier": "^2.1.0",
|
||||||
"rollup-plugin-serve": "^1.1.0",
|
"rollup-plugin-serve": "^1.1.0",
|
||||||
"rollup-plugin-size-snapshot": "^0.12.0",
|
|
||||||
"rollup-plugin-styles": "^3.10.0",
|
"rollup-plugin-styles": "^3.10.0",
|
||||||
"rollup-plugin-terser": "^6.1.0",
|
"rollup-plugin-terser": "^6.1.0",
|
||||||
"rollup-plugin-typescript2": "^0.27.1",
|
"rollup-plugin-typescript2": "^0.27.1",
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
{
|
|
||||||
"overlayscrollbars.js": {
|
|
||||||
"bundled": 56898,
|
|
||||||
"minified": 17946,
|
|
||||||
"gzipped": 7281
|
|
||||||
},
|
|
||||||
"overlayscrollbars.min.js": {
|
|
||||||
"bundled": 16552,
|
|
||||||
"minified": 16524,
|
|
||||||
"gzipped": 6956
|
|
||||||
},
|
|
||||||
"overlayscrollbars.esm.js": {
|
|
||||||
"bundled": 49032,
|
|
||||||
"minified": 22137,
|
|
||||||
"gzipped": 7992,
|
|
||||||
"treeshaked": {
|
|
||||||
"rollup": {
|
|
||||||
"code": 1641,
|
|
||||||
"import_statements": 0
|
|
||||||
},
|
|
||||||
"webpack": {
|
|
||||||
"code": 2773
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"overlayscrollbars.esm.min.js": {
|
|
||||||
"bundled": 14911,
|
|
||||||
"minified": 14861,
|
|
||||||
"gzipped": 6756,
|
|
||||||
"treeshaked": {
|
|
||||||
"rollup": {
|
|
||||||
"code": 1629,
|
|
||||||
"import_statements": 0
|
|
||||||
},
|
|
||||||
"webpack": {
|
|
||||||
"code": 2762
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+27
-18
@@ -1,7 +1,6 @@
|
|||||||
const { nodeResolve: rollupResolve } = require('@rollup/plugin-node-resolve');
|
const { nodeResolve: rollupResolve } = require('@rollup/plugin-node-resolve');
|
||||||
const { babel: rollupBabelInputPlugin, createBabelInputPluginFactory } = require('@rollup/plugin-babel');
|
const { babel: rollupBabelInputPlugin, createBabelInputPluginFactory } = require('@rollup/plugin-babel');
|
||||||
const { terser: rollupTerser } = require('rollup-plugin-terser');
|
const { terser: rollupTerser } = require('rollup-plugin-terser');
|
||||||
const { sizeSnapshot: rollupSizeSnapshot } = require('rollup-plugin-size-snapshot');
|
|
||||||
const rollupInject = require('@rollup/plugin-inject');
|
const rollupInject = require('@rollup/plugin-inject');
|
||||||
const rollupCommonjs = require('@rollup/plugin-commonjs');
|
const rollupCommonjs = require('@rollup/plugin-commonjs');
|
||||||
const rollupTypescript = require('rollup-plugin-typescript2');
|
const rollupTypescript = require('rollup-plugin-typescript2');
|
||||||
@@ -91,6 +90,22 @@ const rollupBabelPlugin = isTestEnv
|
|||||||
})
|
})
|
||||||
: rollupBabelInputPlugin;
|
: rollupBabelInputPlugin;
|
||||||
|
|
||||||
|
const readFilesStats = (dir, extensions = ['.js', '.css']) => {
|
||||||
|
const result = {};
|
||||||
|
if (fs.existsSync(dir)) {
|
||||||
|
const distFiles = fs.readdirSync(dir);
|
||||||
|
distFiles.forEach((file) => {
|
||||||
|
if (extensions.includes(path.extname(file))) {
|
||||||
|
const stats = fs.lstatSync(path.resolve(dir, file));
|
||||||
|
if (stats.isFile()) {
|
||||||
|
result[path.basename(file)] = stats.size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
const normalizePath = (pathName) => (pathName ? pathName.split(path.sep).join(path.posix.sep) : pathName);
|
const normalizePath = (pathName) => (pathName ? pathName.split(path.sep).join(path.posix.sep) : pathName);
|
||||||
|
|
||||||
const appendExtension = (file) =>
|
const appendExtension = (file) =>
|
||||||
@@ -270,7 +285,7 @@ const rollupConfig = (config = {}, { project = process.cwd(), overwrite = {}, si
|
|||||||
const plugin = typeof item === 'string' ? pipelineMap[item] : item;
|
const plugin = typeof item === 'string' ? pipelineMap[item] : item;
|
||||||
arr.push(...(Array.isArray(plugin) ? plugin : [plugin]));
|
arr.push(...(Array.isArray(plugin) ? plugin : [plugin]));
|
||||||
return arr;
|
return arr;
|
||||||
}, [].concat(isTestEnv ? [] : [rollupSizeSnapshot({ printInfo: false, snapshotPath: sizeSnapshotFilename })])),
|
}, []),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -284,10 +299,12 @@ const rollupConfig = (config = {}, { project = process.cwd(), overwrite = {}, si
|
|||||||
const esm = esmBuild ? genConfig({ esm: true, typeDeclaration: false }) : null;
|
const esm = esmBuild ? genConfig({ esm: true, typeDeclaration: false }) : null;
|
||||||
|
|
||||||
let outputs = 0;
|
let outputs = 0;
|
||||||
|
let existingDistFilesStats;
|
||||||
const builds = [legacy, esm]
|
const builds = [legacy, esm]
|
||||||
.filter((build) => build !== null)
|
.filter((build) => build !== null)
|
||||||
.map((build, index, buildsArr) => {
|
.map((build, index, buildsArr) => {
|
||||||
if (index === 0) {
|
if (index === 0) {
|
||||||
|
existingDistFilesStats = { ...readFilesStats(distPath) };
|
||||||
buildsArr.forEach((build) => {
|
buildsArr.forEach((build) => {
|
||||||
const { output } = build;
|
const { output } = build;
|
||||||
outputs += Array.isArray(output) ? output.length : 1;
|
outputs += Array.isArray(output) ? output.length : 1;
|
||||||
@@ -336,18 +353,13 @@ const rollupConfig = (config = {}, { project = process.cwd(), overwrite = {}, si
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!isTestEnv && !silent) {
|
if (!isTestEnv && !silent) {
|
||||||
const snapshotPath = resolvePath(projectPath, sizeSnapshotFilename);
|
if (existingDistFilesStats) {
|
||||||
if (fs.existsSync(snapshotPath)) {
|
|
||||||
const sizeSnapshotBefore = require(snapshotPath);
|
|
||||||
|
|
||||||
build.plugins.push({
|
build.plugins.push({
|
||||||
name: 'compareSizeSnapshots',
|
name: 'compareDistSizes',
|
||||||
writeBundle() {
|
writeBundle() {
|
||||||
if (isLastFile()) {
|
if (isLastFile()) {
|
||||||
delete require.cache[snapshotPath];
|
const newDistFilesStats = readFilesStats(distPath);
|
||||||
const sizeSnapshotAfter = require(snapshotPath);
|
|
||||||
const { yellow, white, green, red, blackBright } = chalk;
|
const { yellow, white, green, red, blackBright } = chalk;
|
||||||
|
|
||||||
const printColoredPercent = (value) => {
|
const printColoredPercent = (value) => {
|
||||||
const fixed = `${value.toFixed(2)}%`;
|
const fixed = `${value.toFixed(2)}%`;
|
||||||
if (value === 0) {
|
if (value === 0) {
|
||||||
@@ -361,18 +373,15 @@ const rollupConfig = (config = {}, { project = process.cwd(), overwrite = {}, si
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Object.keys(sizeSnapshotAfter).forEach((key) => {
|
Object.keys(existingDistFilesStats).forEach((key) => {
|
||||||
const { bundled, gzipped } = sizeSnapshotAfter[key];
|
const newSize = newDistFilesStats[key];
|
||||||
const { bundled: bundledBefore = bundled / 2, gzipped: gzippedBefore = gzipped / 2 } = sizeSnapshotBefore[key] || {};
|
const oldSize = existingDistFilesStats[key] || 0;
|
||||||
|
const percent = printColoredPercent(oldSize === 0 ? 100 : ((newSize - oldSize) / oldSize) * 100);
|
||||||
const bundledPercent = printColoredPercent(((bundled - bundledBefore) / bundledBefore) * 100);
|
|
||||||
const gzippedPercent = printColoredPercent(((gzipped - gzippedBefore) / gzippedBefore) * 100);
|
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
console.log('');
|
console.log('');
|
||||||
console.log(yellow(key));
|
console.log(yellow(key));
|
||||||
console.log(`bundled: ${bundledPercent}`, blackBright(`(previous: ${bundledBefore} | new: ${bundled})`));
|
console.log(`size change: ${percent}`, blackBright(`(previous: ${oldSize} | new: ${newSize})`));
|
||||||
console.log(`gzipped: ${gzippedPercent}`, blackBright(`(previous: ${gzippedBefore} | new: ${gzipped})`));
|
|
||||||
}, 1);
|
}, 1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user