fix: dev load remote plugin (#3175)

This commit is contained in:
jack zhang 2023-12-11 16:16:04 +08:00 committed by chenos
parent 9d644304c1
commit ed37b78c33

View File

@ -4,8 +4,8 @@ import type { RequireJS } from './requirejs';
import type { DevDynamicImport } from '../Application';
export function defineDevPlugins(plugins: Record<string, typeof Plugin>) {
Object.entries(plugins).forEach(([name, plugin]) => {
window.define(name, () => plugin);
Object.entries(plugins).forEach(([packageName, plugin]) => {
window.define(`${packageName}/client`, () => plugin);
});
}
@ -77,7 +77,6 @@ interface GetPluginsOption {
export async function getPlugins(options: GetPluginsOption): Promise<Array<[string, typeof Plugin]>> {
const { requirejs, pluginData, devDynamicImport } = options;
if (pluginData.length === 0) return [];
if (process.env.NODE_ENV === 'development' && !process.env.USE_REMOTE_PLUGIN) {
@ -89,15 +88,13 @@ export async function getPlugins(options: GetPluginsOption): Promise<Array<[stri
const pluginModule = await devDynamicImport(plugin.packageName);
if (pluginModule) {
res.push([plugin.name, pluginModule.default]);
resolveDevPlugins[plugin.name] = pluginModule.default;
} else {
console.error(`[nocobase]: plugin ${plugin.packageName} load error`);
resolveDevPlugins[plugin.packageName] = pluginModule.default;
}
}
defineDevPlugins(resolveDevPlugins);
}
const remotePlugins = pluginData.filter((item) => !resolveDevPlugins[item.name]);
const remotePlugins = pluginData.filter((item) => !resolveDevPlugins[item.packageName]);
if (remotePlugins.length === 0) {
return res;