Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ 支持传入 shouldNotModifyPublicPath 参数来关闭 qiankun 注入的 runtimePublicPath #59

Merged
merged 3 commits into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { IApi } from 'umi-types';
import assert from 'assert';
import { GlobalOptions } from './types';
import { IApi } from 'umi-types';
import master from './master';
import slave from './slave';
import { GlobalOptions } from './types';

export default function(api: IApi, options: GlobalOptions) {
api.addRuntimePluginKey('qiankun');
Expand All @@ -18,7 +18,7 @@ export default function(api: IApi, options: GlobalOptions) {
}
});

const { master: masterOpts, slave: slaveOpts } = options || {};
const { master: masterOpts, slave: slaveOpts, shouldNotModifyRuntimePublicPath = false } = options || {};

assert(!(masterOpts && slaveOpts), '请勿同时配置 master 和 slave 配置项');

Expand All @@ -32,7 +32,7 @@ export default function(api: IApi, options: GlobalOptions) {
api.registerPlugin({
id: 'qiankun-slave',
apply: slave,
opts: { ...slaveOpts, registerRuntimeKeyInIndex: true },
opts: { ...slaveOpts, shouldNotModifyRuntimePublicPath, registerRuntimeKeyInIndex: true },
});
}
}
5 changes: 3 additions & 2 deletions src/slave/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +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 } = options || {};
const { registerRuntimeKeyInIndex = false, keepOriginalRoutes = false, shouldNotModifyRuntimePublicPath = false } =
options || {};
api.addRuntimePlugin(require.resolve('./runtimePlugin'));
if (!registerRuntimeKeyInIndex) {
api.addRuntimePluginKey('qiankun');
Expand All @@ -34,7 +35,7 @@ export default function(api: IApi, options: Options) {
}));

// 如果没有手动关闭 runtimePublicPath,则直接使用 qiankun 注入的 publicPath
if (api.config.runtimePublicPath !== false) {
if (api.config.runtimePublicPath !== false && !shouldNotModifyRuntimePublicPath) {
api.modifyPublicPathStr(
`window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ || window.publicPath || "${
// 开发阶段 publicPath 配置无效,默认为 /
Expand Down
6 changes: 4 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @since 2019-06-20
*/

import { LifeCycles, Fetch } from 'qiankun';
import { LifeCycles } from 'qiankun';
// eslint-disable-next-line import/no-unresolved
import { IConfig } from 'umi-types';

Expand All @@ -23,12 +23,14 @@ export type Options = {
masterHistory: IConfig['history'];
registerRuntimeKeyInIndex?: boolean; // 仅做插件本身透传用,开发者无需关心
keepOriginalRoutes?: boolean | string;
fetch?: Fetch;
shouldNotModifyRuntimePublicPath?: boolean;
fetch?: typeof window.fetch;
};

export type keepOriginalRoutesOption = boolean | string;

export type GlobalOptions = {
master?: Options;
slave?: Options;
shouldNotModifyRuntimePublicPath?: boolean;
};