Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove package.json from browser build #847

Closed
Balearica opened this issue Oct 29, 2023 · 2 comments · Fixed by #848
Closed

Remove package.json from browser build #847

Balearica opened this issue Oct 29, 2023 · 2 comments · Fixed by #848

Comments

@Balearica
Copy link
Collaborator

We dynamically import version numbers from package.json so that Tesseract.js always loads the appropriate version of worker.min.js and Tesseract.js-core. However, it looks like the entire contents of package.json are being embedded in both the browser versions of tesseract.min.js and worker.min.js by webpack (not just the version numbers). This probably inflates file sizes by a few kb for each file.

@Balearica
Copy link
Collaborator Author

It looks like this issues is caused by how Webpack is interacting with the prefer-destructuring rule required by our linter. Therefore, I am disabling this rule.

// The linter prefers this syntax..
const { version } = require('../../../package.json');

// ...and rejects this syntax
const version = require('../../../package.json').version;

However, the latter syntax produces better results. The latter implementation only embeds version in the final bundle, however the former implementation results in the entire package.json file being embedded in the final bundle.

@Balearica
Copy link
Collaborator Author

This change decreases the file size of both tesseract.min.js and worker.min.js by 2.7kb each for a total of 5.4kb saved.

Balearica added a commit that referenced this issue Oct 29, 2023
* Updated types to support all parameters per #831

* Updated require statements to reduce file size per #847
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant