Enhance CDN packages and playground
Amp-Thread-ID: https://ampcode.com/threads/T-01a02485-5574-707c-bff4-5668d83bee8a Co-authored-by: Heaust Azure <heaust.azure@gmail.com>
This commit is contained in:
+19
-7
@@ -4,7 +4,8 @@ import process from "node:process";
|
||||
import { build } from "esbuild";
|
||||
|
||||
const [root, output] = process.argv.slice(2);
|
||||
if (!root || !output) throw new Error("usage: node build.mjs <repository> <output>");
|
||||
if (!root || !output)
|
||||
throw new Error("usage: node build.mjs <repository> <output>");
|
||||
|
||||
const browser = {
|
||||
bundle: true,
|
||||
@@ -17,8 +18,14 @@ const browser = {
|
||||
|
||||
const workerFiles = new Map([
|
||||
[path.join(root, "core", "index.js"), "./worker.js"],
|
||||
[path.join(root, "addons", "handles", "src", "importers", "gltf.ts"), "./importer-worker.js"],
|
||||
[path.join(root, "addons", "handles", "src", "bvh", "picking.ts"), "./bvh-worker.js"],
|
||||
[
|
||||
path.join(root, "addons", "handles", "src", "importers", "gltf.ts"),
|
||||
"./importer-worker.js",
|
||||
],
|
||||
[
|
||||
path.join(root, "addons", "handles", "src", "bvh", "picking.ts"),
|
||||
"./bvh-worker.js",
|
||||
],
|
||||
]);
|
||||
|
||||
const workerURLs = {
|
||||
@@ -32,7 +39,8 @@ const workerURLs = {
|
||||
/new Worker\(new URL\("\.\/worker\.(?:js|ts)", import\.meta\.url\),/,
|
||||
`createYawnWorker(new URL(${JSON.stringify(worker)}, import.meta.url),`,
|
||||
);
|
||||
if (transformed === contents) throw new Error(`worker constructor not found in ${source}`);
|
||||
if (transformed === contents)
|
||||
throw new Error(`worker constructor not found in ${source}`);
|
||||
contents = `
|
||||
function createYawnWorker(url, options) {
|
||||
if (url.origin === globalThis.location.origin) return new Worker(url, options);
|
||||
@@ -57,8 +65,8 @@ await Promise.all([
|
||||
}),
|
||||
build({
|
||||
...browser,
|
||||
alias: { "@yawn/core": path.join(root, "core", "index.js") },
|
||||
entryPoints: [path.join(root, "addons", "handles", "src", "index.ts")],
|
||||
external: ["@yawn/core"],
|
||||
outfile: path.join(output, "handles.js"),
|
||||
plugins: [workerURLs],
|
||||
}),
|
||||
@@ -73,12 +81,16 @@ await Promise.all([
|
||||
}),
|
||||
build({
|
||||
...browser,
|
||||
entryPoints: [path.join(root, "addons", "handles", "src", "importers", "worker.ts")],
|
||||
entryPoints: [
|
||||
path.join(root, "addons", "handles", "src", "importers", "worker.ts"),
|
||||
],
|
||||
outfile: path.join(output, "importer-worker.js"),
|
||||
}),
|
||||
build({
|
||||
...browser,
|
||||
entryPoints: [path.join(root, "addons", "handles", "src", "bvh", "worker.ts")],
|
||||
entryPoints: [
|
||||
path.join(root, "addons", "handles", "src", "bvh", "worker.ts"),
|
||||
],
|
||||
outfile: path.join(output, "bvh-worker.js"),
|
||||
}),
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user