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
Move OpenCV, TensorFlow.js, and COCO-SSD from optionalDependencies
to devDependencies. These libraries are now bundled into the vendor
directory during build instead of being optional runtime dependencies.
Also upgrade @rollup/plugin-terser from 0.4.4 to 1.0.0 which
requires Node.js 20+ and includes updated dependencies.
Related changes:
- Move @techstark/opencv-js to devDependencies
- Move @tensorflow/tfjs to devDependencies
- Move @tensorflow-models/coco-ssd to devDependencies
- Update @rollup/plugin-terser to 1.0.0
Fix npm install errors and make ML/CV libraries truly optional.
Changes:
- Move dependencies from "dependencies" to "optionalDependencies"
- Fix @techstark/opencv-js version from "^4.12.0" to "4.12.0-release.1"
- The caret syntax (^) doesn't work with suffix versions like -release.1
- Use exact version match instead
Why optionalDependencies:
- Installation won't fail if these packages fail to install
- Users can opt-out with: npm install foliate-js --omit=optional
- Maintains the library's "no hard dependencies" philosophy
- Graceful degradation: panel detection falls back to grid-only mode
Behavior:
- Default: npm attempts to install OpenCV, TensorFlow, COCO-SSD (~4.5MB)
- With --omit=optional: skips heavy ML/CV libraries
- Either way: library works, panel detection gracefully adapts
This resolves npm install errors where "^4.12.0" couldn't be found
because the actual version is "4.12.0-release.1".
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.