1
+ /** @type {import('next').NextConfig } */
2
+ const { PHASE_DEVELOPMENT_SERVER } = require ( 'next/constants' ) ;
1
3
const TsconfigPathsPlugin = require ( 'tsconfig-paths-webpack-plugin' ) ;
2
4
3
5
/**
4
- * Webpack config used by export and dev builds
6
+ * Webpack config used in all environments
5
7
* @param {* } config
6
8
* @param {* } param1
7
9
* @returns
@@ -24,95 +26,65 @@ const webpackConfig = (config, { isServer }) => {
24
26
if ( ! isServer ) {
25
27
config . output . environment = { ...config . output . environment , asyncFunction : true } ;
26
28
}
27
-
28
- // Add fallback and resolve configurations for browser compatibility
29
- config . resolve = {
30
- ...config . resolve ,
31
- extensions : [ '.ts' , '.tsx' , '.js' , '.mjs' ] ,
32
- fallback : {
33
- https : require . resolve ( 'https-browserify' ) ,
34
- http : require . resolve ( 'stream-http' ) ,
35
- 'get-port-please' : false ,
36
- net : false ,
37
- fs : false ,
38
- os : false ,
39
- path : false ,
40
- events : require . resolve ( 'events/' ) ,
41
- buffer : require . resolve ( 'buffer/' ) ,
42
- stream : require . resolve ( 'readable-stream' ) ,
43
- crypto : require . resolve ( 'crypto-browserify' ) ,
44
- constants : require . resolve ( 'constants-browserify' ) ,
45
- zlib : require . resolve ( 'browserify-zlib' ) ,
46
- dns : false ,
47
- tls : false ,
48
- process : false ,
49
- child_process : false ,
50
- } ,
51
- } ;
52
29
53
30
return config ;
54
31
} ;
55
32
56
- /**
57
- * Next.js config that produces a static page
58
- */
59
- const nextConfigExport = {
60
- output : 'export' ,
61
- webpack : webpackConfig ,
62
- experimental : {
63
- esmExternals : true , // Ensure modern module support
64
- } ,
65
-
66
- // https://github.com/Anastasia-Labs/lucid-evolution/issues/437
67
- serverExternalPackages : [
68
- "@lucid-evolution/lucid"
69
- ]
70
- }
71
-
72
- /** @type {import('next').NextConfig } */
73
- const nextConfigDev = {
74
- // output: 'export',
75
- serverExternalPackages : [
76
- "@lucid-evolution/lucid" ,
77
- ] ,
78
- async headers ( ) {
79
- return [
80
- {
81
- // matching all API routes
82
- source : "/api/v1/:path*" ,
83
- headers : [
84
- { key : "Access-Control-Allow-Credentials" , value : "true" } ,
85
- { key : "Access-Control-Allow-Origin" , value : "*" } ,
86
- { key : "Access-Control-Allow-Methods" , value : "GET,OPTIONS,PATCH,DELETE,POST,PUT" } ,
87
- { key : "Access-Control-Allow-Headers" , value : "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version" } ,
33
+ module . exports = ( phase , { defaultConfig} ) => {
34
+ if ( phase === PHASE_DEVELOPMENT_SERVER ) {
35
+ return {
36
+ /* NextJS development-only config options here */
37
+ serverExternalPackages : [
38
+ "@lucid-evolution/lucid" ,
39
+ ] ,
40
+ async headers ( ) {
41
+ return [
42
+ {
43
+ // matching all API routes
44
+ source : "/api/v1/:path*" ,
45
+ headers : [
46
+ { key : "Access-Control-Allow-Credentials" , value : "true" } ,
47
+ { key : "Access-Control-Allow-Origin" , value : "*" } ,
48
+ { key : "Access-Control-Allow-Methods" , value : "GET,OPTIONS,PATCH,DELETE,POST,PUT" } ,
49
+ { key : "Access-Control-Allow-Headers" , value : "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version" } ,
50
+ ]
51
+ }
88
52
]
89
- }
90
- ]
91
- } ,
92
- async rewrites ( ) {
93
- return [
94
- {
95
- source : '/api/v1/:path*' , // Match all routes starting with /api/v1/
96
- destination : 'http://localhost:8080/api/v1/:path*' , // Proxy to backend server
97
53
} ,
98
- ] ;
99
- } ,
100
- async redirects ( ) {
101
- return [
102
- {
103
- source : '/' ,
104
- destination : '/mint-authority' ,
105
- permanent : true , // Use true for a 301 redirect, false for 302
54
+ async rewrites ( ) {
55
+ return [
56
+ {
57
+ source : '/api/v1/:path*' , // Match all routes starting with /api/v1/
58
+ destination : 'http://localhost:8080/api/v1/:path*' , // Proxy to backend server
59
+ } ,
60
+ ] ;
106
61
} ,
107
- ] ;
108
- } ,
109
- experimental : {
110
- esmExternals : true , // Ensure modern module support
111
- } ,
112
- webpack : webpackConfig
113
- } ;
114
-
115
- const nextConfig = ( process . env . WST_BUILD === 'export' ) ? nextConfigExport : nextConfigDev ;
116
-
117
- module . exports = nextConfig ;
118
-
62
+ async redirects ( ) {
63
+ return [
64
+ {
65
+ source : '/' ,
66
+ destination : '/mint-authority' ,
67
+ permanent : true , // Use true for a 301 redirect, false for 302
68
+ } ,
69
+ ] ;
70
+ } ,
71
+ experimental : {
72
+ esmExternals : true , // Ensure modern module support
73
+ } ,
74
+ webpack : webpackConfig
75
+ }
76
+ }
77
+ // Default NextJS config for other phases (e.g., production, static export)
78
+ return {
79
+ output : 'export' ,
80
+ webpack : webpackConfig ,
81
+ experimental : {
82
+ esmExternals : true , // Ensure modern module support
83
+ } ,
84
+
85
+ // https://github.com/Anastasia-Labs/lucid-evolution/issues/437
86
+ serverExternalPackages : [
87
+ "@lucid-evolution/lucid"
88
+ ]
89
+ }
90
+ }
0 commit comments