Can't access draco loader files when working with "Vite"

Hello everyone,
I’ve recently gotten familiar with DRACOloader. The problem is the way I have to address the DecoderPath.
I am using Vite + Three.js for my project. This is how I have to access the decoder’s path:

dracoLoader.setDecoderPath('node_modules/three/examples/js/libs/draco/gltf/')

This works in dev server and it seems a bit wrong to me since it directly gains access to somewhere in node_modules.

Beside this problem, since there is no exact modules imported, Vite can’t read it and when asking it to build, it doesn’t export the codes for the decoder.

The only solution I have come up with, is to copy the decoder files and paste them next to my project’s scripts and configure Vite to export them for build. This also seems like a wrong thing because I have to copy files from somewhere in node_modules and add them to my project scripts.

Thank you for your help in advance.

Given how the Draco decoder files are compiled and distributed, I think it’s likely that copy/pasting the files is the right way to include them here. You can get the official version from github.com/google/draco if you prefer – three.js includes copies of those.

1 Like

Thank you for your answer.
Since those files have large amount of code and I’m gonna have to commit them to the git repo we’re working on, do you think it’s ok? Wouldn’t that bring any problems to the development process in the future?

The Draco decoder files are not large enough to cause development issues within Git; including them as static resources in your repository is OK.

1 Like

node_modules does not exist in production. the job of a bundler is to pull out all the parts that your app relies on and then form a bundle. put the decoder into the /public folder and refer to it as /draco/gltf. you can also use the cdn https://www.gstatic.com/draco/versioned/decoders/1.4.3/

2 Likes