Skip to content

Commit

Permalink
Improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaslihotzki committed Jan 31, 2023
1 parent e2f942c commit 66f7b71
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions guide/src/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,18 @@ Don't add WebAssembly fallback imports in generated JavaScript.

### `--split-linked-modules`

Controls whether wasm-bindgen will split linked modules out into their own files.
Enabling this is recommended, because it allows lazy loading and setting a
stricter Content Security Policy.

wasm-bindgen uses the `new URL('…', import.meta.url)` syntax to link such split
out files. This is directly supported when using webpack 5 or no bundler at all.

For other bundlers, ensure they support the link syntax, possibly by enabling an
extra plugin. That's why this option is disabled by default. Alternatively,
configure the bundler to keep the link syntax as is and to copy all files in
`snippets/` to the output directory preserving their paths.
Controls whether wasm-bindgen will split linked modules out into their own
files. Enabling this is recommended, because it allows lazy-loading the linked
modules and setting a stricter Content Security Policy.

wasm-bindgen uses the `new URL('…', import.meta.url)` syntax to resolve the
links to such split out files. This breaks with most bundlers, since the
bundler doesn't know to include the linked module in its output. That's why
this option is disabled by default. Webpack 5 is an exception, which has
special treatment for that syntax. For other bundlers, you'll need to take
extra steps to get it to work, likely by using a plugin.

Alternatively, you can leave the syntax as is and instead manually configure
the bundler to copy all files in `snippets/` to the output directory,
preserving their paths relative to whichever bundled file ends up containing
the JS shim.

0 comments on commit 66f7b71

Please sign in to comment.