diff --git a/packages/core/cli/src/util.js b/packages/core/cli/src/util.js index b31299edf1..84cd0aaf63 100644 --- a/packages/core/cli/src/util.js +++ b/packages/core/cli/src/util.js @@ -190,13 +190,8 @@ exports.genTsConfigPaths = function genTsConfigPaths() { const packageJsonName = require(packageFile).name; const packageDir = dirname(packageFile); const relativePath = packageDir.slice(cwdLength + 1).replace(/\\/, '/'); - const hasClient = fg.sync(['client', 'client.ts', 'client.tsx', 'client.js', 'client.jsx'], { - cwd: join(packageDir, 'src'), - }).length; - if (hasClient) { - paths[`${packageJsonName}/client`] = [`${relativePath}/src/client`]; - } paths[packageJsonName] = [`${relativePath}/src`]; + paths[`${packageJsonName}/client`] = [`${relativePath}/src/client`]; }); const tsConfigJsonPath = join(cwd, './tsconfig.paths.json'); diff --git a/packages/core/client/src/application/PluginManager.ts b/packages/core/client/src/application/PluginManager.ts index 4255a8cc06..3e37b466a3 100644 --- a/packages/core/client/src/application/PluginManager.ts +++ b/packages/core/client/src/application/PluginManager.ts @@ -45,7 +45,6 @@ export class PluginManager { const plugins = await getPlugins({ requirejs: this.app.requirejs, pluginData: pluginList, - baseURL: this.app.apiClient.axios?.defaults?.baseURL, devDynamicImport: this.app.devDynamicImport, }); for await (const plugin of plugins) { diff --git a/packages/core/client/src/application/utils/remotePlugins.ts b/packages/core/client/src/application/utils/remotePlugins.ts index 2b1f94b309..ae2ada08ea 100644 --- a/packages/core/client/src/application/utils/remotePlugins.ts +++ b/packages/core/client/src/application/utils/remotePlugins.ts @@ -9,30 +9,40 @@ export function defineDevPlugins(plugins: Record) { }); } -export function getRemotePlugins( - requirejs: any, - pluginData: PluginData[] = [], - baseURL = '', -): Promise> { - if (baseURL.endsWith('/')) { - baseURL = baseURL.slice(0, -1); - } - if (baseURL.endsWith('/api')) { - baseURL = baseURL.slice(0, -4); - } +export function definePluginClient(packageName: string) { + window.define(`${packageName}/client`, ['exports', packageName], function (_exports: any, _plugin: any) { + Object.defineProperty(_exports, '__esModule', { + value: true, + }); + Object.keys(_plugin).forEach(function (key) { + if (key === 'default' || key === '__esModule') return; + if (key in _exports && _exports[key] === _plugin[key]) return; + Object.defineProperty(_exports, key, { + enumerable: true, + get: function () { + return _plugin[key]; + }, + }); + }); + }); +} +export function getRemotePlugins(requirejs: any, pluginData: PluginData[] = []): Promise> { requirejs.requirejs.config({ waitSeconds: 120, - paths: pluginData.reduce>((memo, item) => { - memo[item.packageName] = `${baseURL}${item.url}?noExt`; - memo[`${item.packageName}/client`] = `${baseURL}${item.url}?noExtAndIsClient`; - return memo; + paths: pluginData.reduce>((acc, cur) => { + acc[cur.packageName] = `${cur.url}?noExt`; + return acc; }, {}), }); + const packageNames = pluginData.map((item) => item.packageName); + packageNames.forEach((packageName) => { + definePluginClient(packageName); + }); return new Promise((resolve, reject) => { requirejs.requirejs( - pluginData.map((item) => item.packageName), + packageNames, (...plugins: (typeof Plugin & { default?: typeof Plugin })[]) => { const res = plugins.filter((item) => item).map((item) => item.default || item); resolve(res); @@ -56,12 +66,11 @@ export function getRemotePlugins( interface GetPluginsOption { requirejs: RequireJS; pluginData: PluginData[]; - baseURL?: string; devDynamicImport?: DevDynamicImport; } export async function getPlugins(options: GetPluginsOption): Promise> { - const { requirejs, pluginData, baseURL, devDynamicImport } = options; + const { requirejs, pluginData, devDynamicImport } = options; if (pluginData.length === 0) return []; @@ -87,10 +96,10 @@ export async function getPlugins(options: GetPluginsOption): Promise