wasm-pack icon indicating copy to clipboard operation
wasm-pack copied to clipboard

How do I generate only the .wasm file and nothing else?

Open Directory opened this issue 4 years ago • 2 comments

I am trying to incorporate this within webpack. I do not want to use any of the baby step cripple autogenerated js files because those are unnecasary http requests that need to be loaded into the browser. i am using the webpack WasmPackPlugin library. my plugin setting is as follows.

new WasmPackPlugin({
  crateDirectory: './src/rust_lib',
  outDir: path.resolve(__dirname, 'dist'),
  extraArgs: "--no-typescript --target web",
})

i have my hello world rust code inside of src/rust_lib. i want it to compile the .wasm file in dist. ONLY the .wasm file. right now in its current state it trys to make a package and generates a .gitignore, index.js, and package.json. i do not want an npm package. i will be loading the index_bg.wasm file directly from my main js. theres no need for a pointless http req made to get index.js only to load the wasm. i know i could ignore the file and load it directly anyway but the contents of dist are exposed in production and its important only whats needed is present. I also just want to have a clean setup with no clutter.

What i have tried so far is scowering the docs for args to do this. i got rid of the ts files with --no-typescript and tried setting all kinds of different targets but it still tries to generate a package. How do i make it only generate the stand alone .wasm binary?

Directory avatar Aug 01 '21 07:08 Directory

Related: https://github.com/rustwasm/wasm-pack/issues/865, https://github.com/rustwasm/wasm-pack/issues/811

antonok-edm avatar Oct 22 '21 22:10 antonok-edm

This is impossible. You need the JS glue code to load the wasm file properly

ranile avatar May 30 '23 15:05 ranile