sonda
Version:
Universal bundle analyzer and visualizer that works with most popular bundlers and frameworks.
31 lines (30 loc) • 1.22 kB
JavaScript
import { styleText } from "util";
import { Config, SondaWebpackPlugin } from "sonda";
//#region src/entrypoints/next.ts
let turbopackWarningShown = false;
function SondaNextPlugin(userOptions = {}) {
return function Sonda(nextConfig = {}) {
const options = new Config(userOptions, {
integration: "next",
filename: "sonda_[env]_[index]"
});
if (!options.enabled) return nextConfig;
warnIfTurbopackIsUsed();
return Object.assign({}, nextConfig, { webpack(config, { nextRuntime, isServer }) {
const env = nextRuntime || "client";
if (env === "edge" || isServer && !options.server) return config;
const sondaOptions = options.clone();
sondaOptions.filename = sondaOptions.filename.replace("[env]", env);
config.plugins.push(new SondaWebpackPlugin(sondaOptions));
return config;
} });
};
}
function warnIfTurbopackIsUsed() {
const args = process.argv.slice(2);
if (turbopackWarningShown || !args.includes("build") || args.includes("--webpack")) return;
turbopackWarningShown = true;
console.warn(styleText("red", "Sonda does not support Next.js builds with Turbopack yet. Run `next build --webpack` to generate Sonda reports."));
}
//#endregion
export { SondaNextPlugin as default };