Files
DefectingCat.github.io/next.config.js
DefectingCat 7b05f849cc update dependencies
update nextjs to 14
2023-11-07 11:01:14 +08:00

88 lines
2.1 KiB
JavaScript

/**
* @type {import('next').NextConfig}
*/
// const isExport = process.env.NEXT_BUILD === 'export';
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
});
const nextConfig = {
/* config options here */
reactStrictMode: true,
swcMinify: true,
output: 'standalone',
// images: isExport ? { unoptimized: true } : {},
experimental: {
webpackBuildWorker: true,
},
compiler: {
removeConsole: process.env.NODE_ENV === 'production',
},
pageExtensions: ['ts', 'tsx', 'js', 'jsx', 'md', 'mdx'],
webpack(config, { isServer }) {
if (!isServer) {
// We're in the browser build, so we can safely exclude the sharp module
config.externals.push('sharp');
}
// audio support
config.module.rules.push({
test: /\.(ogg|mp3|wav|mpe?g)$/i,
exclude: config.exclude,
use: [
{
loader: require.resolve('url-loader'),
options: {
limit: config.inlineImageLimit,
fallback: require.resolve('file-loader'),
publicPath: `${config.assetPrefix}/_next/static/images/`,
outputPath: `${isServer ? '../' : ''}static/images/`,
name: '[name]-[hash].[ext]',
esModule: config.esModule || false,
},
},
],
});
// shader support
config.module.rules.push({
test: /\.(glsl|vs|fs|vert|frag)$/,
exclude: /node_modules/,
use: ['raw-loader', 'glslify-loader'],
});
return config;
},
};
const KEYS_TO_OMIT = [
'webpackDevMiddleware',
'configOrigin',
'target',
'analyticsId',
'webpack5',
'amp',
'assetPrefix',
];
module.exports = (_phase, { defaultConfig }) => {
const plugins = [[withBundleAnalyzer, {}]];
const wConfig = plugins.reduce(
(acc, [plugin, config]) => plugin({ ...acc, ...config }),
{
...defaultConfig,
...nextConfig,
},
);
const finalConfig = {};
Object.keys(wConfig).forEach((key) => {
if (!KEYS_TO_OMIT.includes(key)) {
finalConfig[key] = wConfig[key];
}
});
return finalConfig;
};