@@ -8,7 +8,7 @@ import terser from '@rollup/plugin-terser';
88import builtins from 'rollup-plugin-node-builtins' ;
99import { visualizer } from 'rollup-plugin-visualizer' ;
1010import replace from '@rollup/plugin-replace' ;
11- import globals from 'rollup-plugin-node-globals ' ;
11+ import globals from 'rollup-plugin-polyfill-node ' ;
1212
1313const packageJson = require ( './package.json' ) ;
1414const isDev = process . env . NODE_ENV === 'dev' ;
@@ -33,6 +33,24 @@ const sharedDeps = ['eventemitter2', 'socket.io-client', 'debug', 'uuid', 'cross
3333// Filter function to exclude bundled dependencies
3434const excludeBundledDeps = ( dep ) => ! bundledDeps . includes ( dep ) ;
3535
36+ // Used to inject "/* webpackIgnore: true */" for sdk-install-modal-web dynamic import
37+ const injectWebpackIgnore = ( ) => {
38+ return {
39+ name : 'inject-webpack-ignore' ,
40+ generateBundle ( _ , bundle ) {
41+ for ( const file of Object . keys ( bundle ) ) {
42+ if ( file === 'metamask-sdk.js' && bundle [ file ] . code ) {
43+ // Inject the webpackIgnore comment into dynamic import
44+ bundle [ file ] . code = bundle [ file ] . code . replace (
45+ / i m p o r t \( / g,
46+ 'import(/* webpackIgnore: true */'
47+ ) ;
48+ }
49+ }
50+ } ,
51+ } ;
52+ } ;
53+
3654// Dependencies that should always be external
3755const baseExternalDeps = [
3856 ...peerDependencies . filter ( excludeBundledDeps ) ,
@@ -165,16 +183,25 @@ const configs = [
165183 transformMixedEsModules : true ,
166184 include : / n o d e _ m o d u l e s / ,
167185 } ) ,
168- globals ( ) ,
186+ globals ( {
187+ include : null ,
188+ } ) ,
169189 builtins ( {
170190 crypto : true ,
171191 stream : true ,
172192 http : true ,
173193 https : true ,
174194 url : true ,
195+ process : true ,
175196 buffer : false ,
176197 } ) ,
177- terser ( ) ,
198+ terser ( {
199+ format : {
200+ // keep all /* webpack*: * */ comments and /* vite-*: * */ comments
201+ comments : ( _ , comment ) => comment . value . includes ( "webpack" ) || comment . value . includes ( "vite" )
202+ }
203+ } ) ,
204+ injectWebpackIgnore ( ) ,
178205 ] ,
179206 onwarn : sharedWarningHandler ,
180207 } ,
@@ -234,9 +261,17 @@ const configs = [
234261 dedupe : sharedDeps ,
235262 } ) ,
236263 commonjs ( { transformMixedEsModules : true , include : / n o d e _ m o d u l e s / } ) ,
237- globals ( ) ,
264+ globals ( {
265+ include : null ,
266+ } ) ,
238267 builtins ( { crypto : true } ) ,
239- terser ( ) ,
268+ terser ( {
269+ format : {
270+ // keep all /* webpack*: * */ comments and /* vite-*: * */ comments
271+ comments : ( _ , comment ) => comment . value . includes ( "webpack" ) || comment . value . includes ( "vite" )
272+ }
273+ } ) ,
274+ injectWebpackIgnore ( ) ,
240275 ] ,
241276 onwarn : sharedWarningHandler ,
242277 } ,
@@ -263,7 +298,12 @@ const configs = [
263298 browser : true ,
264299 preferBuiltins : true ,
265300 } ) ,
266- terser ( ) ,
301+ terser ( {
302+ format : {
303+ // keep all /* webpack*: * */ comments and /* vite-*: * */ comments
304+ comments : ( _ , comment ) => comment . value . includes ( "webpack" ) || comment . value . includes ( "vite" )
305+ }
306+ } ) ,
267307 ] ,
268308 onwarn : sharedWarningHandler ,
269309 } ,
@@ -306,7 +346,12 @@ const configs = [
306346 exportConditions : [ 'node' ] ,
307347 } ) ,
308348 commonjs ( { transformMixedEsModules : true } ) ,
309- terser ( ) ,
349+ terser ( {
350+ format : {
351+ // keep all /* webpack*: * */ comments and /* vite-*: * */ comments
352+ comments : ( _ , comment ) => comment . value . includes ( "webpack" ) || comment . value . includes ( "vite" )
353+ }
354+ } ) ,
310355 ] ,
311356 onwarn : sharedWarningHandler ,
312357 } ,
0 commit comments