@umijs/plugins 4.0.0-rc.2 → 4.0.0-rc.20
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 +78 -16
- package/dist/antd.js +45 -12
- package/dist/dva.js +27 -2
- package/dist/initial-state.js +3 -3
- package/dist/layout.js +99 -28
- package/dist/locale.js +46 -50
- package/dist/model.js +21 -36
- package/dist/moment2dayjs.js +4 -4
- package/dist/qiankun/master.js +33 -12
- package/dist/qiankun/slave.js +67 -44
- package/dist/qiankun.js +1 -0
- package/dist/request.js +134 -127
- package/dist/tailwindcss.js +31 -29
- package/dist/unocss.js +15 -33
- package/dist/utils/astUtils.js +5 -1
- package/dist/utils/localeUtils.js +15 -24
- package/dist/utils/modelUtils.d.ts +5 -1
- package/dist/utils/modelUtils.js +93 -7
- package/dist/utils/withTmpPath.js +2 -2
- package/libs/locale/localeExports.tpl +6 -6
- package/libs/qiankun/master/MicroApp.tsx +7 -0
- 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/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 +15 -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 {
|
|
@@ -28,15 +18,15 @@ exports.default = (api) => {
|
|
|
28
18
|
catch (e) {
|
|
29
19
|
api.logger.warn('antd is not installed. <SelecLang /> unavailable');
|
|
30
20
|
}
|
|
21
|
+
const defaultConfig = {
|
|
22
|
+
baseNavigator: true,
|
|
23
|
+
useLocalStorage: true,
|
|
24
|
+
baseSeparator: '-',
|
|
25
|
+
antd: hasAntd,
|
|
26
|
+
};
|
|
31
27
|
api.describe({
|
|
32
28
|
key: 'locale',
|
|
33
29
|
config: {
|
|
34
|
-
default: {
|
|
35
|
-
baseNavigator: true,
|
|
36
|
-
useLocalStorage: true,
|
|
37
|
-
baseSeparator: '-',
|
|
38
|
-
antd: hasAntd,
|
|
39
|
-
},
|
|
40
30
|
schema(joi) {
|
|
41
31
|
return joi.object({
|
|
42
32
|
default: joi.string(),
|
|
@@ -52,47 +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
|
-
|
|
95
|
-
|
|
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);
|
|
96
88
|
const momentLocales = localeList
|
|
97
89
|
.map(({ momentLocale }) => momentLocale)
|
|
98
90
|
.filter((locale) => locale);
|
|
@@ -102,7 +94,7 @@ exports.default = (api) => {
|
|
|
102
94
|
let MomentLocales = momentLocales;
|
|
103
95
|
let DefaultMomentLocale = '';
|
|
104
96
|
// set moment default accounding to locale.default
|
|
105
|
-
if (!MomentLocales.length && ((
|
|
97
|
+
if (!MomentLocales.length && ((_b = api.config.locale) === null || _b === void 0 ? void 0 : _b.default)) {
|
|
106
98
|
const [lang, country = ''] = defaultLocale.split(baseSeparator);
|
|
107
99
|
const { momentLocale } = (0, localeUtils_1.getMomentLocale)(lang, country, resolveKey);
|
|
108
100
|
if (momentLocale) {
|
|
@@ -112,9 +104,9 @@ exports.default = (api) => {
|
|
|
112
104
|
}
|
|
113
105
|
let DefaultAntdLocales = [];
|
|
114
106
|
// set antd default locale
|
|
115
|
-
if (!antdLocales.length && ((
|
|
107
|
+
if (!antdLocales.length && ((_c = api.config.locale) === null || _c === void 0 ? void 0 : _c.antd)) {
|
|
116
108
|
const [lang, country = ''] = defaultLocale.split(baseSeparator);
|
|
117
|
-
DefaultAntdLocales = plugin_utils_1.lodash.uniq(
|
|
109
|
+
DefaultAntdLocales = plugin_utils_1.lodash.uniq(await addAntdLocales({
|
|
118
110
|
lang,
|
|
119
111
|
country,
|
|
120
112
|
}));
|
|
@@ -139,7 +131,7 @@ exports.default = (api) => {
|
|
|
139
131
|
path: 'locale.tsx',
|
|
140
132
|
});
|
|
141
133
|
const localeExportsTpl = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../libs/locale/localeExports.tpl'), 'utf-8');
|
|
142
|
-
const localeDirName =
|
|
134
|
+
const localeDirName = 'locales';
|
|
143
135
|
const localeDirPath = (0, path_1.join)(api.paths.absSrcPath, localeDirName);
|
|
144
136
|
api.writeTmpFile({
|
|
145
137
|
path: 'localeExports.ts',
|
|
@@ -150,16 +142,20 @@ exports.default = (api) => {
|
|
|
150
142
|
UseLocalStorage: !!useLocalStorage,
|
|
151
143
|
LocaleDir: localeDirName,
|
|
152
144
|
ExistLocaleDir: (0, fs_1.existsSync)(localeDirPath),
|
|
153
|
-
LocaleList: localeList.map((locale) => (
|
|
145
|
+
LocaleList: localeList.map((locale) => ({
|
|
146
|
+
...locale,
|
|
147
|
+
antdLocale: locale.antdLocale.map((antdLocale, index) => ({
|
|
154
148
|
locale: antdLocale,
|
|
155
149
|
index: index,
|
|
156
|
-
})),
|
|
150
|
+
})),
|
|
151
|
+
paths: locale.paths.map((path, index) => ({
|
|
157
152
|
path,
|
|
158
153
|
index,
|
|
159
|
-
}))
|
|
154
|
+
})),
|
|
155
|
+
})),
|
|
160
156
|
Antd: !!antd,
|
|
161
157
|
DefaultLocale: JSON.stringify(defaultLocale),
|
|
162
|
-
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'))),
|
|
163
159
|
reactIntlPkgPath,
|
|
164
160
|
}),
|
|
165
161
|
});
|
|
@@ -179,25 +175,25 @@ exports.default = (api) => {
|
|
|
179
175
|
Antd: !!antd,
|
|
180
176
|
LocaleList: localeList,
|
|
181
177
|
ShowSelectLang: localeList.length > 1 && !!antd,
|
|
182
|
-
antdFiles: ((
|
|
178
|
+
antdFiles: ((_d = api.config) === null || _d === void 0 ? void 0 : _d.ssr) ? 'lib' : 'es',
|
|
183
179
|
}),
|
|
184
180
|
});
|
|
185
181
|
// index.ts
|
|
186
182
|
api.writeTmpFile({
|
|
187
183
|
path: 'index.ts',
|
|
188
184
|
content: `
|
|
189
|
-
export { useIntl, formatMessage, FormattedMessage } from './localeExports.ts';
|
|
185
|
+
export { setLocale, getLocale, useIntl, injectIntl, formatMessage, FormattedMessage } from './localeExports.ts';
|
|
190
186
|
export { SelectLang } from './SelectLang.tsx';
|
|
191
187
|
`,
|
|
192
188
|
});
|
|
193
|
-
})
|
|
189
|
+
});
|
|
194
190
|
// Runtime Plugin
|
|
195
191
|
api.addRuntimePlugin(() => [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })]);
|
|
196
192
|
api.addRuntimePluginKey(() => ['locale']);
|
|
197
193
|
// watch locale files
|
|
198
|
-
api.addTmpGenerateWatcherPaths(() =>
|
|
194
|
+
api.addTmpGenerateWatcherPaths(async () => {
|
|
199
195
|
const resolveKey = api.config.moment2dayjs ? 'dayjs' : 'moment';
|
|
200
|
-
const localeList =
|
|
196
|
+
const localeList = await getList(resolveKey);
|
|
201
197
|
return (0, localeUtils_1.exactLocalePaths)(localeList);
|
|
202
|
-
})
|
|
198
|
+
});
|
|
203
199
|
};
|
package/dist/model.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -18,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
18
22
|
__setModuleDefault(result, mod);
|
|
19
23
|
return result;
|
|
20
24
|
};
|
|
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
|
-
});
|
|
29
|
-
};
|
|
30
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
26
|
const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
|
|
32
27
|
const fs_1 = require("fs");
|
|
@@ -45,17 +40,8 @@ exports.default = (api) => {
|
|
|
45
40
|
},
|
|
46
41
|
enableBy: api.EnableBy.config,
|
|
47
42
|
});
|
|
48
|
-
api.
|
|
49
|
-
const models =
|
|
50
|
-
memo.pluginModel = {
|
|
51
|
-
models,
|
|
52
|
-
};
|
|
53
|
-
return memo;
|
|
54
|
-
}));
|
|
55
|
-
api.onGenerateFiles((args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
-
const models = args.isFirstTime
|
|
57
|
-
? api.appData.pluginModel.models
|
|
58
|
-
: yield getAllModels(api);
|
|
43
|
+
api.onGenerateFiles(async () => {
|
|
44
|
+
const models = await getAllModels(api);
|
|
59
45
|
// model.ts
|
|
60
46
|
api.writeTmpFile({
|
|
61
47
|
path: 'model.ts',
|
|
@@ -90,7 +76,7 @@ export function dataflowProvider(container, opts) {
|
|
|
90
76
|
}
|
|
91
77
|
`,
|
|
92
78
|
});
|
|
93
|
-
})
|
|
79
|
+
});
|
|
94
80
|
api.addTmpGenerateWatcherPaths(() => {
|
|
95
81
|
return [(0, path_1.join)(api.paths.absSrcPath, 'models')];
|
|
96
82
|
});
|
|
@@ -98,19 +84,18 @@ export function dataflowProvider(container, opts) {
|
|
|
98
84
|
return [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })];
|
|
99
85
|
});
|
|
100
86
|
};
|
|
101
|
-
function getAllModels(api) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
});
|
|
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 || [])],
|
|
115
100
|
});
|
|
116
101
|
}
|
package/dist/moment2dayjs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const utils_1 = require("@umijs/utils");
|
|
4
3
|
const path_1 = require("path");
|
|
4
|
+
const plugin_utils_1 = require("umi/plugin-utils");
|
|
5
5
|
/*
|
|
6
6
|
As long as moment2dayjs is registered, moment will be replaced by dayjs.
|
|
7
7
|
The presets that can adapt to antd is registered by default.
|
|
@@ -81,11 +81,11 @@ dayjs.extend({{.}});
|
|
|
81
81
|
|
|
82
82
|
dayjs.extend(antdPlugin);
|
|
83
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'));
|
|
84
|
+
const dayjsAntdPluginPath = (0, plugin_utils_1.winPath)(require.resolve('antd-dayjs-webpack-plugin/src/antd-plugin'));
|
|
85
|
+
const dayjsPath = (0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('dayjs/package.json')));
|
|
86
86
|
api.writeTmpFile({
|
|
87
87
|
path: 'runtime.tsx',
|
|
88
|
-
content:
|
|
88
|
+
content: plugin_utils_1.Mustache.render(runtimeTpl, {
|
|
89
89
|
plugins,
|
|
90
90
|
dayjsPath,
|
|
91
91
|
dayjsAntdPluginPath,
|
package/dist/qiankun/master.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isMasterEnable = void 0;
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
5
|
const path_1 = require("path");
|
|
6
|
+
const plugin_utils_1 = require("umi/plugin-utils");
|
|
6
7
|
const withTmpPath_1 = require("../utils/withTmpPath");
|
|
7
8
|
const constants_1 = require("./constants");
|
|
8
9
|
function isMasterEnable(opts) {
|
|
@@ -22,22 +23,30 @@ exports.default = (api) => {
|
|
|
22
23
|
api.addRuntimePlugin(() => {
|
|
23
24
|
return [(0, withTmpPath_1.withTmpPath)({ api, path: 'masterRuntimePlugin.tsx' })];
|
|
24
25
|
});
|
|
25
|
-
api.modifyDefaultConfig((config) => (
|
|
26
|
-
|
|
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
|
+
}));
|
|
27
37
|
api.modifyRoutes((memo) => {
|
|
28
38
|
Object.keys(memo).forEach((id) => {
|
|
39
|
+
var _a;
|
|
29
40
|
const route = memo[id];
|
|
30
41
|
if (route.microApp) {
|
|
31
42
|
const appName = route.microApp;
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
// TODO: config masterHistoryType
|
|
35
|
-
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';
|
|
36
45
|
const routeProps = route.microAppProps || {};
|
|
37
46
|
const normalizedRouteProps = JSON.stringify(routeProps).replace(/"/g, "'");
|
|
38
47
|
route.file = `(async () => {
|
|
39
48
|
const { getMicroAppRouteComponent } = await import('@@/plugin-qiankun-master/getMicroAppRouteComponent');
|
|
40
|
-
return getMicroAppRouteComponent({ appName: '${appName}', base: '${base}', masterHistoryType: '${masterHistoryType}', routeProps: ${normalizedRouteProps} })
|
|
49
|
+
return getMicroAppRouteComponent({ appName: '${appName}', base: '${base}', routePath: '${route.path}', masterHistoryType: '${masterHistoryType}', routeProps: ${normalizedRouteProps} })
|
|
41
50
|
})()`;
|
|
42
51
|
}
|
|
43
52
|
});
|
|
@@ -64,7 +73,11 @@ exports.default = (api) => {
|
|
|
64
73
|
api.writeTmpFile({
|
|
65
74
|
path: 'masterOptions.ts',
|
|
66
75
|
content: `
|
|
67
|
-
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
|
+
})};
|
|
68
81
|
export const getMasterOptions = () => options;
|
|
69
82
|
export const setMasterOptions = (newOpts) => options = ({ ...options, ...newOpts });
|
|
70
83
|
`,
|
|
@@ -90,7 +103,6 @@ export const setMasterOptions = (newOpts) => options = ({ ...options, ...newOpts
|
|
|
90
103
|
path: file.replace(/\.tpl$/, ''),
|
|
91
104
|
tpl: getFileContent(file),
|
|
92
105
|
context: {
|
|
93
|
-
runtimeHistory: api.config.runtimeHistory,
|
|
94
106
|
dynamicRoot: false,
|
|
95
107
|
hasModelPlugin: api.isPluginEnable('model'),
|
|
96
108
|
// dynamicRoot:
|
|
@@ -99,16 +111,25 @@ export const setMasterOptions = (newOpts) => options = ({ ...options, ...newOpts
|
|
|
99
111
|
});
|
|
100
112
|
}
|
|
101
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
|
+
}
|
|
102
118
|
api.writeTmpFile({
|
|
103
119
|
path: file.replace(/\.tpl$/, ''),
|
|
104
|
-
content:
|
|
120
|
+
content: content
|
|
105
121
|
.replace('__USE_MODEL__', api.isPluginEnable('model')
|
|
106
122
|
? `import { useModel } from '@@/plugin-model'`
|
|
107
123
|
: `const useModel = null;`)
|
|
108
|
-
.replace(/from '
|
|
109
|
-
.replace(/from 'lodash\//g, `from '${(0, path_1.dirname)(require.resolve('lodash/package'))}/`),
|
|
124
|
+
.replace(/from 'lodash\//g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('lodash/package')))}/`),
|
|
110
125
|
});
|
|
111
126
|
}
|
|
112
127
|
});
|
|
128
|
+
api.writeTmpFile({
|
|
129
|
+
path: 'index.ts',
|
|
130
|
+
content: `
|
|
131
|
+
export { MicroApp } from './MicroApp';
|
|
132
|
+
`,
|
|
133
|
+
});
|
|
113
134
|
});
|
|
114
135
|
};
|
package/dist/qiankun/slave.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const assert_1 = __importDefault(require("assert"));
|
|
7
7
|
const fs_1 = require("fs");
|
|
8
8
|
const path_1 = require("path");
|
|
9
|
+
const plugin_utils_1 = require("umi/plugin-utils");
|
|
9
10
|
const withTmpPath_1 = require("../utils/withTmpPath");
|
|
10
11
|
const constants_1 = require("./constants");
|
|
11
12
|
// BREAK CHANGE: 需要手动配置 slave: {},不能留空
|
|
@@ -29,20 +30,32 @@ exports.default = (api) => {
|
|
|
29
30
|
key: 'addExtraModels',
|
|
30
31
|
fn() {
|
|
31
32
|
return [
|
|
32
|
-
|
|
33
|
+
(0, withTmpPath_1.withTmpPath)({
|
|
34
|
+
api,
|
|
35
|
+
path: `qiankunModel.ts#{"namespace":"${constants_1.qiankunStateFromMasterModelNamespace}"}`,
|
|
36
|
+
}),
|
|
33
37
|
];
|
|
34
38
|
},
|
|
35
39
|
});
|
|
36
40
|
api.modifyDefaultConfig((memo) => {
|
|
37
|
-
var _a, _b, _c;
|
|
38
|
-
const initialSlaveOptions =
|
|
39
|
-
|
|
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,
|
|
40
49
|
// 默认开启 runtimePublicPath,避免出现 dynamic import 场景子应用资源地址出问题
|
|
41
|
-
runtimePublicPath: true,
|
|
42
|
-
|
|
43
|
-
|
|
50
|
+
runtimePublicPath: true,
|
|
51
|
+
qiankun: {
|
|
52
|
+
...memo.qiankun,
|
|
53
|
+
slave: initialSlaveOptions,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
44
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;
|
|
45
|
-
|
|
57
|
+
const historyType = ((_d = api.userConfig.history) === null || _d === void 0 ? void 0 : _d.type) || 'browser';
|
|
58
|
+
if (!shouldNotModifyDefaultBase && historyType !== 'hash') {
|
|
46
59
|
// @ts-ignore
|
|
47
60
|
modifiedDefaultConfig.base = `/${api.pkg.name}`;
|
|
48
61
|
}
|
|
@@ -52,22 +65,23 @@ exports.default = (api) => {
|
|
|
52
65
|
var _a, _b;
|
|
53
66
|
// mfsu 场景默认给子应用增加 mfName 配置,从而避免冲突
|
|
54
67
|
if (config.mfsu !== false) {
|
|
55
|
-
config.mfsu =
|
|
56
|
-
|
|
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
|
+
};
|
|
57
73
|
}
|
|
58
74
|
return config;
|
|
59
75
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
// return publicPathStr;
|
|
70
|
-
// });
|
|
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
|
+
});
|
|
71
85
|
api.chainWebpack((config) => {
|
|
72
86
|
(0, assert_1.default)(api.pkg.name, 'You should have name in package.json.');
|
|
73
87
|
const { shouldNotAddLibraryChunkName } = (api.config.qiankun || {}).slave;
|
|
@@ -112,30 +126,39 @@ if (!window.__POWERED_BY_QIANKUN__) {
|
|
|
112
126
|
function getFileContent(file) {
|
|
113
127
|
return (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../../libs/qiankun/slave', file), 'utf-8');
|
|
114
128
|
}
|
|
115
|
-
api.onGenerateFiles(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
+
});
|
|
130
155
|
api.writeTmpFile({
|
|
131
|
-
path:
|
|
132
|
-
content:
|
|
133
|
-
|
|
134
|
-
|
|
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'))}/`),
|
|
156
|
+
path: 'index.ts',
|
|
157
|
+
content: `
|
|
158
|
+
export { connectMaster } from './connectMaster';
|
|
159
|
+
`,
|
|
138
160
|
});
|
|
139
|
-
}
|
|
161
|
+
},
|
|
162
|
+
before: 'model',
|
|
140
163
|
});
|
|
141
164
|
};
|