Conversation
shellscape
left a comment
There was a problem hiding this comment.
Looks really good, thank you for stepping up to make this happen. I do have some suggestions for changes however.
|
Now that these initial changes are done: Do we need |
I don't see a need right now. Those options in the |
pnevares
left a comment
There was a problem hiding this comment.
One suggestion, but otherwise LGTM!
|
The import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import { wasm } from '@rollup/plugin-wasm';
export default {
input: 'src/main.js',
output: {
file: 'dist/bundle.js',
format: 'commonjs',
},
plugins: [
nodeResolve(),
commonjs(),
wasm({ maxFileSize: 0, publicPath: 'assets/' }),
],
}; |

Rollup Plugin Name:
WASMThis PR contains:
Are tests included?
Breaking Changes?
If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.
List any relevant issue numbers:
Discussed in #324.
Description
This PR adds support for not inlined WASM files. Currently WASM files are always base64 encoded, which increases size by > 30%. There's some discussion in #324. This PR addresses this issue by adding a
limitandpublicPathoption like in the URL plugin. E. g.would mean that no WASM files are inlined and all are copied to the destination folder and loaded via
fs(in Node) orfetch(in the browser) at runtime.Implementation
1.) Switching between
fsandfetchI decided to include code for both and decide at runtime what to execute. The other option would be having a plugin flag for the target platform. But I opted for this since I didn't see a downside besides the negligible code size impact.
One noteworthy detail: I loaded
fsviaeval('require("fs")')to avoid warnings like darionco/rollup-plugin-web-worker-loader#20. Of courseevalis typically bad but I don't see an issue here.2.) Path and name of the output WASM files
I handled file generation similarly to the URL plugin. The differences are:
emitFilesoption.fileNameoption, instead the output file name is always[hash].wasm.destDirandsourceDiroptions.Let me know if you think these are needed here as well. I didn't add them now because I wanted to make sure that my approach is valid in principle first.
Tests
I added one test which:
fixtures/complex.jsas CJS module.output/bundle.jswith its assertions.