Skip to content

Commit e48fa4a

Browse files
authored
[fix] util polyfill to make compiler self-contained (sveltejs#8014)
this is needed for running the Svelte compiler in the browser Fixes sveltejs#8010
1 parent f4779ee commit e48fa4a

File tree

3 files changed

+65
-3
lines changed

3 files changed

+65
-3
lines changed

package-lock.json

Lines changed: 52 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
"sourcemap-codec": "^1.4.8",
154154
"tiny-glob": "^0.2.9",
155155
"tslib": "^2.4.1",
156-
"typescript": "^3.7.5"
156+
"typescript": "^3.7.5",
157+
"util": "^0.12.5"
157158
}
158159
}

rollup.config.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,18 @@ export default [
108108
input: 'src/compiler/index.ts',
109109
plugins: [
110110
replace({
111-
__VERSION__: pkg.version
111+
__VERSION__: pkg.version,
112+
'process.env.NODE_DEBUG': false // appears inside the util package
112113
}),
114+
{
115+
resolveId(id) {
116+
// util is a built-in module in Node.js, but we want a self-contained compiler bundle
117+
// that also works in the browser, so we load its polyfill instead
118+
if (id === 'util') {
119+
return require.resolve('./node_modules/util'); // just 'utils' would resolve this to the built-in module
120+
}
121+
}
122+
},
113123
resolve(),
114124
commonjs({
115125
include: ['node_modules/**']

0 commit comments

Comments
 (0)