Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

next.config.js 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. webpack: (config, { dev, isServer }) => {
  93. if (dev) {
  94. config.plugins.push(codeInspectorPlugin({ bundler: 'webpack' }))
  95. }
  96. return config
  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. },
  113. // fix all before production. Now it slow the develop speed.
  114. eslint: {
  115. // Warning: This allows production builds to successfully complete even if
  116. // your project has ESLint errors.
  117. ignoreDuringBuilds: true,
  118. dirs: ['app', 'bin', 'config', 'context', 'hooks', 'i18n', 'models', 'service', 'test', 'types', 'utils'],
  119. },
  120. typescript: {
  121. // https://nextjs.org/docs/api-reference/next.config.js/ignoring-typescript-errors
  122. ignoreBuildErrors: true,
  123. },
  124. reactStrictMode: true,
  125. async redirects() {
  126. return [
  127. {
  128. source: '/',
  129. destination: '/apps',
  130. permanent: false,
  131. },
  132. ]
  133. },
  134. output: 'standalone',
  135. }
  136. module.exports = withPWA(withBundleAnalyzer(withMDX(nextConfig)))