Skip to content

Commit 20378ca

Browse files
authored
fix: Tell webpack about dynamic import + fixed polyfills (#1151)
fix: tell webpack about dynamic import + fixed polyfills
1 parent a535262 commit 20378ca

File tree

6 files changed

+74
-12
lines changed

6 files changed

+74
-12
lines changed

packages/sdk-install-modal-web/stencil.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const config: Config = {
1111
},
1212
],
1313
enableCache: true,
14-
buildEs5: true,
14+
buildEs5: false,
1515
// Add hash for file names for better caching
1616
hashFileNames: true,
1717
excludeUnusedDependencies: true,

packages/sdk-react/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
"rollup-plugin-dts": "^4.2.2",
9999
"rollup-plugin-jscc": "^2.0.0",
100100
"rollup-plugin-peer-deps-external": "^2.2.4",
101+
"rollup-plugin-polyfill-node": "^0.13.0",
101102
"rollup-plugin-postcss": "^4.0.2",
102103
"rollup-plugin-terser": "^7.0.2",
103104
"rollup-plugin-typescript2": "^0.36.0",

packages/sdk-react/rollup.config.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { nodeResolve } from '@rollup/plugin-node-resolve';
44
import typescript from '@rollup/plugin-typescript';
55
import external from 'rollup-plugin-peer-deps-external';
66
import { terser } from 'rollup-plugin-terser';
7+
import globals from 'rollup-plugin-polyfill-node';
78

89
const packageJson = require('./package.json');
910

@@ -35,8 +36,16 @@ const config = [
3536
browser: true,
3637
}),
3738
commonjs(),
39+
globals({
40+
include: null,
41+
}),
3842
json(),
39-
terser(),
43+
terser({
44+
format: {
45+
// keep all /* webpack*: * */ comments and /* vite-*: * */ comments
46+
comments: (_, comment) => comment.value.includes("webpack") || comment.value.includes("vite")
47+
}
48+
}),
4049
],
4150
},
4251
{
@@ -60,8 +69,16 @@ const config = [
6069
preferBuiltins: true,
6170
}),
6271
commonjs(),
72+
globals({
73+
include: null,
74+
}),
6375
json(),
64-
terser(),
76+
terser({
77+
format: {
78+
// keep all /* webpack*: * */ comments and /* vite-*: * */ comments
79+
comments: (_, comment) => comment.value.includes("webpack") || comment.value.includes("vite")
80+
}
81+
}),
6582
],
6683
}
6784
];

packages/sdk/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@
131131
"rollup-plugin-jscc": "^2.0.0",
132132
"rollup-plugin-natives": "^0.7.5",
133133
"rollup-plugin-node-builtins": "^2.1.2",
134-
"rollup-plugin-node-globals": "^1.4.0",
135134
"rollup-plugin-polyfill-node": "^0.13.0",
136135
"rollup-plugin-sizes": "^1.0.6",
137136
"rollup-plugin-typescript2": "^0.31.2",

packages/sdk/rollup.config.js

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import terser from '@rollup/plugin-terser';
88
import builtins from 'rollup-plugin-node-builtins';
99
import { visualizer } from 'rollup-plugin-visualizer';
1010
import replace from '@rollup/plugin-replace';
11-
import globals from 'rollup-plugin-node-globals';
11+
import globals from 'rollup-plugin-polyfill-node';
1212

1313
const packageJson = require('./package.json');
1414
const 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
3434
const 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+
/import\(/g,
46+
'import(/* webpackIgnore: true */'
47+
);
48+
}
49+
}
50+
},
51+
};
52+
};
53+
3654
// Dependencies that should always be external
3755
const baseExternalDeps = [
3856
...peerDependencies.filter(excludeBundledDeps),
@@ -165,16 +183,25 @@ const configs = [
165183
transformMixedEsModules: true,
166184
include: /node_modules/,
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: /node_modules/ }),
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
},

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11269,6 +11269,7 @@ __metadata:
1126911269
rollup-plugin-node-builtins: ^2.1.2
1127011270
rollup-plugin-node-globals: ^1.4.0
1127111271
rollup-plugin-peer-deps-external: ^2.2.4
11272+
rollup-plugin-polyfill-node: ^0.13.0
1127211273
rollup-plugin-postcss: ^4.0.2
1127311274
rollup-plugin-terser: ^7.0.2
1127411275
rollup-plugin-typescript2: ^0.36.0
@@ -11606,7 +11607,6 @@ __metadata:
1160611607
rollup-plugin-jscc: ^2.0.0
1160711608
rollup-plugin-natives: ^0.7.5
1160811609
rollup-plugin-node-builtins: ^2.1.2
11609-
rollup-plugin-node-globals: ^1.4.0
1161011610
rollup-plugin-polyfill-node: ^0.13.0
1161111611
rollup-plugin-sizes: ^1.0.6
1161211612
rollup-plugin-typescript2: ^0.31.2

0 commit comments

Comments
 (0)