Skip to content

Commit

Permalink
✨ 新增 shouldNotModifyDefaultBase 配置,对齐 umi3 版本的插件
Browse files Browse the repository at this point in the history
  • Loading branch information
kuitos committed Oct 26, 2020
1 parent 9c2689e commit 90adf51
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function(api: IApi, options: GlobalOptions) {
api.registerPlugin({
id: 'qiankun-slave',
apply: slave,
opts: { ...slaveOpts, shouldNotModifyRuntimePublicPath, registerRuntimeKeyInIndex: true },
opts: { shouldNotModifyRuntimePublicPath, registerRuntimeKeyInIndex: true, ...slaveOpts },
});
}
}
31 changes: 20 additions & 11 deletions src/slave/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { Options } from '../types';
const localIpAddress = process.env.USE_REMOTE_IP ? address.ip() : 'localhost';

export default function(api: IApi, options: Options) {
const { registerRuntimeKeyInIndex = false, keepOriginalRoutes = false, shouldNotModifyRuntimePublicPath = false } =
options || {};
const { registerRuntimeKeyInIndex = false, keepOriginalRoutes = false, shouldNotModifyRuntimePublicPath = false, shouldNotModifyDefaultBase = false } =
options || {};
api.addRuntimePlugin(require.resolve('./runtimePlugin'));
if (!registerRuntimeKeyInIndex) {
api.addRuntimePluginKey('qiankun');
Expand All @@ -24,15 +24,24 @@ export default function(api: IApi, options: Options) {
const mountElementId = api.config.mountElementId || defaultSlaveRootId;
// eslint-disable-next-line import/no-dynamic-require, global-require
const { name: pkgName } = require(join(api.cwd, 'package.json'));
api.modifyDefaultConfig(memo => ({
...memo,
// TODO 临时关闭,等这个 pr 合并 https://github.com/umijs/umi/pull/2866
// disableGlobalVariables: true,
base: `/${pkgName}`,
mountElementId,
// 默认开启 runtimePublicPath,避免出现 dynamic import 场景子应用资源地址出问题
runtimePublicPath: true,
}));
api.modifyDefaultConfig(memo => {
const config: any = {
mountElementId,
// 默认开启 runtimePublicPath,避免出现 dynamic import 场景子应用资源地址出问题
runtimePublicPath: true,
};

if (!shouldNotModifyDefaultBase) {
config.base = `/${pkgName}`;
}

return {
...memo,
// TODO 临时关闭,等这个 pr 合并 https://github.com/umijs/umi/pull/2866
// disableGlobalVariables: true,
...config,
};
});

// 如果没有手动关闭 runtimePublicPath,则直接使用 qiankun 注入的 publicPath
if (api.config.runtimePublicPath !== false && !shouldNotModifyRuntimePublicPath) {
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type Options = {
registerRuntimeKeyInIndex?: boolean; // 仅做插件本身透传用,开发者无需关心
keepOriginalRoutes?: boolean | string;
shouldNotModifyRuntimePublicPath?: boolean;
shouldNotModifyDefaultBase?: boolean;
fetch?: typeof window.fetch;
};

Expand Down

0 comments on commit 90adf51

Please sign in to comment.