@soleil-se/build-app
Version:
Script for building WebApps, RESTApps, Widgets and MCP Servers with Svelte in Sitevision.
33 lines (30 loc) • 804 B
JavaScript
export default function amdGlobals({ globals } = {}) {
const ignored = [];
function shouldLoad(id) {
return !ignored.includes(id);
}
return {
name: 'rollup-plugin-amd-globals',
resolveId(importee) {
if (!Object.keys(globals).includes(importee)) {
// Should be handled as usual.
return null;
}
// Most likely a global dependency.
// Do not ask other plugins or check the file system to find it.
if (!ignored.includes(importee)) {
ignored.push(importee);
}
return importee;
},
load(id) {
if (shouldLoad(id)) {
return null;
}
// The virtual source code for the provided global dependency.
return {
code: `export default window['${globals[id]}'];`,
};
},
};
}