Skip to content

Commit

Permalink
[fix] util polyfill to make compiler self-contained
Browse files Browse the repository at this point in the history
this is needed for running the Svelte compiler in the browser
Fixes sveltejs#8010
  • Loading branch information
dummdidumm committed Nov 10, 2022
1 parent b2d3607 commit 0858cda
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 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.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -148,6 +148,7 @@
"periscopic": "^3.0.4",
"puppeteer": "^2.0.0",
"rollup": "^1.27.14",
"util": "^0.12.5",
"source-map": "^0.7.4",
"source-map-support": "^0.5.21",
"sourcemap-codec": "^1.4.8",
Expand Down
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 0858cda

Please sign in to comment.