mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
onsite-toolkit: add resolver (#706)
Co-authored-by: panda <panda_dtdyy@outlook.com>
This commit is contained in:
1 parent
d1e79f3a9c
commit
f888537757
7 files changed
+510
-6
No files matched your search
@@ -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',
|
||||
};
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user