Set up build system to automatically download and copy ML/CV libraries
during npm run build, eliminating manual file management.
Changes to package.json:
- Add devDependencies:
* @techstark/opencv-js: OpenCV.js for edge detection
* @tensorflow-models/coco-ssd: ML model for panel detection
* @rollup/plugin-terser: Minification plugin (already used)
Changes to rollup.config.js:
- Add custom downloadTensorFlow plugin:
* Downloads TensorFlow UMD build from unpkg.com during build
* Saves to vendor/tfjs/tf.min.js (1.5MB)
* Only runs during build, not in watch mode
- Add copy plugins for ML/CV libraries:
* Copy OpenCV.js from node_modules to vendor/opencv/opencv.js
* Copy COCO-SSD from node_modules to vendor/coco-ssd/coco-ssd.min.js
This automated approach ensures:
1. All vendored libraries are updated when npm install is run
2. No manual file downloads or copy operations needed
3. Reproducible builds across different environments
4. Version tracking via package.json
Build workflow: npm install → npm run build → all ML/CV libraries ready
Update rollup config to copy OpenCV, TensorFlow.js, and COCO-SSD
libraries to vendor directory. These dependencies are used for the
panel detection feature and need to be bundled with the application
instead of loaded from npm packages at runtime.
- Add copyOpenCV() plugin to copy OpenCV.js from node_modules
- Add copyTensorFlow() plugin to copy TensorFlow.js from node_modules
- Add copyCocoSsd() plugin to copy COCO-SSD model from node_modules
- Apply formatting consistency (double quotes for imports)
Previously, zip.js and fflate were built from the main Foliate repo.
And PDF.js files were copied manually. Now they all build here.
Unfortunately, two CSS files still need to be copied manually.