-
Notifications
You must be signed in to change notification settings - Fork 1
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
[FEATURE]: New Frontend Static Auditor - Bundle Analyze #119
Comments
-> The result should take on account: simple folder and nested folders (monorepo)
At this level we have all needed modules to start building frontends.
Each step should correspond to a commit if possible and try to validate each step with a unit test if possible. |
Code Draft: import AppLogger from '@v6y/core-logic/src/core/AppLogger.js';
import path from 'path';
const isFrontend = (module) => {
/// if dependencies react ou angular
};
const getFrontendBundler = (dependencies) => {
// vite, webpack, next
};
const isBundleChunckConform = ({ name, size }) => {
// if size > 600kb
// if name is not hashed
};
const getFrontendDirectories = (directory, frontendModules) => {
try {
const files = fs.readdirSync(directory);
frontendModules = frontendModules || [];
files.forEach(function (module) {
if (fs.statSync(directory + '/' + module).isDirectory()) {
const directoryFiles = fs.readdirSync(module);
if (directoryFiles?.includes('package.json') && isFrontend(module)) {
frontendModules.push(path.join(directory, module));
} else {
frontendModules = getFrontendDirectories(
directory + '/' + file,
frontendModules,
);
}
}
});
return frontendModules;
} catch (error) {
AppLogger.info(`[AuditUtils - getFilesRecursively] error: ${error}`);
return [];
}
};
const analyzeBundle = (workspaceFolder) => {
const frontendModules = getFrontendDirectories(workspaceFolder);
for (const module in frontendModules) {
const packageManger = detect();
execSync(`${packageManger} install`, { cwd: module });
const frontendBundler = getFrontendBundler('');
// vite: pnpm analyze
// webpack: ....
// next: pnpm ANALYZE=true pnpm build
const outputAnalyze = execSync('commande analyze');
if (isBundleChunckConform(outputAnalyze)) {
// audit report
} else {
// audit report
}
}
}; |
✨ Description
Extends the static auditor to add "Bundle Analyze".
https://github.com/ekino/v6y/tree/main/v6y-apps/bfb-static-auditor/src/auditors
The bundle analyze provide stats about the dist that will be delivered to the prod.
We should add new auditor:
bundle-analyzer
Starting from the worskpace (where code is checkout to be analyzed):
We should launch npm or pnpm or yarn install according to project configuration.
We should find frontend modules:
-> a frontend module should have a package.json that contains
react
as dependency (for example).-> for each frontend module we should identify which bundler is used: webpack, vite, rspack, next, ...
-> for each type of bundler we should execute a bundle analyze script: npm run ....
https://medium.com/ekino-france/rspack-an-engineers-approach-to-build-system-innovation-924e57c596a0
https://medium.com/ekino-france/beyond-webpack-esbuild-vite-rollup-swc-and-snowpack-97911a7175cf
Once we have stats of bundle and chuncks size:
-> if a chunck has a size < 600KO Gzip -> it's assumed good
-> else an error with an exception should be trigerred.
https://www.npmjs.com/package/vite-bundle-visualizer
The text was updated successfully, but these errors were encountered: