mirror of
https://github.com/withastro/astro.git
synced 2025-01-20 22:12:38 -05:00
Remove cheerio scanning from build stats (#1629)
This commit is contained in:
parent
4c9d3cf3d9
commit
b0ef391e57
1 changed files with 18 additions and 14 deletions
|
@ -1,4 +1,3 @@
|
||||||
import cheerio from 'cheerio';
|
|
||||||
import * as eslexer from 'es-module-lexer';
|
import * as eslexer from 'es-module-lexer';
|
||||||
import fetch from 'node-fetch';
|
import fetch from 'node-fetch';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
@ -60,23 +59,28 @@ export async function profileJS({ cwd, entryHTML }: { cwd: URL; entryHTML?: URL
|
||||||
|
|
||||||
// profile HTML entry (do this first, before all JS in a project is scanned)
|
// profile HTML entry (do this first, before all JS in a project is scanned)
|
||||||
if (entryHTML) {
|
if (entryHTML) {
|
||||||
let $ = cheerio.load(await fs.promises.readFile(entryHTML));
|
|
||||||
let entryScripts: URL[] = [];
|
let entryScripts: URL[] = [];
|
||||||
let visitedEntry = false; // note: a quirk of Vite is that the entry file is async-loaded. Count that, but don’t count subsequent async loads
|
let visitedEntry = false; // note: a quirk of Vite is that the entry file is async-loaded. Count that, but don’t count subsequent async loads
|
||||||
|
|
||||||
|
// Note: this function used cheerio to scan HTML, read deps, and build
|
||||||
|
// an accurate, “production-ready” benchmark for how much HTML, JS, and CSS
|
||||||
|
// you shipped. Disabled for now, because we have a post-merge cleanup item
|
||||||
|
// to revisit these build stats.
|
||||||
|
//
|
||||||
|
// let $ = cheerio.load(await fs.promises.readFile(entryHTML));
|
||||||
// scan <script> files, keep adding to total until done
|
// scan <script> files, keep adding to total until done
|
||||||
$('script').each((n, el) => {
|
// $('script').each((n, el) => {
|
||||||
const src = $(el).attr('src');
|
// const src = $(el).attr('src');
|
||||||
const innerHTML = $(el).html();
|
// const innerHTML = $(el).html();
|
||||||
// if inline script, add to overall JS weight
|
// // if inline script, add to overall JS weight
|
||||||
if (innerHTML) {
|
// if (innerHTML) {
|
||||||
htmlSize += Buffer.byteLength(innerHTML);
|
// htmlSize += Buffer.byteLength(innerHTML);
|
||||||
}
|
// }
|
||||||
// otherwise if external script, load & scan it
|
// // otherwise if external script, load & scan it
|
||||||
if (src) {
|
// if (src) {
|
||||||
entryScripts.push(new URL(src, entryHTML));
|
// entryScripts.push(new URL(src, entryHTML));
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
|
||||||
let scanPromises: Promise<void>[] = [];
|
let scanPromises: Promise<void>[] = [];
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue