@umijs/plugins 4.0.0-rc.7 → 4.0.0
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/dist/access.js +79 -17
- package/dist/analytics.js +1 -1
- package/dist/antd.js +25 -4
- package/dist/dva.js +14 -3
- package/dist/initial-state.js +12 -9
- package/dist/layout.js +114 -27
- package/dist/locale.js +40 -43
- package/dist/model.js +16 -35
- package/dist/qiankun/master.js +31 -11
- package/dist/qiankun/slave.js +66 -44
- package/dist/qiankun.js +1 -0
- package/dist/request.js +136 -127
- package/dist/utils/localeUtils.js +5 -14
- package/dist/utils/modelUtils.d.ts +6 -1
- package/dist/utils/modelUtils.js +110 -8
- package/libs/model.tsx +43 -5
- package/libs/qiankun/master/MicroApp.tsx +15 -6
- package/libs/qiankun/master/common.ts +15 -10
- package/libs/qiankun/master/getMicroAppRouteComponent.tsx.tpl +5 -16
- package/libs/qiankun/master/masterRuntimePlugin.tsx +6 -5
- package/libs/qiankun/master/types.ts +2 -0
- package/libs/qiankun/slave/connectMaster.tsx +0 -1
- package/libs/qiankun/slave/lifecycles.ts +14 -8
- package/libs/qiankun/slave/qiankunModel.ts +0 -1
- package/libs/qiankun/slave/slaveRuntimePlugin.ts +9 -15
- package/package.json +13 -13
package/dist/locale.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.packageNormalize = void 0;
|
|
13
4
|
const fs_1 = require("fs");
|
|
@@ -19,7 +10,6 @@ const packageNormalize = (packageName) => packageName.replace(/[@\/\-.]/g, '_');
|
|
|
19
10
|
exports.packageNormalize = packageNormalize;
|
|
20
11
|
// TODO: runtime plugin
|
|
21
12
|
exports.default = (api) => {
|
|
22
|
-
var _a;
|
|
23
13
|
// TODO: antd 的校验考虑 antd 插件
|
|
24
14
|
let hasAntd = false;
|
|
25
15
|
try {
|
|
@@ -52,46 +42,49 @@ exports.default = (api) => {
|
|
|
52
42
|
});
|
|
53
43
|
const reactIntlPkgPath = (0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('react-intl/package')));
|
|
54
44
|
// polyfill
|
|
55
|
-
|
|
56
|
-
|
|
45
|
+
api.addEntryImportsAhead(() => (0, localeUtils_1.isNeedPolyfill)(api.config.targets || {})
|
|
46
|
+
? [
|
|
57
47
|
{
|
|
58
48
|
source: require.resolve('intl'),
|
|
59
49
|
},
|
|
60
|
-
]
|
|
61
|
-
|
|
62
|
-
const addAntdLocales = (args) =>
|
|
63
|
-
var
|
|
64
|
-
return
|
|
50
|
+
]
|
|
51
|
+
: []);
|
|
52
|
+
const addAntdLocales = async (args) => {
|
|
53
|
+
var _a;
|
|
54
|
+
return await api.applyPlugins({
|
|
65
55
|
key: 'addAntdLocales',
|
|
66
56
|
type: api.ApplyPluginsType.add,
|
|
67
57
|
initialValue: [
|
|
68
|
-
`antd/${((
|
|
58
|
+
`antd/${((_a = api.config) === null || _a === void 0 ? void 0 : _a.ssr) ? 'lib' : 'es'}/locale/${(0, localeUtils_1.getAntdLocale)(args.lang, args.country)}`,
|
|
69
59
|
],
|
|
70
60
|
args,
|
|
71
61
|
});
|
|
72
|
-
}
|
|
73
|
-
const getList = (resolveKey) =>
|
|
74
|
-
var
|
|
62
|
+
};
|
|
63
|
+
const getList = async (resolveKey) => {
|
|
64
|
+
var _a;
|
|
75
65
|
const { paths } = api;
|
|
76
66
|
return (0, localeUtils_1.getLocaleList)({
|
|
77
|
-
localeFolder:
|
|
78
|
-
separator: (
|
|
67
|
+
localeFolder: 'locales',
|
|
68
|
+
separator: (_a = api.config.locale) === null || _a === void 0 ? void 0 : _a.baseSeparator,
|
|
79
69
|
absSrcPath: paths.absSrcPath,
|
|
80
70
|
absPagesPath: paths.absPagesPath,
|
|
81
71
|
addAntdLocales,
|
|
82
72
|
resolveKey,
|
|
83
73
|
});
|
|
84
|
-
}
|
|
85
|
-
api.onGenerateFiles(() =>
|
|
86
|
-
var
|
|
74
|
+
};
|
|
75
|
+
api.onGenerateFiles(async () => {
|
|
76
|
+
var _a, _b, _c, _d;
|
|
87
77
|
const localeTpl = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../libs/locale/locale.tpl'), 'utf-8');
|
|
88
78
|
// moment2dayjs
|
|
89
79
|
const resolveKey = api.config.moment2dayjs ? 'dayjs' : 'moment';
|
|
90
80
|
const momentPkgPath = (0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve(`${resolveKey}/package.json`)));
|
|
91
81
|
const EventEmitterPkg = (0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('event-emitter/package')));
|
|
92
|
-
const { baseSeparator, baseNavigator, antd, title, useLocalStorage } =
|
|
93
|
-
|
|
94
|
-
|
|
82
|
+
const { baseSeparator, baseNavigator, antd, title, useLocalStorage } = {
|
|
83
|
+
...defaultConfig,
|
|
84
|
+
...api.config.locale,
|
|
85
|
+
};
|
|
86
|
+
const defaultLocale = ((_a = api.config.locale) === null || _a === void 0 ? void 0 : _a.default) || `zh${baseSeparator}CN`;
|
|
87
|
+
const localeList = await getList(resolveKey);
|
|
95
88
|
const momentLocales = localeList
|
|
96
89
|
.map(({ momentLocale }) => momentLocale)
|
|
97
90
|
.filter((locale) => locale);
|
|
@@ -101,7 +94,7 @@ exports.default = (api) => {
|
|
|
101
94
|
let MomentLocales = momentLocales;
|
|
102
95
|
let DefaultMomentLocale = '';
|
|
103
96
|
// set moment default accounding to locale.default
|
|
104
|
-
if (!MomentLocales.length && ((
|
|
97
|
+
if (!MomentLocales.length && ((_b = api.config.locale) === null || _b === void 0 ? void 0 : _b.default)) {
|
|
105
98
|
const [lang, country = ''] = defaultLocale.split(baseSeparator);
|
|
106
99
|
const { momentLocale } = (0, localeUtils_1.getMomentLocale)(lang, country, resolveKey);
|
|
107
100
|
if (momentLocale) {
|
|
@@ -111,9 +104,9 @@ exports.default = (api) => {
|
|
|
111
104
|
}
|
|
112
105
|
let DefaultAntdLocales = [];
|
|
113
106
|
// set antd default locale
|
|
114
|
-
if (!antdLocales.length && ((
|
|
107
|
+
if (!antdLocales.length && ((_c = api.config.locale) === null || _c === void 0 ? void 0 : _c.antd)) {
|
|
115
108
|
const [lang, country = ''] = defaultLocale.split(baseSeparator);
|
|
116
|
-
DefaultAntdLocales = plugin_utils_1.lodash.uniq(
|
|
109
|
+
DefaultAntdLocales = plugin_utils_1.lodash.uniq(await addAntdLocales({
|
|
117
110
|
lang,
|
|
118
111
|
country,
|
|
119
112
|
}));
|
|
@@ -138,7 +131,7 @@ exports.default = (api) => {
|
|
|
138
131
|
path: 'locale.tsx',
|
|
139
132
|
});
|
|
140
133
|
const localeExportsTpl = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../libs/locale/localeExports.tpl'), 'utf-8');
|
|
141
|
-
const localeDirName =
|
|
134
|
+
const localeDirName = 'locales';
|
|
142
135
|
const localeDirPath = (0, path_1.join)(api.paths.absSrcPath, localeDirName);
|
|
143
136
|
api.writeTmpFile({
|
|
144
137
|
path: 'localeExports.ts',
|
|
@@ -149,16 +142,20 @@ exports.default = (api) => {
|
|
|
149
142
|
UseLocalStorage: !!useLocalStorage,
|
|
150
143
|
LocaleDir: localeDirName,
|
|
151
144
|
ExistLocaleDir: (0, fs_1.existsSync)(localeDirPath),
|
|
152
|
-
LocaleList: localeList.map((locale) => (
|
|
145
|
+
LocaleList: localeList.map((locale) => ({
|
|
146
|
+
...locale,
|
|
147
|
+
antdLocale: locale.antdLocale.map((antdLocale, index) => ({
|
|
153
148
|
locale: antdLocale,
|
|
154
149
|
index: index,
|
|
155
|
-
})),
|
|
150
|
+
})),
|
|
151
|
+
paths: locale.paths.map((path, index) => ({
|
|
156
152
|
path,
|
|
157
153
|
index,
|
|
158
|
-
}))
|
|
154
|
+
})),
|
|
155
|
+
})),
|
|
159
156
|
Antd: !!antd,
|
|
160
157
|
DefaultLocale: JSON.stringify(defaultLocale),
|
|
161
|
-
warningPkgPath: (0, plugin_utils_1.winPath)(require.resolve('warning/package')),
|
|
158
|
+
warningPkgPath: (0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('warning/package'))),
|
|
162
159
|
reactIntlPkgPath,
|
|
163
160
|
}),
|
|
164
161
|
});
|
|
@@ -178,25 +175,25 @@ exports.default = (api) => {
|
|
|
178
175
|
Antd: !!antd,
|
|
179
176
|
LocaleList: localeList,
|
|
180
177
|
ShowSelectLang: localeList.length > 1 && !!antd,
|
|
181
|
-
antdFiles: ((
|
|
178
|
+
antdFiles: ((_d = api.config) === null || _d === void 0 ? void 0 : _d.ssr) ? 'lib' : 'es',
|
|
182
179
|
}),
|
|
183
180
|
});
|
|
184
181
|
// index.ts
|
|
185
182
|
api.writeTmpFile({
|
|
186
183
|
path: 'index.ts',
|
|
187
184
|
content: `
|
|
188
|
-
export { useIntl, formatMessage, FormattedMessage } from './localeExports.ts';
|
|
185
|
+
export { setLocale, getLocale, useIntl, injectIntl, formatMessage, FormattedMessage } from './localeExports.ts';
|
|
189
186
|
export { SelectLang } from './SelectLang.tsx';
|
|
190
187
|
`,
|
|
191
188
|
});
|
|
192
|
-
})
|
|
189
|
+
});
|
|
193
190
|
// Runtime Plugin
|
|
194
191
|
api.addRuntimePlugin(() => [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })]);
|
|
195
192
|
api.addRuntimePluginKey(() => ['locale']);
|
|
196
193
|
// watch locale files
|
|
197
|
-
api.addTmpGenerateWatcherPaths(() =>
|
|
194
|
+
api.addTmpGenerateWatcherPaths(async () => {
|
|
198
195
|
const resolveKey = api.config.moment2dayjs ? 'dayjs' : 'moment';
|
|
199
|
-
const localeList =
|
|
196
|
+
const localeList = await getList(resolveKey);
|
|
200
197
|
return (0, localeUtils_1.exactLocalePaths)(localeList);
|
|
201
|
-
})
|
|
198
|
+
});
|
|
202
199
|
};
|
package/dist/model.js
CHANGED
|
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
26
|
const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
|
|
36
27
|
const fs_1 = require("fs");
|
|
@@ -49,17 +40,8 @@ exports.default = (api) => {
|
|
|
49
40
|
},
|
|
50
41
|
enableBy: api.EnableBy.config,
|
|
51
42
|
});
|
|
52
|
-
api.
|
|
53
|
-
const models =
|
|
54
|
-
memo.pluginModel = {
|
|
55
|
-
models,
|
|
56
|
-
};
|
|
57
|
-
return memo;
|
|
58
|
-
}));
|
|
59
|
-
api.onGenerateFiles((args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
|
-
const models = args.isFirstTime
|
|
61
|
-
? api.appData.pluginModel.models
|
|
62
|
-
: yield getAllModels(api);
|
|
43
|
+
api.onGenerateFiles(async () => {
|
|
44
|
+
const models = await getAllModels(api);
|
|
63
45
|
// model.ts
|
|
64
46
|
api.writeTmpFile({
|
|
65
47
|
path: 'model.ts',
|
|
@@ -94,7 +76,7 @@ export function dataflowProvider(container, opts) {
|
|
|
94
76
|
}
|
|
95
77
|
`,
|
|
96
78
|
});
|
|
97
|
-
})
|
|
79
|
+
});
|
|
98
80
|
api.addTmpGenerateWatcherPaths(() => {
|
|
99
81
|
return [(0, path_1.join)(api.paths.absSrcPath, 'models')];
|
|
100
82
|
});
|
|
@@ -102,19 +84,18 @@ export function dataflowProvider(container, opts) {
|
|
|
102
84
|
return [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })];
|
|
103
85
|
});
|
|
104
86
|
};
|
|
105
|
-
function getAllModels(api) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
});
|
|
87
|
+
async function getAllModels(api) {
|
|
88
|
+
const extraModels = await api.applyPlugins({
|
|
89
|
+
key: 'addExtraModels',
|
|
90
|
+
type: api.ApplyPluginsType.add,
|
|
91
|
+
initialValue: [],
|
|
92
|
+
});
|
|
93
|
+
return new modelUtils_1.ModelUtils(api, {
|
|
94
|
+
astTest({ node }) {
|
|
95
|
+
return t.isArrowFunctionExpression(node) || t.isFunctionDeclaration(node);
|
|
96
|
+
},
|
|
97
|
+
}).getAllModels({
|
|
98
|
+
sort: {},
|
|
99
|
+
extraModels: [...extraModels, ...(api.config.model.extraModels || [])],
|
|
119
100
|
});
|
|
120
101
|
}
|
package/dist/qiankun/master.js
CHANGED
|
@@ -23,22 +23,30 @@ exports.default = (api) => {
|
|
|
23
23
|
api.addRuntimePlugin(() => {
|
|
24
24
|
return [(0, withTmpPath_1.withTmpPath)({ api, path: 'masterRuntimePlugin.tsx' })];
|
|
25
25
|
});
|
|
26
|
-
api.modifyDefaultConfig((config) => (
|
|
27
|
-
|
|
26
|
+
api.modifyDefaultConfig((config) => ({
|
|
27
|
+
...config,
|
|
28
|
+
mountElementId: constants_1.defaultMasterRootId,
|
|
29
|
+
qiankun: {
|
|
30
|
+
...config.qiankun,
|
|
31
|
+
master: {
|
|
32
|
+
...JSON.parse(process.env.INITIAL_QIANKUN_MASTER_OPTIONS || '{}'),
|
|
33
|
+
...(config.qiankun || {}).master,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
}));
|
|
28
37
|
api.modifyRoutes((memo) => {
|
|
29
38
|
Object.keys(memo).forEach((id) => {
|
|
39
|
+
var _a;
|
|
30
40
|
const route = memo[id];
|
|
31
41
|
if (route.microApp) {
|
|
32
42
|
const appName = route.microApp;
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
// TODO: config masterHistoryType
|
|
36
|
-
const masterHistoryType = 'browser';
|
|
43
|
+
const base = api.config.base || '/';
|
|
44
|
+
const masterHistoryType = ((_a = api.config.history) === null || _a === void 0 ? void 0 : _a.type) || 'browser';
|
|
37
45
|
const routeProps = route.microAppProps || {};
|
|
38
46
|
const normalizedRouteProps = JSON.stringify(routeProps).replace(/"/g, "'");
|
|
39
47
|
route.file = `(async () => {
|
|
40
48
|
const { getMicroAppRouteComponent } = await import('@@/plugin-qiankun-master/getMicroAppRouteComponent');
|
|
41
|
-
return getMicroAppRouteComponent({ appName: '${appName}', base: '${base}', masterHistoryType: '${masterHistoryType}', routeProps: ${normalizedRouteProps} })
|
|
49
|
+
return getMicroAppRouteComponent({ appName: '${appName}', base: '${base}', routePath: '${route.path}', masterHistoryType: '${masterHistoryType}', routeProps: ${normalizedRouteProps} })
|
|
42
50
|
})()`;
|
|
43
51
|
}
|
|
44
52
|
});
|
|
@@ -65,7 +73,11 @@ exports.default = (api) => {
|
|
|
65
73
|
api.writeTmpFile({
|
|
66
74
|
path: 'masterOptions.ts',
|
|
67
75
|
content: `
|
|
68
|
-
let options = ${JSON.stringify(
|
|
76
|
+
let options = ${JSON.stringify({
|
|
77
|
+
masterHistoryType: ((_a = api.config.history) === null || _a === void 0 ? void 0 : _a.type) || constants_1.defaultHistoryType,
|
|
78
|
+
base: api.config.base || '/',
|
|
79
|
+
...api.config.qiankun.master,
|
|
80
|
+
})};
|
|
69
81
|
export const getMasterOptions = () => options;
|
|
70
82
|
export const setMasterOptions = (newOpts) => options = ({ ...options, ...newOpts });
|
|
71
83
|
`,
|
|
@@ -91,7 +103,6 @@ export const setMasterOptions = (newOpts) => options = ({ ...options, ...newOpts
|
|
|
91
103
|
path: file.replace(/\.tpl$/, ''),
|
|
92
104
|
tpl: getFileContent(file),
|
|
93
105
|
context: {
|
|
94
|
-
runtimeHistory: api.config.runtimeHistory,
|
|
95
106
|
dynamicRoot: false,
|
|
96
107
|
hasModelPlugin: api.isPluginEnable('model'),
|
|
97
108
|
// dynamicRoot:
|
|
@@ -100,16 +111,25 @@ export const setMasterOptions = (newOpts) => options = ({ ...options, ...newOpts
|
|
|
100
111
|
});
|
|
101
112
|
}
|
|
102
113
|
else {
|
|
114
|
+
let content = getFileContent(file);
|
|
115
|
+
if (!api.config.qiankun.externalQiankun) {
|
|
116
|
+
content = content.replace(/from 'qiankun'/g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('qiankun/package')))}'`);
|
|
117
|
+
}
|
|
103
118
|
api.writeTmpFile({
|
|
104
119
|
path: file.replace(/\.tpl$/, ''),
|
|
105
|
-
content:
|
|
120
|
+
content: content
|
|
106
121
|
.replace('__USE_MODEL__', api.isPluginEnable('model')
|
|
107
122
|
? `import { useModel } from '@@/plugin-model'`
|
|
108
123
|
: `const useModel = null;`)
|
|
109
|
-
.replace(/from 'qiankun'/g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('qiankun/package')))}'`)
|
|
110
124
|
.replace(/from 'lodash\//g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('lodash/package')))}/`),
|
|
111
125
|
});
|
|
112
126
|
}
|
|
113
127
|
});
|
|
128
|
+
api.writeTmpFile({
|
|
129
|
+
path: 'index.ts',
|
|
130
|
+
content: `
|
|
131
|
+
export { MicroApp } from './MicroApp';
|
|
132
|
+
`,
|
|
133
|
+
});
|
|
114
134
|
});
|
|
115
135
|
};
|
package/dist/qiankun/slave.js
CHANGED
|
@@ -30,20 +30,32 @@ exports.default = (api) => {
|
|
|
30
30
|
key: 'addExtraModels',
|
|
31
31
|
fn() {
|
|
32
32
|
return [
|
|
33
|
-
|
|
33
|
+
(0, withTmpPath_1.withTmpPath)({
|
|
34
|
+
api,
|
|
35
|
+
path: `qiankunModel.ts#{"namespace":"${constants_1.qiankunStateFromMasterModelNamespace}"}`,
|
|
36
|
+
}),
|
|
34
37
|
];
|
|
35
38
|
},
|
|
36
39
|
});
|
|
37
40
|
api.modifyDefaultConfig((memo) => {
|
|
38
|
-
var _a, _b, _c;
|
|
39
|
-
const initialSlaveOptions =
|
|
40
|
-
|
|
41
|
+
var _a, _b, _c, _d;
|
|
42
|
+
const initialSlaveOptions = {
|
|
43
|
+
devSourceMap: true,
|
|
44
|
+
...JSON.parse(process.env.INITIAL_QIANKUN_SLAVE_OPTIONS || '{}'),
|
|
45
|
+
...(memo.qiankun || {}).slave,
|
|
46
|
+
};
|
|
47
|
+
const modifiedDefaultConfig = {
|
|
48
|
+
...memo,
|
|
41
49
|
// 默认开启 runtimePublicPath,避免出现 dynamic import 场景子应用资源地址出问题
|
|
42
|
-
runtimePublicPath: true,
|
|
43
|
-
|
|
44
|
-
|
|
50
|
+
runtimePublicPath: true,
|
|
51
|
+
qiankun: {
|
|
52
|
+
...memo.qiankun,
|
|
53
|
+
slave: initialSlaveOptions,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
45
56
|
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;
|
|
46
|
-
|
|
57
|
+
const historyType = ((_d = api.userConfig.history) === null || _d === void 0 ? void 0 : _d.type) || 'browser';
|
|
58
|
+
if (!shouldNotModifyDefaultBase && historyType !== 'hash') {
|
|
47
59
|
// @ts-ignore
|
|
48
60
|
modifiedDefaultConfig.base = `/${api.pkg.name}`;
|
|
49
61
|
}
|
|
@@ -53,22 +65,23 @@ exports.default = (api) => {
|
|
|
53
65
|
var _a, _b;
|
|
54
66
|
// mfsu 场景默认给子应用增加 mfName 配置,从而避免冲突
|
|
55
67
|
if (config.mfsu !== false) {
|
|
56
|
-
config.mfsu =
|
|
57
|
-
|
|
68
|
+
config.mfsu = {
|
|
69
|
+
...config.mfsu,
|
|
70
|
+
mfName: ((_a = config.mfsu) === null || _a === void 0 ? void 0 : _a.mfName) ||
|
|
71
|
+
`mf_${(_b = api.pkg.name) === null || _b === void 0 ? void 0 : _b.replace(/^@/, '').replace(/\W/g, '_')}`,
|
|
72
|
+
};
|
|
58
73
|
}
|
|
59
74
|
return config;
|
|
60
75
|
});
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
// return publicPathStr;
|
|
71
|
-
// });
|
|
76
|
+
api.addHTMLHeadScripts(() => {
|
|
77
|
+
var _a, _b;
|
|
78
|
+
const dontModify = (_b = (_a = api.config.qiankun) === null || _a === void 0 ? void 0 : _a.slave) === null || _b === void 0 ? void 0 : _b.shouldNotModifyRuntimePublicPath;
|
|
79
|
+
return dontModify
|
|
80
|
+
? []
|
|
81
|
+
: [
|
|
82
|
+
`window.publicPath = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ || "${api.config.publicPath || '/'}";`,
|
|
83
|
+
];
|
|
84
|
+
});
|
|
72
85
|
api.chainWebpack((config) => {
|
|
73
86
|
(0, assert_1.default)(api.pkg.name, 'You should have name in package.json.');
|
|
74
87
|
const { shouldNotAddLibraryChunkName } = (api.config.qiankun || {}).slave;
|
|
@@ -113,30 +126,39 @@ if (!window.__POWERED_BY_QIANKUN__) {
|
|
|
113
126
|
function getFileContent(file) {
|
|
114
127
|
return (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../../libs/qiankun/slave', file), 'utf-8');
|
|
115
128
|
}
|
|
116
|
-
api.onGenerateFiles(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
129
|
+
api.onGenerateFiles({
|
|
130
|
+
fn() {
|
|
131
|
+
// api.writeTmpFile({
|
|
132
|
+
// path: 'slaveOptions.ts',
|
|
133
|
+
// content: `
|
|
134
|
+
// let options = ${JSON.stringify((api.config.qiankun || {}).slave || {})};
|
|
135
|
+
// export const getSlaveOptions = () => options;
|
|
136
|
+
// export const setSlaveOptions = (newOpts) => options = ({ ...options, ...newOpts });
|
|
137
|
+
// `,
|
|
138
|
+
// });
|
|
139
|
+
[
|
|
140
|
+
'qiankunModel.ts',
|
|
141
|
+
'connectMaster.tsx',
|
|
142
|
+
'slaveRuntimePlugin.ts',
|
|
143
|
+
'lifecycles.ts',
|
|
144
|
+
].forEach((file) => {
|
|
145
|
+
api.writeTmpFile({
|
|
146
|
+
path: file.replace(/\.tpl$/, ''),
|
|
147
|
+
content: getFileContent(file)
|
|
148
|
+
.replace('__USE_MODEL__', api.isPluginEnable('model')
|
|
149
|
+
? `import { useModel } from '@@/plugin-model'`
|
|
150
|
+
: `const useModel = null;`)
|
|
151
|
+
.replace(/from 'qiankun'/g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('qiankun/package')))}'`)
|
|
152
|
+
.replace(/from 'lodash\//g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('lodash/package')))}/`),
|
|
153
|
+
});
|
|
154
|
+
});
|
|
131
155
|
api.writeTmpFile({
|
|
132
|
-
path:
|
|
133
|
-
content:
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
: `const useModel = null;`)
|
|
137
|
-
.replace(/from 'qiankun'/g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('qiankun/package')))}'`)
|
|
138
|
-
.replace(/from 'lodash\//g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('lodash/package')))}/`),
|
|
156
|
+
path: 'index.ts',
|
|
157
|
+
content: `
|
|
158
|
+
export { connectMaster } from './connectMaster';
|
|
159
|
+
`,
|
|
139
160
|
});
|
|
140
|
-
}
|
|
161
|
+
},
|
|
162
|
+
before: 'model',
|
|
141
163
|
});
|
|
142
164
|
};
|