Can't tree shaking in Vite
Closed this issue · 14 comments
magick-wasm version
0.0.19
Description
when I comment this code, tree shaking can works.
Steps to Reproduce
1、create a vite(vue2) project
2、npm install
3、add below code
import { Gravity } from "@imagemagick/magick-wasm"
console.log(Gravity);
4、npm run build
5、view the bundle size
19772.80 KiB / gzip: 6829.42 KiB
Images
No response
I don't think you can. The native library that uses ImageMagick has a lot of features and that increases the size of the bundle and I don't think you can tree shake that wasm code.
@dlemstra or can you split the code to several files? and I want know the original wasm file size.
The orginal wasm size is around 19mb at this point in time. The source code is already split in multiple files but I think the bundler combines it.
@dlemstra why the size of WASM-ImageMagick is just around 6mb?
I suspect that has to do with this library supporting the following delegates: freetype heic jng jp2 jpeg jxl lcms lqr openexr png raw tiff webp xml zlib
and that library only supporting a subset of those delegates.
You could reduce the binary size by removing some dependencies. But that will require you to modify the Magick.Native build and also make a custom build of magick-wasm.
@dlemstra I tried to exec build.cmd at https://github.com/dlemstra/Magick.Native/tree/main/build/wasm-x86, it generate a docker image, and then I dont known how to go on.
You can find the wasm files in the output directory.
@dlemstra but my output directory is empty, the output directory is at https://github.com/dlemstra/Magick.Native/tree/main/build/wasm-x86/output? or in docker?
I don't know what you have done but the output should be created in that folder. There might be something broken in your build but I cannot assist you with that. Going to close this issue now.
t
ok, thank you.