0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-06 14:50:20 -05:00
penpot/frontend/scripts/build-libs.js
Andrey Antukh 0cd446421d 🐛 Fix some issues with vendored libraries and build process
related to how package.json is defined and how modules
are exported
2024-11-05 14:18:51 +01:00

49 lines
1.3 KiB
JavaScript

import * as esbuild from "esbuild";
import { readFile } from "node:fs/promises";
const filter =
/react-virtualized[/\\]dist[/\\]es[/\\]WindowScroller[/\\]utils[/\\]onScroll\.js$/;
const fixReactVirtualized = {
name: "esbuild-plugin-react-virtualized",
setup({ onLoad }) {
onLoad({ filter }, async ({ path }) => {
const code = await readFile(path, "utf8");
const broken = `import { bpfrpt_proptype_WindowScroller } from "../WindowScroller.js";`;
return { contents: code.replace(broken, "") };
});
},
};
const rebuildNotify = {
name: "rebuild-notify",
setup(build) {
build.onEnd((result) => {
// console.log(result);
// [:main] Build completed. (1003 files, 1 compiled, 0 warnings, 9.06s)
console.log(
`[:libs] Build completed. (${result.errors.length} warnings, ${result.errors.length} errors)`,
);
});
},
};
const config = {
entryPoints: ["target/index.js"],
bundle: true,
format: "iife",
outfile: "resources/public/js/libs.js",
plugins: [fixReactVirtualized, rebuildNotify],
};
async function watch() {
let ctx = await esbuild.context(config);
return ctx.watch();
}
if (process.argv.includes("--watch")) {
await watch();
} else {
const localConfig = { ...config, minify: true };
await esbuild.build(localConfig);
}