daedalOS/next.config.js
2025-04-22 19:52:19 -07:00

91 lines
2.2 KiB
JavaScript

// @ts-check
const isProduction = process.env.NODE_ENV === "production";
const bundleAnalyzer = process.env.npm_config_argv?.includes(
"build:bundle-analyzer"
);
const path = require("path");
const webpack = require("webpack");
/**
* @type {import("next").NextConfig}
* */
const nextConfig = {
compiler: {
reactRemoveProperties: isProduction,
removeConsole: isProduction,
styledComponents: {
displayName: false,
fileName: false,
minify: isProduction,
pure: true,
ssr: true,
transpileTemplateLiterals: true,
},
},
devIndicators: false,
headers: async () => [
{
source: "/:path*",
headers: [
{
key: "Cross-Origin-Opener-Policy",
value: "same-origin",
},
{
key: "Cross-Origin-Embedder-Policy",
value: "credentialless",
},
],
},
],
output: "export",
productionBrowserSourceMaps: false,
reactProductionProfiling: false,
reactStrictMode: !isProduction,
webpack: (config) => {
config.plugins.push(
new webpack.NormalModuleReplacementPlugin(/node:/, (resource) => {
const mod = resource.request.replace(/^node:/, "");
switch (mod) {
case "buffer":
resource.request = "buffer";
break;
case "stream":
resource.request = "readable-stream";
break;
default:
throw new Error(`Not found ${mod}`);
}
}),
new webpack.DefinePlugin({
__REACT_DEVTOOLS_GLOBAL_HOOK__: "({ isDisabled: true })",
})
);
config.resolve.alias = config.resolve.alias || {};
config.resolve.alias["MediaInfoModule.wasm"] = path.resolve(
__dirname,
"node_modules/mediainfo.js/dist/MediaInfoModule.wasm"
);
config.resolve.fallback = config.resolve.fallback || {};
config.resolve.fallback.module = false;
config.resolve.fallback.perf_hooks = false;
config.module.parser.javascript = config.module.parser.javascript || {};
config.module.parser.javascript.dynamicImportFetchPriority = "high";
return config;
},
};
module.exports = bundleAnalyzer
? require("@next/bundle-analyzer")({
enabled: isProduction,
})(nextConfig)
: nextConfig;