You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

next.config.js 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. const { codeInspectorPlugin } = require('code-inspector-plugin')
  2. const withPWA = require('next-pwa')({
  3. dest: 'public',
  4. register: true,
  5. skipWaiting: true,
  6. disable: process.env.NODE_ENV === 'development',
  7. fallbacks: {
  8. document: '/_offline.html',
  9. },
  10. runtimeCaching: [
  11. {
  12. urlPattern: /^https:\/\/fonts\.googleapis\.com\/.*/i,
  13. handler: 'CacheFirst',
  14. options: {
  15. cacheName: 'google-fonts',
  16. expiration: {
  17. maxEntries: 4,
  18. maxAgeSeconds: 365 * 24 * 60 * 60 // 1 year
  19. }
  20. }
  21. },
  22. {
  23. urlPattern: /^https:\/\/fonts\.gstatic\.com\/.*/i,
  24. handler: 'CacheFirst',
  25. options: {
  26. cacheName: 'google-fonts-webfonts',
  27. expiration: {
  28. maxEntries: 4,
  29. maxAgeSeconds: 365 * 24 * 60 * 60 // 1 year
  30. }
  31. }
  32. },
  33. {
  34. urlPattern: /\.(?:png|jpg|jpeg|svg|gif|webp|avif)$/i,
  35. handler: 'CacheFirst',
  36. options: {
  37. cacheName: 'images',
  38. expiration: {
  39. maxEntries: 64,
  40. maxAgeSeconds: 30 * 24 * 60 * 60 // 30 days
  41. }
  42. }
  43. },
  44. {
  45. urlPattern: /\.(?:js|css)$/i,
  46. handler: 'StaleWhileRevalidate',
  47. options: {
  48. cacheName: 'static-resources',
  49. expiration: {
  50. maxEntries: 32,
  51. maxAgeSeconds: 24 * 60 * 60 // 1 day
  52. }
  53. }
  54. },
  55. {
  56. urlPattern: /^\/api\/.*/i,
  57. handler: 'NetworkFirst',
  58. options: {
  59. cacheName: 'api-cache',
  60. networkTimeoutSeconds: 10,
  61. expiration: {
  62. maxEntries: 16,
  63. maxAgeSeconds: 60 * 60 // 1 hour
  64. }
  65. }
  66. }
  67. ]
  68. })
  69. const withMDX = require('@next/mdx')({
  70. extension: /\.mdx?$/,
  71. options: {
  72. // If you use remark-gfm, you'll need to use next.config.mjs
  73. // as the package is ESM only
  74. // https://github.com/remarkjs/remark-gfm#install
  75. remarkPlugins: [],
  76. rehypePlugins: [],
  77. // If you use `MDXProvider`, uncomment the following line.
  78. // providerImportSource: "@mdx-js/react",
  79. },
  80. })
  81. const withBundleAnalyzer = require('@next/bundle-analyzer')({
  82. enabled: process.env.ANALYZE === 'true',
  83. })
  84. // the default url to prevent parse url error when running jest
  85. const hasSetWebPrefix = process.env.NEXT_PUBLIC_WEB_PREFIX
  86. const port = process.env.PORT || 3000
  87. const locImageURLs = !hasSetWebPrefix ? [new URL(`http://localhost:${port}/**`), new URL(`http://127.0.0.1:${port}/**`)] : []
  88. const remoteImageURLs = [hasSetWebPrefix ? new URL(`${process.env.NEXT_PUBLIC_WEB_PREFIX}/**`) : '', ...locImageURLs].filter(item => !!item)
  89. /** @type {import('next').NextConfig} */
  90. const nextConfig = {
  91. basePath: process.env.NEXT_PUBLIC_BASE_PATH || '',
  92. transpilePackages: ['echarts', 'zrender'],
  93. turbopack: {
  94. rules: codeInspectorPlugin({
  95. bundler: 'turbopack'
  96. })
  97. },
  98. productionBrowserSourceMaps: false, // enable browser source map generation during the production build
  99. // Configure pageExtensions to include md and mdx
  100. pageExtensions: ['ts', 'tsx', 'js', 'jsx', 'md', 'mdx'],
  101. // https://nextjs.org/docs/messages/next-image-unconfigured-host
  102. images: {
  103. remotePatterns: remoteImageURLs.map(remoteImageURL => ({
  104. protocol: remoteImageURL.protocol.replace(':', ''),
  105. hostname: remoteImageURL.hostname,
  106. port: remoteImageURL.port,
  107. pathname: remoteImageURL.pathname,
  108. search: '',
  109. })),
  110. },
  111. experimental: {
  112. optimizePackageImports: [
  113. '@remixicon/react',
  114. '@heroicons/react'
  115. ],
  116. },
  117. // fix all before production. Now it slow the develop speed.
  118. eslint: {
  119. // Warning: This allows production builds to successfully complete even if
  120. // your project has ESLint errors.
  121. ignoreDuringBuilds: true,
  122. dirs: ['app', 'bin', 'config', 'context', 'hooks', 'i18n', 'models', 'service', 'test', 'types', 'utils'],
  123. },
  124. typescript: {
  125. // https://nextjs.org/docs/api-reference/next.config.js/ignoring-typescript-errors
  126. ignoreBuildErrors: true,
  127. },
  128. reactStrictMode: true,
  129. async redirects() {
  130. return [
  131. {
  132. source: '/',
  133. destination: '/apps',
  134. permanent: false,
  135. },
  136. ]
  137. },
  138. output: 'standalone',
  139. }
  140. module.exports = withPWA(withBundleAnalyzer(withMDX(nextConfig)))