next.config.mjs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import withMDX from '@next/mdx';
  2. import env from './env.js';
  3. /** @type {import('next').NextConfig} */
  4. export default withMDX()({
  5. output: 'export',
  6. images: {
  7. unoptimized: true,
  8. },
  9. env: env,
  10. pageExtensions: ['js', 'jsx', 'mdx', 'ts', 'tsx'],
  11. webpack(config) {
  12. // Grab the existing rule that handles SVG imports
  13. const fileLoaderRule = config.module.rules.find((rule) =>
  14. rule.test?.test?.('.svg'),
  15. );
  16. config.module.rules.push(
  17. // Reapply the existing rule, but only for svg imports ending in ?url
  18. {
  19. ...fileLoaderRule,
  20. test: /\.svg$/i,
  21. resourceQuery: /url/, // *.svg?url
  22. },
  23. // Convert all other *.svg imports to React components
  24. {
  25. test: /\.svg$/i,
  26. issuer: fileLoaderRule.issuer,
  27. resourceQuery: { not: [...fileLoaderRule.resourceQuery.not, /url/] }, // exclude if *.svg?url
  28. use: [
  29. {
  30. loader: '@svgr/webpack',
  31. options: {
  32. svgoConfig: {
  33. plugins: [{ name: 'preset-default' }],
  34. },
  35. },
  36. },
  37. ],
  38. },
  39. );
  40. // Modify the file loader rule to ignore *.svg, since we have it handled now.
  41. fileLoaderRule.exclude = /\.svg$/i;
  42. return config;
  43. },
  44. });