fix: dev load remote plugin (#3175)
This commit is contained in:
parent
efb6580eaf
commit
cb0d757a6b
@ -4,8 +4,8 @@ import type { RequireJS } from './requirejs';
|
|||||||
import type { DevDynamicImport } from '../Application';
|
import type { DevDynamicImport } from '../Application';
|
||||||
|
|
||||||
export function defineDevPlugins(plugins: Record<string, typeof Plugin>) {
|
export function defineDevPlugins(plugins: Record<string, typeof Plugin>) {
|
||||||
Object.entries(plugins).forEach(([name, plugin]) => {
|
Object.entries(plugins).forEach(([packageName, plugin]) => {
|
||||||
window.define(name, () => plugin);
|
window.define(`${packageName}/client`, () => plugin);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +77,6 @@ interface GetPluginsOption {
|
|||||||
|
|
||||||
export async function getPlugins(options: GetPluginsOption): Promise<Array<[string, typeof Plugin]>> {
|
export async function getPlugins(options: GetPluginsOption): Promise<Array<[string, typeof Plugin]>> {
|
||||||
const { requirejs, pluginData, devDynamicImport } = options;
|
const { requirejs, pluginData, devDynamicImport } = options;
|
||||||
|
|
||||||
if (pluginData.length === 0) return [];
|
if (pluginData.length === 0) return [];
|
||||||
|
|
||||||
if (process.env.NODE_ENV === 'development' && !process.env.USE_REMOTE_PLUGIN) {
|
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);
|
const pluginModule = await devDynamicImport(plugin.packageName);
|
||||||
if (pluginModule) {
|
if (pluginModule) {
|
||||||
res.push([plugin.name, pluginModule.default]);
|
res.push([plugin.name, pluginModule.default]);
|
||||||
resolveDevPlugins[plugin.name] = pluginModule.default;
|
resolveDevPlugins[plugin.packageName] = pluginModule.default;
|
||||||
} else {
|
|
||||||
console.error(`[nocobase]: plugin ${plugin.packageName} load error`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
defineDevPlugins(resolveDevPlugins);
|
defineDevPlugins(resolveDevPlugins);
|
||||||
}
|
}
|
||||||
|
|
||||||
const remotePlugins = pluginData.filter((item) => !resolveDevPlugins[item.name]);
|
const remotePlugins = pluginData.filter((item) => !resolveDevPlugins[item.packageName]);
|
||||||
|
|
||||||
if (remotePlugins.length === 0) {
|
if (remotePlugins.length === 0) {
|
||||||
return res;
|
return res;
|
||||||
|
Loading…
Reference in New Issue
Block a user