Skip to content

Commit

Permalink
[fix] util polyfill to make compiler self-contained (#8014)
Browse files Browse the repository at this point in the history
this is needed for running the Svelte compiler in the browser
Fixes #8010
  • Loading branch information
dummdidumm committed Nov 10, 2022
1 parent f4779ee commit e48fa4a
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
53 changes: 52 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -153,6 +153,7 @@
"sourcemap-codec": "^1.4.8",
"tiny-glob": "^0.2.9",
"tslib": "^2.4.1",
"typescript": "^3.7.5"
"typescript": "^3.7.5",
"util": "^0.12.5"
}
}
12 changes: 11 additions & 1 deletion rollup.config.js
Expand Up @@ -108,8 +108,18 @@ export default [
input: 'src/compiler/index.ts',
plugins: [
replace({
__VERSION__: pkg.version
__VERSION__: pkg.version,
'process.env.NODE_DEBUG': false // appears inside the util package
}),
{
resolveId(id) {
// util is a built-in module in Node.js, but we want a self-contained compiler bundle
// that also works in the browser, so we load its polyfill instead
if (id === 'util') {
return require.resolve('./node_modules/util'); // just 'utils' would resolve this to the built-in module
}
}
},
resolve(),
commonjs({
include: ['node_modules/**']
Expand Down

0 comments on commit e48fa4a

Please sign in to comment.