@@ -33,13 +33,27 @@ const nextConfig = withExpo({
3333 experimental : {
3434 forceSwcTransforms : true ,
3535 } ,
36- webpack : ( config ) => {
36+ webpack : ( config , { dev , isServer } ) => {
3737 config . resolve = {
3838 ...config . resolve ,
3939 symlinks : false , // tells webpack to follow the real path of symlinked module instead of the symlink path itself
40+ fallback : {
41+ ...config . resolve . fallback ,
42+ stream : require . resolve ( 'stream-browserify' ) ,
43+ crypto : require . resolve ( 'crypto-browserify' ) ,
44+ http : require . resolve ( 'stream-http' ) ,
45+ https : require . resolve ( 'https-browserify' ) ,
46+ os : require . resolve ( 'os-browserify/browser' ) ,
47+ path : require . resolve ( 'path-browserify' ) ,
48+ zlib : require . resolve ( 'browserify-zlib' ) ,
49+ } ,
4050 alias : {
4151 ...config . resolve . alias ,
4252 // Make sure the react version used is from our node_modules
53+ '@babel/runtime' : path . resolve (
54+ __dirname ,
55+ './node_modules/@babel/runtime' ,
56+ ) ,
4357 react : path . resolve ( __dirname , './node_modules/react' ) ,
4458 'react-native$' : require . resolve ( 'react-native-web' ) ,
4559 // 'expo-asset': path.resolve(__dirname, './node_modules/expo-asset'),
@@ -62,6 +76,36 @@ const nextConfig = withExpo({
6276 ) ,
6377 } ,
6478 } ;
79+
80+ // Disable caching for development
81+ config . cache = {
82+ type : 'filesystem' ,
83+ buildDependencies : {
84+ config : [ __filename ] ,
85+ } ,
86+ cacheDirectory : path . resolve ( __dirname , '.next/cache/webpack' ) ,
87+ // Only cache node_modules except for sdk-install-modal-web
88+ managedPaths : [
89+ // Include all node_modules except sdk-install-modal-web
90+ path . resolve ( __dirname , 'node_modules' ) ,
91+ ] ,
92+ // Exclude the sdk package from caching using version check
93+ version : `${
94+ require ( '@metamask/sdk-install-modal-web/package.json' ) . version
95+ } -${ Date . now ( ) } `,
96+ } ;
97+
98+ // Add watch options to detect changes
99+ config . watchOptions = {
100+ aggregateTimeout : 300 ,
101+ poll : 1000 ,
102+ ignored : [
103+ '**/.git/**' ,
104+ '**/node_modules/**' ,
105+ '!**/node_modules/@metamask/sdk-install-modal-web/**' ,
106+ ] ,
107+ } ;
108+
65109 config . module . rules . push (
66110 {
67111 test : / \. ( j s | j s x ) $ / ,
@@ -127,6 +171,41 @@ const nextConfig = withExpo({
127171 } ,
128172 ) ;
129173
174+ // Find the rule that handles JavaScript files
175+ const jsRule = config . module . rules . find (
176+ ( rule ) => rule . test && rule . test . test ( '.js' ) ,
177+ ) ;
178+
179+ if ( jsRule ) {
180+ // Include @babel /runtime in the Babel loader
181+ jsRule . include = [
182+ ...( Array . isArray ( jsRule . include )
183+ ? jsRule . include
184+ : [ jsRule . include ]
185+ ) . filter ( Boolean ) ,
186+ path . resolve ( __dirname , 'node_modules/@babel/runtime' ) ,
187+ ] ;
188+ }
189+
190+ // Add the babel-plugin-transform-import-meta to the loader options
191+ config . module . rules . forEach ( ( rule ) => {
192+ if ( rule . use ) {
193+ const use = Array . isArray ( rule . use ) ? rule . use : [ rule . use ] ;
194+ use . forEach ( ( loader ) => {
195+ if (
196+ typeof loader === 'object' &&
197+ loader . loader &&
198+ loader . loader . includes ( 'babel-loader' ) &&
199+ loader . options
200+ ) { loader . options . plugins = [
201+ ...( loader . options . plugins || [ ] ) ,
202+ 'babel-plugin-transform-import-meta' ,
203+ ] ;
204+ }
205+ } ) ;
206+ }
207+ } ) ;
208+
130209 // write config to disk for debugging
131210 fs . writeFileSync (
132211 './next.webpack.config.json' ,
0 commit comments