next.config.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. const withLess = require('next-with-less');
  2. const withBundleAnalyzer = require('@next/bundle-analyzer')({
  3. enabled: process.env.ANALYZE === 'true',
  4. });
  5. const { PHASE_DEVELOPMENT_SERVER } = require('next/constants');
  6. const runtimeCaching = require('next-pwa/cache');
  7. const withPWA = require('next-pwa')({
  8. dest: 'public',
  9. runtimeCaching: [
  10. {
  11. urlPattern: /\.(?:ts|m3u8)$/i,
  12. handler: 'NetworkOnly',
  13. },
  14. {
  15. urlPattern: (url) => { return url.pathname.startsWith("/admin/"); },
  16. handler: 'NetworkOnly',
  17. options: {
  18. fetchOptions: { credentials: 'same-origin' }
  19. }
  20. },
  21. {
  22. urlPattern: (url) => { return url.pathname.startsWith("/api/"); },
  23. handler: 'NetworkOnly',
  24. },
  25. ...runtimeCaching,
  26. ],
  27. register: true,
  28. skipWaiting: true,
  29. disableDevLogs: true,
  30. publicExcludes: ['!img/platformlogos/**/*', '!styles/admin/**/*'],
  31. buildExcludes: [/chunks\/pages\/admin.*/, '!**/admin/**/*'],
  32. sourcemap: process.env.NODE_ENV === 'development',
  33. disable: process.env.NODE_ENV === 'development',
  34. });
  35. async function rewrites() {
  36. return [
  37. {
  38. source: '/api/:path*',
  39. destination: 'http://localhost:8080/api/:path*', // Proxy to Backend to work around CORS.
  40. },
  41. {
  42. source: '/hls/:path*',
  43. destination: 'http://localhost:8080/hls/:path*', // Proxy to Backend to work around CORS.
  44. },
  45. {
  46. source: '/img/:path*',
  47. destination: 'http://localhost:8080/img/:path*', // Proxy to Backend to work around CORS.
  48. },
  49. {
  50. source: '/logo',
  51. destination: 'http://localhost:8080/logo', // Proxy to Backend to work around CORS.
  52. },
  53. {
  54. source: '/thumbnail.jpg',
  55. destination: 'http://localhost:8080/thumbnail.jpg', // Proxy to Backend to work around CORS.
  56. },
  57. {
  58. source: '/customjavascript',
  59. destination: 'http://localhost:8080/customjavascript', // Proxy to Backend to work around CORS.
  60. },
  61. ];
  62. }
  63. module.exports = async phase => {
  64. /**
  65. * @type {import('next').NextConfig}
  66. */
  67. let nextConfig = withPWA(
  68. withBundleAnalyzer(
  69. withLess({
  70. productionBrowserSourceMaps: process.env.SOURCE_MAPS === 'true',
  71. trailingSlash: true,
  72. reactStrictMode: true,
  73. images: {
  74. unoptimized: true,
  75. },
  76. swcMinify: true,
  77. transpilePackages: [ "antd", "@ant-design", "rc-util", "rc-pagination", "rc-picker", "rc-notification", "rc-tooltip", "rc-tree", "rc-table" ],
  78. webpack(config) {
  79. config.module.rules.push({
  80. test: /\.svg$/i,
  81. issuer: /\.[jt]sx?$/,
  82. use: ['@svgr/webpack'],
  83. });
  84. return config;
  85. },
  86. pageExtensions: ['tsx'],
  87. }),
  88. ),
  89. );
  90. if (phase === PHASE_DEVELOPMENT_SERVER) {
  91. nextConfig = {
  92. ...nextConfig,
  93. rewrites,
  94. };
  95. } else {
  96. nextConfig = {
  97. ...nextConfig,
  98. output: 'export',
  99. };
  100. }
  101. return nextConfig;
  102. };