const withBundleAnalyzer = require('@next/bundle-analyzer')({ enabled: process.env.ANALYZE === 'true', }); const path = require('path'); const { remarkPlugins } = require('./lib/remark-plugins'); module.exports = withBundleAnalyzer({ experimental: { modern: true, polyfillsOptimization: true, jsconfigPaths: true, }, pageExtensions: ['js', 'ts', 'tsx', 'md', 'mdx'], webpack: (config, options) => { config.module.rules.push({ test: /.mdx?$/, // load both .md and .mdx files use: [ options.defaultLoaders.babel, { loader: '@mdx-js/loader', options: { remarkPlugins, }, }, path.join(__dirname, './lib/md-loader'), ], }); if (!options.dev) { const splitChunks = config.optimization && config.optimization.splitChunks; if (splitChunks) { const cacheGroups = splitChunks.cacheGroups; const test = /[\\/]node_modules[\\/](preact|preact-render-to-string|preact-context-provider)[\\/]/; if (cacheGroups.framework) { cacheGroups.preact = Object.assign({}, cacheGroups.framework, { test, }); cacheGroups.commons.name = 'framework'; } else { cacheGroups.preact = { name: 'commons', chunks: 'all', test, }; } } // Install webpack aliases: const aliases = config.resolve.alias || (config.resolve.alias = {}); aliases.react = aliases['react-dom'] = 'preact/compat'; aliases['react-ssr-prepass'] = 'preact-ssr-prepass'; } return config; }, });