onsite-toolkit: add resolver (#706)

Co-authored-by: panda <panda_dtdyy@outlook.com>
This commit is contained in:
undefinedandpanda authored and GitHub committed 2024-11-13 10:26:13 +08:00
1 parent d1e79f3a9c
commit f888537757
7 files changed
+510 -6

No files matched your search

+23 -4
View File
@@ -29,14 +29,33 @@ const tmp = tmpdir();
const federationPlugin: esbuild.Plugin = {
name: 'federation',
setup(b) {
const packages = {
react: 'React',
'react-dom': 'ReactDOM',
jquery: '$',
};
b.onResolve({ filter: /^@hydrooj\/ui-default/ }, () => ({
path: 'api',
namespace: 'ui-default',
}));
b.onLoad({ filter: /.*/, namespace: 'ui-default' }, () => ({
contents: 'module.exports = window.HydroExports;',
loader: 'tsx',
}));
for (const key in packages) {
b.onResolve({ filter: new RegExp(`^${key}($|\\/)`) }, () => ({
path: packages[key],
namespace: 'ui-default',
}));
}
b.onLoad({ filter: /.*/, namespace: 'ui-default' }, (args) => {
if (args.path === 'api') {
return {
contents: 'module.exports = window.HydroExports;',
loader: 'tsx',
};
}
return {
contents: `module.exports = window.HydroExports['${args.path}'];`,
loader: 'tsx',
};
});
},
};