@umijs/plugins 4.0.0-beta.12 → 4.0.0-beta.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/dist/access.js +73 -1
- package/dist/{dayjs.d.ts → analytics.d.ts} +0 -0
- package/dist/analytics.js +67 -0
- package/dist/antd.js +0 -25
- package/dist/dva.d.ts +3 -9
- package/dist/dva.js +59 -107
- package/dist/initial-state.js +112 -1
- package/dist/layout.js +479 -1
- package/dist/locale.d.ts +1 -0
- package/dist/locale.js +199 -1
- package/dist/model.d.ts +0 -9
- package/dist/model.js +71 -74
- package/dist/moment2dayjs.d.ts +3 -0
- package/dist/moment2dayjs.js +96 -0
- package/dist/qiankun/constants.d.ts +5 -0
- package/dist/qiankun/constants.js +8 -0
- package/dist/qiankun/master.d.ts +6 -0
- package/dist/qiankun/master.js +114 -0
- package/dist/qiankun/slave.d.ts +3 -0
- package/dist/qiankun/slave.js +141 -0
- package/dist/qiankun.js +15 -1
- package/dist/request.js +297 -1
- package/dist/utils/{getIdentifierDeclaration.d.ts → astUtils.d.ts} +0 -0
- package/dist/utils/{getIdentifierDeclaration.js → astUtils.js} +0 -0
- package/dist/utils/localeUtils.d.ts +33 -0
- package/dist/utils/localeUtils.js +135 -0
- package/dist/utils/modelUtils.d.ts +35 -0
- package/dist/utils/modelUtils.js +145 -0
- package/libs/dva.ts +10 -0
- package/libs/locale/SelectLang.tpl +478 -0
- package/libs/locale/locale.tpl +82 -0
- package/libs/locale/localeExports.tpl +271 -0
- package/libs/locale/runtime.tpl +33 -0
- package/libs/model.tsx +140 -0
- package/libs/qiankun/master/AntdErrorBoundary.tsx +34 -0
- package/libs/qiankun/master/AntdLoader.tsx +15 -0
- package/libs/qiankun/master/ErrorBoundary.tsx +7 -0
- package/libs/qiankun/master/MicroApp.tsx +262 -0
- package/libs/qiankun/master/MicroAppWithMemoHistory.tsx +43 -0
- package/libs/qiankun/master/common.ts +133 -0
- package/libs/qiankun/master/constants.ts +7 -0
- package/libs/qiankun/master/getMicroAppRouteComponent.tsx.tpl +45 -0
- package/libs/qiankun/master/masterRuntimePlugin.tsx +130 -0
- package/libs/qiankun/master/types.ts +44 -0
- package/libs/qiankun/slave/connectMaster.tsx +15 -0
- package/libs/qiankun/slave/lifecycles.ts +149 -0
- package/libs/qiankun/slave/qiankunModel.ts +19 -0
- package/libs/qiankun/slave/slaveRuntimePlugin.ts +21 -0
- package/package.json +20 -6
- package/dist/dayjs.js +0 -5
package/dist/model.d.ts
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
1
|
import { IApi } from 'umi';
|
|
2
2
|
declare const _default: (api: IApi) => void;
|
|
3
3
|
export default _default;
|
|
4
|
-
export declare function getAllModels(api: IApi): string[][];
|
|
5
|
-
export declare function getModels(opts: {
|
|
6
|
-
base: string;
|
|
7
|
-
pattern?: string;
|
|
8
|
-
}): string[];
|
|
9
|
-
export declare function isModelValid(opts: {
|
|
10
|
-
content: string;
|
|
11
|
-
file: string;
|
|
12
|
-
}): boolean;
|
package/dist/model.js
CHANGED
|
@@ -18,102 +18,99 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
18
18
|
__setModuleDefault(result, mod);
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
|
-
var
|
|
22
|
-
|
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
23
29
|
};
|
|
24
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.isModelValid = exports.getModels = exports.getAllModels = void 0;
|
|
26
|
-
const parser = __importStar(require("@umijs/bundler-utils/compiled/babel/parser"));
|
|
27
|
-
const traverse_1 = __importDefault(require("@umijs/bundler-utils/compiled/babel/traverse"));
|
|
28
31
|
const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
|
|
29
|
-
const esbuild_1 = require("@umijs/bundler-utils/compiled/esbuild");
|
|
30
32
|
const fs_1 = require("fs");
|
|
31
33
|
const path_1 = require("path");
|
|
32
34
|
const plugin_utils_1 = require("umi/plugin-utils");
|
|
33
|
-
const
|
|
35
|
+
const modelUtils_1 = require("./utils/modelUtils");
|
|
36
|
+
const withTmpPath_1 = require("./utils/withTmpPath");
|
|
34
37
|
exports.default = (api) => {
|
|
35
38
|
api.describe({
|
|
36
39
|
config: {
|
|
37
40
|
schema(Joi) {
|
|
38
|
-
return Joi.object(
|
|
41
|
+
return Joi.object({
|
|
42
|
+
extraModels: Joi.array().items(Joi.string()),
|
|
43
|
+
});
|
|
39
44
|
},
|
|
40
45
|
},
|
|
41
46
|
enableBy: api.EnableBy.config,
|
|
42
47
|
});
|
|
43
|
-
api.modifyAppData((memo) => {
|
|
44
|
-
const models = getAllModels(api);
|
|
48
|
+
api.modifyAppData((memo) => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
+
const models = yield getAllModels(api);
|
|
45
50
|
memo.pluginModel = {
|
|
46
51
|
models,
|
|
47
52
|
};
|
|
48
53
|
return memo;
|
|
49
|
-
});
|
|
50
|
-
api.onGenerateFiles((args) => {
|
|
54
|
+
}));
|
|
55
|
+
api.onGenerateFiles((args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
56
|
const models = args.isFirstTime
|
|
52
|
-
? api.appData.
|
|
53
|
-
: getAllModels(api);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
57
|
+
? api.appData.pluginModel.models
|
|
58
|
+
: yield getAllModels(api);
|
|
59
|
+
// model.ts
|
|
60
|
+
api.writeTmpFile({
|
|
61
|
+
path: 'model.ts',
|
|
62
|
+
content: modelUtils_1.ModelUtils.getModelsContent(models),
|
|
63
|
+
});
|
|
64
|
+
// index.tsx
|
|
65
|
+
const indexContent = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../libs/model.tsx'), 'utf-8').replace('fast-deep-equal', (0, plugin_utils_1.winPath)(require.resolve('fast-deep-equal')));
|
|
66
|
+
api.writeTmpFile({
|
|
67
|
+
path: 'index.tsx',
|
|
68
|
+
content: indexContent,
|
|
69
|
+
});
|
|
70
|
+
// runtime.tsx
|
|
71
|
+
api.writeTmpFile({
|
|
72
|
+
path: 'runtime.tsx',
|
|
73
|
+
content: `
|
|
74
|
+
import React from 'react';
|
|
75
|
+
import { Provider } from './';
|
|
76
|
+
import { models as rawModels } from './model';
|
|
77
|
+
|
|
78
|
+
function ProviderWrapper(props: any) {
|
|
79
|
+
const models = React.useMemo(() => {
|
|
80
|
+
return Object.keys(rawModels).reduce((memo, key) => {
|
|
81
|
+
memo[rawModels[key].namespace] = rawModels[key].model;
|
|
82
|
+
return memo;
|
|
83
|
+
}, {});
|
|
84
|
+
}, []);
|
|
85
|
+
return <Provider models={models} {...props}>{ props.children }</Provider>
|
|
72
86
|
}
|
|
73
|
-
|
|
74
|
-
function
|
|
75
|
-
|
|
76
|
-
.sync(opts.pattern || '**/*.{ts,js}', {
|
|
77
|
-
cwd: opts.base,
|
|
78
|
-
absolute: true,
|
|
79
|
-
})
|
|
80
|
-
.map(plugin_utils_1.winPath)
|
|
81
|
-
.filter((file) => {
|
|
82
|
-
if (/\.d.ts$/.test(file))
|
|
83
|
-
return false;
|
|
84
|
-
if (/\.(test|e2e|spec).([jt])sx?$/.test(file))
|
|
85
|
-
return false;
|
|
86
|
-
const content = (0, fs_1.readFileSync)(file, 'utf-8');
|
|
87
|
-
return isModelValid({ content, file });
|
|
88
|
-
});
|
|
87
|
+
|
|
88
|
+
export function dataflowProvider(container, opts) {
|
|
89
|
+
return <ProviderWrapper {...opts}>{ container }</ProviderWrapper>;
|
|
89
90
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const loader = (0, path_1.extname)(file).slice(1);
|
|
96
|
-
const result = (0, esbuild_1.transformSync)(content, {
|
|
97
|
-
loader,
|
|
98
|
-
sourcemap: false,
|
|
99
|
-
minify: false,
|
|
91
|
+
`,
|
|
92
|
+
});
|
|
93
|
+
}));
|
|
94
|
+
api.addTmpGenerateWatcherPaths(() => {
|
|
95
|
+
return [(0, path_1.join)(api.paths.absSrcPath, 'models')];
|
|
100
96
|
});
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const ast = parser.parse(result.code, {
|
|
104
|
-
sourceType: 'module',
|
|
105
|
-
sourceFilename: file,
|
|
106
|
-
plugins: [],
|
|
97
|
+
api.addRuntimePlugin(() => {
|
|
98
|
+
return [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })];
|
|
107
99
|
});
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
100
|
+
};
|
|
101
|
+
function getAllModels(api) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
const extraModels = yield api.applyPlugins({
|
|
104
|
+
key: 'addExtraModels',
|
|
105
|
+
type: api.ApplyPluginsType.add,
|
|
106
|
+
initialValue: [],
|
|
107
|
+
});
|
|
108
|
+
return new modelUtils_1.ModelUtils(api, {
|
|
109
|
+
astTest({ node }) {
|
|
110
|
+
return t.isArrowFunctionExpression(node) || t.isFunctionDeclaration(node);
|
|
111
|
+
},
|
|
112
|
+
}).getAllModels({
|
|
113
|
+
extraModels: [...extraModels, ...(api.config.model.extraModels || [])],
|
|
114
|
+
});
|
|
116
115
|
});
|
|
117
|
-
return ret;
|
|
118
116
|
}
|
|
119
|
-
exports.isModelValid = isModelValid;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("@umijs/utils");
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
/*
|
|
6
|
+
As long as moment2dayjs is registered, moment will be replaced by dayjs.
|
|
7
|
+
The presets that can adapt to antd is registered by default.
|
|
8
|
+
When the user configures preset and plugins at the same time, we will merge them.
|
|
9
|
+
*/
|
|
10
|
+
exports.default = (api) => {
|
|
11
|
+
api.describe({
|
|
12
|
+
key: 'moment2dayjs',
|
|
13
|
+
config: {
|
|
14
|
+
schema(joi) {
|
|
15
|
+
return joi.object({
|
|
16
|
+
preset: joi.string(),
|
|
17
|
+
plugins: joi.array(),
|
|
18
|
+
});
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
enableBy: api.EnableBy.config,
|
|
22
|
+
});
|
|
23
|
+
const presets = {
|
|
24
|
+
antd: [
|
|
25
|
+
'isSameOrBefore',
|
|
26
|
+
'isSameOrAfter',
|
|
27
|
+
'advancedFormat',
|
|
28
|
+
'customParseFormat',
|
|
29
|
+
'weekday',
|
|
30
|
+
'weekYear',
|
|
31
|
+
'weekOfYear',
|
|
32
|
+
'isMoment',
|
|
33
|
+
'localeData',
|
|
34
|
+
'localizedFormat',
|
|
35
|
+
],
|
|
36
|
+
antdv3: [
|
|
37
|
+
'isSameOrBefore',
|
|
38
|
+
'isSameOrAfter',
|
|
39
|
+
'advancedFormat',
|
|
40
|
+
'customParseFormat',
|
|
41
|
+
'weekday',
|
|
42
|
+
'weekYear',
|
|
43
|
+
'weekOfYear',
|
|
44
|
+
'isMoment',
|
|
45
|
+
'localeData',
|
|
46
|
+
'localizedFormat',
|
|
47
|
+
'badMutable',
|
|
48
|
+
],
|
|
49
|
+
};
|
|
50
|
+
const getDayjsPlugins = (api) => {
|
|
51
|
+
let { preset = 'antd', plugins = [] } = api.config.moment2dayjs || {};
|
|
52
|
+
switch (preset) {
|
|
53
|
+
case 'antd':
|
|
54
|
+
return Array.from(new Set(presets['antd'].concat(plugins)));
|
|
55
|
+
case 'antdv3':
|
|
56
|
+
return Array.from(new Set(presets['antdv3'].concat(plugins)));
|
|
57
|
+
case 'none':
|
|
58
|
+
return [].concat(plugins);
|
|
59
|
+
default:
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
// replace moment
|
|
64
|
+
api.modifyConfig((memo) => {
|
|
65
|
+
memo.alias.moment = (0, path_1.dirname)(require.resolve('dayjs/package.json'));
|
|
66
|
+
return memo;
|
|
67
|
+
});
|
|
68
|
+
api.onGenerateFiles(() => {
|
|
69
|
+
const plugins = getDayjsPlugins(api);
|
|
70
|
+
const runtimeTpl = `
|
|
71
|
+
import dayjs from '{{{dayjsPath}}}';
|
|
72
|
+
import antdPlugin from '{{{dayjsAntdPluginPath}}}';
|
|
73
|
+
|
|
74
|
+
{{#plugins}}
|
|
75
|
+
import {{.}} from '{{{dayjsPath}}}/plugin/{{.}}';
|
|
76
|
+
{{/plugins}}
|
|
77
|
+
|
|
78
|
+
{{#plugins}}
|
|
79
|
+
dayjs.extend({{.}});
|
|
80
|
+
{{/plugins}}
|
|
81
|
+
|
|
82
|
+
dayjs.extend(antdPlugin);
|
|
83
|
+
`;
|
|
84
|
+
const dayjsAntdPluginPath = require.resolve('antd-dayjs-webpack-plugin/src/antd-plugin');
|
|
85
|
+
const dayjsPath = (0, path_1.dirname)(require.resolve('dayjs/package.json'));
|
|
86
|
+
api.writeTmpFile({
|
|
87
|
+
path: 'runtime.tsx',
|
|
88
|
+
content: utils_1.Mustache.render(runtimeTpl, {
|
|
89
|
+
plugins,
|
|
90
|
+
dayjsPath,
|
|
91
|
+
dayjsAntdPluginPath,
|
|
92
|
+
}),
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
api.addEntryCodeAhead(() => [`import './plugin-moment2dayjs/runtime.tsx'`]);
|
|
96
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const defaultMasterRootId = "root-master";
|
|
2
|
+
export declare const defaultHistoryType = "browser";
|
|
3
|
+
export declare const qiankunStateForSlaveModelNamespace = "@@qiankunStateForSlave";
|
|
4
|
+
export declare const qiankunStateFromMasterModelNamespace = "@@qiankunStateFromMaster";
|
|
5
|
+
export declare const MODEL_EXPORT_NAME = "useQiankunStateForSlave";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MODEL_EXPORT_NAME = exports.qiankunStateFromMasterModelNamespace = exports.qiankunStateForSlaveModelNamespace = exports.defaultHistoryType = exports.defaultMasterRootId = void 0;
|
|
4
|
+
exports.defaultMasterRootId = 'root-master';
|
|
5
|
+
exports.defaultHistoryType = 'browser';
|
|
6
|
+
exports.qiankunStateForSlaveModelNamespace = '@@qiankunStateForSlave';
|
|
7
|
+
exports.qiankunStateFromMasterModelNamespace = '@@qiankunStateFromMaster';
|
|
8
|
+
exports.MODEL_EXPORT_NAME = 'useQiankunStateForSlave';
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isMasterEnable = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const withTmpPath_1 = require("../utils/withTmpPath");
|
|
7
|
+
const constants_1 = require("./constants");
|
|
8
|
+
function isMasterEnable(opts) {
|
|
9
|
+
var _a;
|
|
10
|
+
const masterCfg = (_a = opts.userConfig.qiankun) === null || _a === void 0 ? void 0 : _a.master;
|
|
11
|
+
if (masterCfg) {
|
|
12
|
+
return masterCfg.enable !== false;
|
|
13
|
+
}
|
|
14
|
+
return !!process.env.INITIAL_QIANKUN_MASTER_OPTIONS;
|
|
15
|
+
}
|
|
16
|
+
exports.isMasterEnable = isMasterEnable;
|
|
17
|
+
exports.default = (api) => {
|
|
18
|
+
api.describe({
|
|
19
|
+
key: 'qiankun-master',
|
|
20
|
+
enableBy: isMasterEnable,
|
|
21
|
+
});
|
|
22
|
+
api.addRuntimePlugin(() => {
|
|
23
|
+
return [(0, withTmpPath_1.withTmpPath)({ api, path: 'masterRuntimePlugin.tsx' })];
|
|
24
|
+
});
|
|
25
|
+
api.modifyDefaultConfig((config) => (Object.assign(Object.assign({}, config), { mountElementId: constants_1.defaultMasterRootId, qiankun: Object.assign(Object.assign({}, config.qiankun), { master: Object.assign(Object.assign({}, JSON.parse(process.env.INITIAL_QIANKUN_MASTER_OPTIONS || '{}')), (config.qiankun || {}).master) }) })));
|
|
26
|
+
// TODO: modify routes
|
|
27
|
+
api.modifyRoutes((memo) => {
|
|
28
|
+
Object.keys(memo).forEach((id) => {
|
|
29
|
+
const route = memo[id];
|
|
30
|
+
if (route.microApp) {
|
|
31
|
+
const appName = route.microApp;
|
|
32
|
+
// TODO: config base
|
|
33
|
+
const base = '/';
|
|
34
|
+
// TODO: config masterHistoryType
|
|
35
|
+
const masterHistoryType = 'browser';
|
|
36
|
+
const routeProps = route.microAppProps || {};
|
|
37
|
+
const normalizedRouteProps = JSON.stringify(routeProps).replace(/"/g, "'");
|
|
38
|
+
route.file = `(async () => {
|
|
39
|
+
const { getMicroAppRouteComponent } = await import('@@/plugin-qiankun-master/getMicroAppRouteComponent');
|
|
40
|
+
return getMicroAppRouteComponent({ appName: '${appName}', base: '${base}', masterHistoryType: '${masterHistoryType}', routeProps: ${normalizedRouteProps} })
|
|
41
|
+
})()`;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return memo;
|
|
45
|
+
});
|
|
46
|
+
// state model for slave app
|
|
47
|
+
api.addRuntimePluginKey(() => [constants_1.MODEL_EXPORT_NAME]);
|
|
48
|
+
api.register({
|
|
49
|
+
key: 'addExtraModels',
|
|
50
|
+
fn() {
|
|
51
|
+
const { path, exports } = api.appData.appJS || {};
|
|
52
|
+
return path && exports.includes(constants_1.MODEL_EXPORT_NAME)
|
|
53
|
+
? [
|
|
54
|
+
`${path}#{"namespace":"${constants_1.qiankunStateForSlaveModelNamespace}","exportName":"${constants_1.MODEL_EXPORT_NAME}"}`,
|
|
55
|
+
]
|
|
56
|
+
: [];
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
function getFileContent(file) {
|
|
60
|
+
return (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../../libs/qiankun/master', file), 'utf-8');
|
|
61
|
+
}
|
|
62
|
+
api.onGenerateFiles(() => {
|
|
63
|
+
var _a;
|
|
64
|
+
api.writeTmpFile({
|
|
65
|
+
path: 'masterOptions.ts',
|
|
66
|
+
content: `
|
|
67
|
+
let options = ${JSON.stringify(Object.assign({ masterHistoryType: ((_a = api.config.history) === null || _a === void 0 ? void 0 : _a.type) || constants_1.defaultHistoryType, base: api.config.base || '/' }, api.config.qiankun.master))};
|
|
68
|
+
export const getMasterOptions = () => options;
|
|
69
|
+
export const setMasterOptions = (newOpts) => options = ({ ...options, ...newOpts });
|
|
70
|
+
`,
|
|
71
|
+
});
|
|
72
|
+
api.writeTmpFile({
|
|
73
|
+
path: 'MicroAppLoader.tsx',
|
|
74
|
+
// 开启了 antd 插件的时候,使用 antd 的 loader 组件,否则提示用户必须设置一个自定义的 loader 组件
|
|
75
|
+
content: api.isPluginEnable('antd')
|
|
76
|
+
? getFileContent('AntdLoader.tsx')
|
|
77
|
+
: `export default function Loader() { console.warn(\`[plugins/qiankun]: Seems like you'r not using @umijs/plugin-antd, you need to provide a custom loader or set autoSetLoading false to shut down this warning!\`); return null; }`,
|
|
78
|
+
});
|
|
79
|
+
[
|
|
80
|
+
'common.ts',
|
|
81
|
+
'constants.ts',
|
|
82
|
+
'types.ts',
|
|
83
|
+
'masterRuntimePlugin.tsx',
|
|
84
|
+
'getMicroAppRouteComponent.tsx.tpl',
|
|
85
|
+
'ErrorBoundary.tsx',
|
|
86
|
+
'MicroApp.tsx',
|
|
87
|
+
].forEach((file) => {
|
|
88
|
+
if (file.endsWith('.tpl')) {
|
|
89
|
+
api.writeTmpFile({
|
|
90
|
+
path: file.replace(/\.tpl$/, ''),
|
|
91
|
+
tpl: getFileContent(file),
|
|
92
|
+
context: {
|
|
93
|
+
runtimeHistory: api.config.runtimeHistory,
|
|
94
|
+
dynamicRoot: false,
|
|
95
|
+
hasModelPlugin: api.isPluginEnable('model'),
|
|
96
|
+
// dynamicRoot:
|
|
97
|
+
// api.config.exportStatic && api.config.exportStatic.dynamicRoot,
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
api.writeTmpFile({
|
|
103
|
+
path: file.replace(/\.tpl$/, ''),
|
|
104
|
+
content: getFileContent(file)
|
|
105
|
+
.replace('__USE_MODEL__', api.isPluginEnable('model')
|
|
106
|
+
? `import { useModel } from '@@/plugin-model'`
|
|
107
|
+
: `const useModel = null;`)
|
|
108
|
+
.replace(/from 'qiankun'/g, `from '${(0, path_1.dirname)(require.resolve('qiankun/package'))}'`)
|
|
109
|
+
.replace(/from 'lodash\//g, `from '${(0, path_1.dirname)(require.resolve('lodash/package'))}/`),
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const assert_1 = __importDefault(require("assert"));
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const withTmpPath_1 = require("../utils/withTmpPath");
|
|
10
|
+
const constants_1 = require("./constants");
|
|
11
|
+
// BREAK CHANGE: 需要手动配置 slave: {},不能留空
|
|
12
|
+
function isSlaveEnable(opts) {
|
|
13
|
+
var _a, _b;
|
|
14
|
+
const slaveCfg = (_b = (_a = opts.userConfig) === null || _a === void 0 ? void 0 : _a.qiankun) === null || _b === void 0 ? void 0 : _b.slave;
|
|
15
|
+
if (slaveCfg) {
|
|
16
|
+
return slaveCfg.enable !== false;
|
|
17
|
+
}
|
|
18
|
+
return !!process.env.INITIAL_QIANKUN_SLAVE_OPTIONS;
|
|
19
|
+
}
|
|
20
|
+
exports.default = (api) => {
|
|
21
|
+
api.describe({
|
|
22
|
+
key: 'qiankun-slave',
|
|
23
|
+
enableBy: isSlaveEnable,
|
|
24
|
+
});
|
|
25
|
+
api.addRuntimePlugin(() => {
|
|
26
|
+
return [(0, withTmpPath_1.withTmpPath)({ api, path: 'slaveRuntimePlugin.ts' })];
|
|
27
|
+
});
|
|
28
|
+
api.register({
|
|
29
|
+
key: 'addExtraModels',
|
|
30
|
+
fn() {
|
|
31
|
+
return [
|
|
32
|
+
`@@/plugin-qiankun-slave/qiankunModel#{"namespace":"${constants_1.qiankunStateFromMasterModelNamespace}"}`,
|
|
33
|
+
];
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
api.modifyDefaultConfig((memo) => {
|
|
37
|
+
var _a, _b, _c;
|
|
38
|
+
const initialSlaveOptions = Object.assign(Object.assign({ devSourceMap: true }, JSON.parse(process.env.INITIAL_QIANKUN_SLAVE_OPTIONS || '{}')), (memo.qiankun || {}).slave);
|
|
39
|
+
const modifiedDefaultConfig = Object.assign(Object.assign({}, memo), {
|
|
40
|
+
// 默认开启 runtimePublicPath,避免出现 dynamic import 场景子应用资源地址出问题
|
|
41
|
+
runtimePublicPath: true,
|
|
42
|
+
// TODO: runtimeHistory
|
|
43
|
+
runtimeHistory: {}, qiankun: Object.assign(Object.assign({}, memo.qiankun), { slave: initialSlaveOptions }) });
|
|
44
|
+
const shouldNotModifyDefaultBase = (_c = (_b = (_a = api.userConfig.qiankun) === null || _a === void 0 ? void 0 : _a.slave) === null || _b === void 0 ? void 0 : _b.shouldNotModifyDefaultBase) !== null && _c !== void 0 ? _c : initialSlaveOptions.shouldNotModifyDefaultBase;
|
|
45
|
+
if (!shouldNotModifyDefaultBase) {
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
modifiedDefaultConfig.base = `/${api.pkg.name}`;
|
|
48
|
+
}
|
|
49
|
+
return modifiedDefaultConfig;
|
|
50
|
+
});
|
|
51
|
+
api.modifyConfig((config) => {
|
|
52
|
+
var _a, _b;
|
|
53
|
+
// mfsu 场景默认给子应用增加 mfName 配置,从而避免冲突
|
|
54
|
+
if (config.mfsu !== false) {
|
|
55
|
+
config.mfsu = Object.assign(Object.assign({}, config.mfsu), { mfName: ((_a = config.mfsu) === null || _a === void 0 ? void 0 : _a.mfName) ||
|
|
56
|
+
`mf_${(_b = api.pkg.name) === null || _b === void 0 ? void 0 : _b.replace(/^@/, '').replace(/\W/g, '_')}` });
|
|
57
|
+
}
|
|
58
|
+
return config;
|
|
59
|
+
});
|
|
60
|
+
// api.modifyPublicPathStr((publicPathStr) => {
|
|
61
|
+
// const { runtimePublicPath } = api.config;
|
|
62
|
+
// const { shouldNotModifyRuntimePublicPath } = (api.config.qiankun || {})
|
|
63
|
+
// .slave!;
|
|
64
|
+
// if (runtimePublicPath === true && !shouldNotModifyRuntimePublicPath) {
|
|
65
|
+
// return `window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ || "${
|
|
66
|
+
// api.config.publicPath || '/'
|
|
67
|
+
// }"`;
|
|
68
|
+
// }
|
|
69
|
+
// return publicPathStr;
|
|
70
|
+
// });
|
|
71
|
+
api.chainWebpack((config) => {
|
|
72
|
+
(0, assert_1.default)(api.pkg.name, 'You should have name in package.json.');
|
|
73
|
+
const { shouldNotAddLibraryChunkName } = (api.config.qiankun || {}).slave;
|
|
74
|
+
config.output
|
|
75
|
+
.libraryTarget('umd')
|
|
76
|
+
.library(shouldNotAddLibraryChunkName ? api.pkg.name : `${api.pkg.name}-[name]`);
|
|
77
|
+
// TODO: SOCKET_SERVER
|
|
78
|
+
// TODO: devSourceMap
|
|
79
|
+
return config;
|
|
80
|
+
});
|
|
81
|
+
// umi bundle 添加 entry 标记
|
|
82
|
+
api.modifyHTML(($) => {
|
|
83
|
+
$('script').each((_, el) => {
|
|
84
|
+
var _a;
|
|
85
|
+
const scriptEl = $(el);
|
|
86
|
+
const umiEntry = /\/?umi(\.\w+)?\.js$/g;
|
|
87
|
+
if (umiEntry.test((_a = scriptEl.attr('src')) !== null && _a !== void 0 ? _a : '')) {
|
|
88
|
+
scriptEl.attr('entry', '');
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
return $;
|
|
92
|
+
});
|
|
93
|
+
api.addEntryImports(() => {
|
|
94
|
+
return [
|
|
95
|
+
{
|
|
96
|
+
source: '@@/plugin-qiankun-slave/lifecycles',
|
|
97
|
+
specifier: '{ genMount as qiankun_genMount, genBootstrap as qiankun_genBootstrap, genUnmount as qiankun_genUnmount, genUpdate as qiankun_genUpdate }',
|
|
98
|
+
},
|
|
99
|
+
];
|
|
100
|
+
});
|
|
101
|
+
api.addEntryCode(() => [
|
|
102
|
+
`
|
|
103
|
+
export const bootstrap = qiankun_genBootstrap(render);
|
|
104
|
+
export const mount = qiankun_genMount('${api.config.mountElementId}');
|
|
105
|
+
export const unmount = qiankun_genUnmount('${api.config.mountElementId}');
|
|
106
|
+
export const update = qiankun_genUpdate();
|
|
107
|
+
if (!window.__POWERED_BY_QIANKUN__) {
|
|
108
|
+
bootstrap().then(mount);
|
|
109
|
+
}
|
|
110
|
+
`,
|
|
111
|
+
]);
|
|
112
|
+
function getFileContent(file) {
|
|
113
|
+
return (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../../libs/qiankun/slave', file), 'utf-8');
|
|
114
|
+
}
|
|
115
|
+
api.onGenerateFiles(() => {
|
|
116
|
+
// api.writeTmpFile({
|
|
117
|
+
// path: 'slaveOptions.ts',
|
|
118
|
+
// content: `
|
|
119
|
+
// let options = ${JSON.stringify((api.config.qiankun || {}).slave || {})};
|
|
120
|
+
// export const getSlaveOptions = () => options;
|
|
121
|
+
// export const setSlaveOptions = (newOpts) => options = ({ ...options, ...newOpts });
|
|
122
|
+
// `,
|
|
123
|
+
// });
|
|
124
|
+
[
|
|
125
|
+
'qiankunModel.ts',
|
|
126
|
+
'connectMaster.tsx',
|
|
127
|
+
'slaveRuntimePlugin.ts',
|
|
128
|
+
'lifecycles.ts',
|
|
129
|
+
].forEach((file) => {
|
|
130
|
+
api.writeTmpFile({
|
|
131
|
+
path: file.replace(/\.tpl$/, ''),
|
|
132
|
+
content: getFileContent(file)
|
|
133
|
+
.replace('__USE_MODEL__', api.isPluginEnable('model')
|
|
134
|
+
? `import { useModel } from '@@/plugin/model'`
|
|
135
|
+
: `const useModel = null;`)
|
|
136
|
+
.replace(/from 'qiankun'/g, `from '${(0, path_1.dirname)(require.resolve('qiankun/package'))}'`)
|
|
137
|
+
.replace(/from 'lodash\//g, `from '${(0, path_1.dirname)(require.resolve('lodash/package'))}/`),
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
};
|
package/dist/qiankun.js
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = (api) => {
|
|
4
|
-
api
|
|
4
|
+
api.describe({
|
|
5
|
+
config: {
|
|
6
|
+
schema(joi) {
|
|
7
|
+
return joi.object().keys({
|
|
8
|
+
slave: joi.object(),
|
|
9
|
+
master: joi.object(),
|
|
10
|
+
});
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
api.addRuntimePluginKey(() => ['qiankun']);
|
|
15
|
+
api.registerPlugins([
|
|
16
|
+
require.resolve('./qiankun/master'),
|
|
17
|
+
require.resolve('./qiankun/slave'),
|
|
18
|
+
]);
|
|
5
19
|
};
|