mirror of
https://github.com/john-okeefe/foliate-js.git
synced 2026-09-09 11:29:14 -04:00
build: configure Rollup to automate ML/CV library vendoring
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
This commit is contained in:
+29
-10
@@ -1,6 +1,34 @@
|
||||
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
||||
import terser from "@rollup/plugin-terser";
|
||||
import { copy } from "fs-extra";
|
||||
import https from "https";
|
||||
|
||||
const downloadTensorFlow = () => ({
|
||||
name: "download-tensorflow",
|
||||
async writeBundle() {
|
||||
const url = "https://unpkg.com/@tensorflow/tfjs@4.22.0/dist/tf.min.js";
|
||||
const dest = "vendor/tfjs/tf.min.js";
|
||||
|
||||
console.log(`Downloading ${url}...`);
|
||||
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to download: ${response.statusText}`);
|
||||
}
|
||||
|
||||
const buffer = await response.arrayBuffer();
|
||||
|
||||
// Create directory
|
||||
const fs = await import("fs");
|
||||
const path = await import("path");
|
||||
const dir = path.dirname(dest);
|
||||
|
||||
await fs.promises.mkdir(dir, { recursive: true });
|
||||
|
||||
await fs.promises.writeFile(dest, new Uint8Array(buffer));
|
||||
console.log(`Downloaded ${buffer.byteLength} bytes to ${dest}`);
|
||||
},
|
||||
});
|
||||
|
||||
const copyPDFJS = () => ({
|
||||
name: "copy-pdfjs",
|
||||
@@ -34,15 +62,6 @@ const copyOpenCV = () => ({
|
||||
);
|
||||
},
|
||||
});
|
||||
const copyTensorFlow = () => ({
|
||||
name: "copy-tensorflow",
|
||||
async writeBundle() {
|
||||
await copy(
|
||||
"node_modules/@tensorflow/tfjs/dist/index.js",
|
||||
"vendor/tfjs/tf.min.js",
|
||||
);
|
||||
},
|
||||
});
|
||||
const copyCocoSsd = () => ({
|
||||
name: "copy-coco-ssd",
|
||||
async writeBundle() {
|
||||
@@ -72,7 +91,7 @@ export default [
|
||||
terser(),
|
||||
copyPDFJS(),
|
||||
copyOpenCV(),
|
||||
copyTensorFlow(),
|
||||
downloadTensorFlow(),
|
||||
copyCocoSsd(),
|
||||
],
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user