UNPKG

gatsby-performance-budget

Version:

A package to check performance budget against the page weight of every page

46 lines (35 loc) 1.1 kB
const { fork } = require("child_process"); const path = require("path"); const { getPages, getReport } = require("./helpers.js"); const budgetPath = path.join(process.cwd(), "/budget.js"); const budget = require(budgetPath); const options = { chromeFlags: ["--headless"], throttlingMethod: "devtools", onlyCategories: ["performance"] }; const config = { extends: "lighthouse:default", settings: { budgets: budget } }; exports.start = async () => { const bin = "node_modules/.bin/gatsby"; const gatsby = path.join(process.cwd(), bin); const buildProcess = await fork(gatsby, ["build"]); buildProcess.on("exit", async () => { try { const serveProcess = await fork(gatsby, ["serve"]); const dir = path.join(process.cwd(), "public"); const pagesDir = await getPages(dir); const slugs = pagesDir.map(i => i.replace(dir, "")); await getReport(slugs, options, config); serveProcess.on("exit", async () => { console.log("Production build has been served!"); }); } catch (error) { console.log(error); } }); };