27 lines
1 KiB
JavaScript
27 lines
1 KiB
JavaScript
// SPDX-FileCopyrightText: 2026 Milovann Yanatchkov
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
// cdn-to-bare.mjs — esbuild onResolve plugin.
|
|
// Rewrites three.js CDN URL imports to bare specifiers at bundle time, so the
|
|
// bimr-web bundle is resolved by the import map in index.html at runtime.
|
|
// Source keeps absolute CDN URLs (required by the standalone viewer repo).
|
|
|
|
const THREE_VERSION = "0.177.0";
|
|
const THREE_CDN = `https://cdn.jsdelivr.net/npm/three@${THREE_VERSION}`;
|
|
const THREE_CORE = `${THREE_CDN}/build/three.module.js`;
|
|
const THREE_ADDONS = `${THREE_CDN}/examples/jsm/`;
|
|
|
|
export const cdnToBare = {
|
|
name: "cdn-to-bare",
|
|
setup(build) {
|
|
build.onResolve({ filter: new RegExp(`^${THREE_CDN.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`) }, (args) => {
|
|
if (args.path === THREE_CORE) {
|
|
return { path: "three", external: true };
|
|
}
|
|
if (args.path.startsWith(THREE_ADDONS)) {
|
|
return { path: `three/addons/${args.path.slice(THREE_ADDONS.length)}`, external: true };
|
|
}
|
|
return { path: args.path, external: true };
|
|
});
|
|
},
|
|
};
|