Treeshaking does not work when excluding components

Author: BafSCreated Dec 6, 2021Updated Oct 14, 2024
Labelshelp wantedbacklog

The documentation explains how to remove components (https://github.com/fingerprintjs/fingerprintjs/blob/master/docs/extending.md#extending-fingerprintjs) but unfortunately it doesn't seems to work well with treeshaking, the components stay in the compiled source.

It's possible to get the "sources" and whitelist components but the blobs are still not treeshaked. I tried with webpack 5.64 and rollup 2.42.

Example of what I had in mind:

javascript
import('@fingerprintjs/fingerprintjs').then(fp => {
  const sources = {
    audio: f.sources.audio, // I would expect to only have the audio component in the compiled source
  };
  const pp = fp.loadSources(fp.sources, {debug: true}, [])();

  pp.then(result => {
    console.log(result);
  });
}),

Another solution would be to be able to import every component individually (like import { audio } from '...'), threeshaking should work then.

Thanks in advance

Source: fingerprintjs/fingerprintjs