next.config.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. const fs = require('fs');
  2. const path = require('path');
  3. const CopyPlugin = require("copy-webpack-plugin");
  4. const withPWA = require('@ducanh2912/next-pwa').default({
  5. dest: 'public',
  6. });
  7. /** @type {import('next').NextConfig} */
  8. const nextConfig = {
  9. reactStrictMode: false,
  10. eslint: {
  11. ignoreDuringBuilds: true,
  12. },
  13. typescript: {
  14. ignoreBuildErrors: true,
  15. },
  16. images: {
  17. unoptimized: true,
  18. },
  19. experimental: {
  20. webpackBuildWorker: true,
  21. },
  22. webpack: (config, { webpack, buildId }) => {
  23. // See https://webpack.js.org/configuration/resolve/#resolvealias
  24. config.resolve.alias = {
  25. ...config.resolve.alias,
  26. "sharp$": false,
  27. "onnxruntime-node$": false,
  28. }
  29. config.plugins.push(
  30. new CopyPlugin({
  31. patterns: [
  32. {
  33. from: "./node_modules/onnxruntime-web/dist/ort-wasm-simd-threaded.wasm",
  34. to: "static/chunks/[name][ext]",
  35. },
  36. {
  37. from: "./node_modules/onnxruntime-web/dist/ort-wasm-threaded.wasm",
  38. to: "static/chunks/[name][ext]",
  39. },
  40. {
  41. from: "./node_modules/onnxruntime-web/dist/ort-wasm.wasm",
  42. to: "static/chunks/[name][ext]",
  43. },
  44. {
  45. from: "./node_modules/onnxruntime-web/dist/ort-wasm-simd.wasm",
  46. to: "static/chunks/[name][ext]",
  47. },
  48. {
  49. from: "node_modules/@ricky0123/vad-web/dist/vad.worklet.bundle.min.js",
  50. to: "static/chunks/[name][ext]",
  51. },
  52. {
  53. from: "node_modules/@ricky0123/vad-web/dist/*.onnx",
  54. to: "static/chunks/[name][ext]",
  55. },
  56. ],
  57. })
  58. );
  59. config.plugins.push(
  60. new webpack.DefinePlugin({
  61. 'process.env.NEXT_PUBLIC_CONFIG_BUILD_ID': JSON.stringify(buildId)
  62. })
  63. );
  64. return config;
  65. },
  66. };
  67. // Try to require user config if it exists
  68. let userConfig;
  69. const userConfigPath = path.resolve(__dirname, './v0-user-next.config.js');
  70. if (fs.existsSync(userConfigPath)) {
  71. try {
  72. userConfig = require(userConfigPath);
  73. } catch (e) {
  74. console.warn('Failed to load v0-user-next.config.js:', e.message);
  75. }
  76. }
  77. mergeConfig(nextConfig, userConfig);
  78. function mergeConfig(nextConfig, userConfig) {
  79. if (!userConfig) return;
  80. for (const key in userConfig) {
  81. if (
  82. typeof nextConfig[key] === 'object' &&
  83. !Array.isArray(nextConfig[key])
  84. ) {
  85. nextConfig[key] = {
  86. ...nextConfig[key],
  87. ...userConfig[key],
  88. };
  89. } else {
  90. nextConfig[key] = userConfig[key];
  91. }
  92. }
  93. }
  94. module.exports = withPWA(nextConfig);