@modern-js/plugin-garfish 2.15.0 → 2.16.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/CHANGELOG.md +15 -0
- package/dist/cjs/cli/index.js +224 -236
- package/dist/cjs/cli/utils.js +24 -48
- package/dist/cjs/deps/index.js +12 -35
- package/dist/cjs/index.js +26 -36
- package/dist/cjs/runtime/index.js +24 -44
- package/dist/cjs/runtime/loadable.js +46 -58
- package/dist/cjs/runtime/plugin.js +86 -82
- package/dist/cjs/runtime/useModuleApps.js +70 -56
- package/dist/cjs/runtime/utils/Context.js +18 -36
- package/dist/cjs/runtime/utils/MApp.js +88 -87
- package/dist/cjs/runtime/utils/apps.js +114 -94
- package/dist/cjs/runtime/utils/setExternal.js +23 -41
- package/dist/cjs/util.js +21 -40
- package/dist/esm/cli/index.js +409 -402
- package/dist/esm/cli/utils.js +25 -26
- package/dist/esm/deps/index.js +1 -2
- package/dist/esm/index.js +1 -2
- package/dist/esm/runtime/index.js +3 -4
- package/dist/esm/runtime/loadable.js +226 -210
- package/dist/esm/runtime/plugin.js +456 -426
- package/dist/esm/runtime/useModuleApps.js +49 -50
- package/dist/esm/runtime/utils/Context.js +1 -1
- package/dist/esm/runtime/utils/MApp.js +337 -316
- package/dist/esm/runtime/utils/apps.js +468 -442
- package/dist/esm/runtime/utils/setExternal.js +9 -9
- package/dist/esm/util.js +4 -5
- package/dist/esm-node/cli/index.js +209 -219
- package/dist/esm-node/cli/utils.js +15 -30
- package/dist/esm-node/deps/index.js +1 -4
- package/dist/esm-node/index.js +1 -4
- package/dist/esm-node/runtime/index.js +3 -10
- package/dist/esm-node/runtime/loadable.js +34 -31
- package/dist/esm-node/runtime/plugin.js +50 -33
- package/dist/esm-node/runtime/useModuleApps.js +12 -19
- package/dist/esm-node/runtime/utils/Context.js +2 -5
- package/dist/esm-node/runtime/utils/MApp.js +61 -40
- package/dist/esm-node/runtime/utils/apps.js +38 -44
- package/dist/esm-node/runtime/utils/setExternal.js +5 -5
- package/dist/esm-node/util.js +4 -9
- package/package.json +15 -11
|
@@ -2,12 +2,12 @@ import React from "react";
|
|
|
2
2
|
import ReactDOM from "react-dom";
|
|
3
3
|
import garfish from "garfish";
|
|
4
4
|
import { logger } from "../../util";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
5
|
+
export default function() {
|
|
6
|
+
logger("setExternal ", {
|
|
7
|
+
react: React,
|
|
8
|
+
"react-dom": ReactDOM
|
|
9
|
+
});
|
|
10
|
+
garfish.setExternal("react", React);
|
|
11
|
+
garfish.setExternal("react-dom", ReactDOM);
|
|
12
|
+
}
|
|
13
|
+
;
|
package/dist/esm/util.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import createDebug from "debug";
|
|
2
|
-
var logger = createDebug("modern-js:plugin-garfish");
|
|
3
|
-
var SUBMODULE_APP_COMPONENT_KEY = "SubModuleComponent";
|
|
4
|
-
function generateSubAppContainerKey(moduleInfo) {
|
|
5
|
-
|
|
2
|
+
export var logger = createDebug("modern-js:plugin-garfish");
|
|
3
|
+
export var SUBMODULE_APP_COMPONENT_KEY = "SubModuleComponent";
|
|
4
|
+
export function generateSubAppContainerKey(moduleInfo) {
|
|
5
|
+
return moduleInfo ? "modern_sub_app_container_".concat(decodeURIComponent(moduleInfo === null || moduleInfo === void 0 ? void 0 : moduleInfo.name)) : "modern_sub_app_container";
|
|
6
6
|
}
|
|
7
|
-
export { SUBMODULE_APP_COMPONENT_KEY, generateSubAppContainerKey, logger };
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { createRuntimeExportsUtils, PLUGIN_SCHEMAS } from "@modern-js/utils";
|
|
2
2
|
import { logger } from "../util";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from "./utils";
|
|
10
|
-
const externals = { "react-dom": "react-dom", react: "react" };
|
|
11
|
-
function getDefaultMicroFrontedConfig(microFrontend) {
|
|
3
|
+
import { getRuntimeConfig, makeProvider, makeRenderFunction, setRuntimeConfig, generateAsyncEntry } from "./utils";
|
|
4
|
+
export const externals = {
|
|
5
|
+
"react-dom": "react-dom",
|
|
6
|
+
react: "react"
|
|
7
|
+
};
|
|
8
|
+
export function getDefaultMicroFrontedConfig(microFrontend) {
|
|
12
9
|
if (microFrontend === true) {
|
|
13
10
|
return {
|
|
14
11
|
enableHtmlEntry: true,
|
|
@@ -22,244 +19,237 @@ function getDefaultMicroFrontedConfig(microFrontend) {
|
|
|
22
19
|
...microFrontend
|
|
23
20
|
};
|
|
24
21
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
22
|
+
export default ({ pluginName = "@modern-js/plugin-garfish", runtimePluginName = "@modern-js/runtime/plugins" } = {}) => {
|
|
23
|
+
return {
|
|
24
|
+
name: "@modern-js/plugin-garfish",
|
|
25
|
+
setup: ({ useAppContext, useResolvedConfigContext, useConfigContext }) => {
|
|
26
|
+
let pluginsExportsUtils;
|
|
27
|
+
return {
|
|
28
|
+
validateSchema() {
|
|
29
|
+
return PLUGIN_SCHEMAS["@modern-js/plugin-garfish"];
|
|
30
|
+
},
|
|
31
|
+
resolvedConfig: async (config) => {
|
|
32
|
+
const { resolved } = config;
|
|
33
|
+
const { masterApp, router } = getRuntimeConfig(resolved);
|
|
34
|
+
const nConfig = {
|
|
35
|
+
resolved: {
|
|
36
|
+
...resolved
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
if (masterApp) {
|
|
40
|
+
var _useConfig_server, _router_historyOptions;
|
|
41
|
+
const useConfig = useConfigContext();
|
|
42
|
+
const baseUrl = useConfig === null || useConfig === void 0 ? void 0 : (_useConfig_server = useConfig.server) === null || _useConfig_server === void 0 ? void 0 : _useConfig_server.baseUrl;
|
|
43
|
+
if (Array.isArray(baseUrl)) {
|
|
44
|
+
throw new Error("Now Micro-Front-End mode dose not support multiple baseUrl, you can set it as a string");
|
|
45
|
+
}
|
|
46
|
+
setRuntimeConfig(nConfig.resolved, "masterApp", Object.assign(typeof masterApp === "object" ? {
|
|
47
|
+
...masterApp
|
|
48
|
+
} : {}, {
|
|
49
|
+
basename: baseUrl || (router === null || router === void 0 ? void 0 : (_router_historyOptions = router.historyOptions) === null || _router_historyOptions === void 0 ? void 0 : _router_historyOptions.basename) || (router === null || router === void 0 ? void 0 : router.basename) || "/"
|
|
50
|
+
}));
|
|
43
51
|
}
|
|
44
|
-
|
|
45
|
-
|
|
52
|
+
logger(`resolvedConfig`, {
|
|
53
|
+
output: nConfig.resolved.output,
|
|
54
|
+
runtime: nConfig.resolved.runtime,
|
|
55
|
+
deploy: nConfig.resolved.deploy,
|
|
56
|
+
server: nConfig.resolved.server
|
|
57
|
+
});
|
|
58
|
+
return nConfig;
|
|
59
|
+
},
|
|
60
|
+
config() {
|
|
61
|
+
var _useConfig_output, _useConfig_deploy;
|
|
46
62
|
const useConfig = useConfigContext();
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
Object.assign(
|
|
57
|
-
typeof masterApp === "object" ? { ...masterApp } : {},
|
|
58
|
-
{
|
|
59
|
-
basename: baseUrl || ((_b = router == null ? void 0 : router.historyOptions) == null ? void 0 : _b.basename) || (router == null ? void 0 : router.basename) || "/"
|
|
60
|
-
}
|
|
61
|
-
)
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
logger(`resolvedConfig`, {
|
|
65
|
-
output: nConfig.resolved.output,
|
|
66
|
-
runtime: nConfig.resolved.runtime,
|
|
67
|
-
deploy: nConfig.resolved.deploy,
|
|
68
|
-
server: nConfig.resolved.server
|
|
69
|
-
});
|
|
70
|
-
return nConfig;
|
|
71
|
-
},
|
|
72
|
-
config() {
|
|
73
|
-
var _a, _b, _c;
|
|
74
|
-
const useConfig = useConfigContext();
|
|
75
|
-
logger("useConfig", useConfig);
|
|
76
|
-
const config = useAppContext();
|
|
77
|
-
pluginsExportsUtils = createRuntimeExportsUtils(
|
|
78
|
-
config.internalDirectory,
|
|
79
|
-
"plugins"
|
|
80
|
-
);
|
|
81
|
-
let disableCssExtract = ((_a = useConfig.output) == null ? void 0 : _a.disableCssExtract) || false;
|
|
82
|
-
if ((_b = useConfig.deploy) == null ? void 0 : _b.microFrontend) {
|
|
83
|
-
const { enableHtmlEntry } = getDefaultMicroFrontedConfig(
|
|
84
|
-
(_c = useConfig.deploy) == null ? void 0 : _c.microFrontend
|
|
85
|
-
);
|
|
86
|
-
if (!enableHtmlEntry) {
|
|
87
|
-
disableCssExtract = true;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return {
|
|
91
|
-
output: {
|
|
92
|
-
disableCssExtract
|
|
93
|
-
},
|
|
94
|
-
source: {
|
|
95
|
-
alias: {
|
|
96
|
-
"@modern-js/runtime/plugins": pluginsExportsUtils.getPath(),
|
|
97
|
-
"@modern-js/runtime/garfish": "@modern-js/plugin-garfish/runtime"
|
|
63
|
+
logger("useConfig", useConfig);
|
|
64
|
+
const config = useAppContext();
|
|
65
|
+
pluginsExportsUtils = createRuntimeExportsUtils(config.internalDirectory, "plugins");
|
|
66
|
+
let disableCssExtract = ((_useConfig_output = useConfig.output) === null || _useConfig_output === void 0 ? void 0 : _useConfig_output.disableCssExtract) || false;
|
|
67
|
+
if ((_useConfig_deploy = useConfig.deploy) === null || _useConfig_deploy === void 0 ? void 0 : _useConfig_deploy.microFrontend) {
|
|
68
|
+
var _useConfig_deploy1;
|
|
69
|
+
const { enableHtmlEntry } = getDefaultMicroFrontedConfig((_useConfig_deploy1 = useConfig.deploy) === null || _useConfig_deploy1 === void 0 ? void 0 : _useConfig_deploy1.microFrontend);
|
|
70
|
+
if (!enableHtmlEntry) {
|
|
71
|
+
disableCssExtract = true;
|
|
98
72
|
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
output: {
|
|
76
|
+
disableCssExtract
|
|
77
|
+
},
|
|
78
|
+
source: {
|
|
79
|
+
alias: {
|
|
80
|
+
"@modern-js/runtime/plugins": pluginsExportsUtils.getPath(),
|
|
81
|
+
"@modern-js/runtime/garfish": "@modern-js/plugin-garfish/runtime"
|
|
104
82
|
}
|
|
105
83
|
},
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
chain.output.libraryTarget("umd");
|
|
111
|
-
if (!((_b2 = useConfig.dev) == null ? void 0 : _b2.assetPrefix) && ((_c2 = resolveOptions == null ? void 0 : resolveOptions.server) == null ? void 0 : _c2.port) && env === "development") {
|
|
112
|
-
chain.output.publicPath(
|
|
113
|
-
`//localhost:${resolveOptions.server.port}/`
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
if (webpack.BannerPlugin) {
|
|
117
|
-
chain.plugin(CHAIN_ID.PLUGIN.BANNER).use(webpack.BannerPlugin, [{ banner: "Micro front-end" }]);
|
|
118
|
-
}
|
|
119
|
-
const { enableHtmlEntry, externalBasicLibrary } = getDefaultMicroFrontedConfig(
|
|
120
|
-
(_d = resolveOptions.deploy) == null ? void 0 : _d.microFrontend
|
|
121
|
-
);
|
|
122
|
-
if (externalBasicLibrary) {
|
|
123
|
-
chain.externals(externals);
|
|
84
|
+
tools: {
|
|
85
|
+
devServer: {
|
|
86
|
+
headers: {
|
|
87
|
+
"Access-Control-Allow-Origin": "*"
|
|
124
88
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
89
|
+
},
|
|
90
|
+
webpackChain: (chain, { webpack, env, CHAIN_ID }) => {
|
|
91
|
+
var _resolveOptions_deploy, _resolveWebpackConfig_resolve;
|
|
92
|
+
const resolveOptions = useResolvedConfigContext();
|
|
93
|
+
if (resolveOptions === null || resolveOptions === void 0 ? void 0 : (_resolveOptions_deploy = resolveOptions.deploy) === null || _resolveOptions_deploy === void 0 ? void 0 : _resolveOptions_deploy.microFrontend) {
|
|
94
|
+
var _useConfig_dev, _resolveOptions_server, _resolveOptions_deploy1;
|
|
95
|
+
chain.output.libraryTarget("umd");
|
|
96
|
+
if (!((_useConfig_dev = useConfig.dev) === null || _useConfig_dev === void 0 ? void 0 : _useConfig_dev.assetPrefix) && (resolveOptions === null || resolveOptions === void 0 ? void 0 : (_resolveOptions_server = resolveOptions.server) === null || _resolveOptions_server === void 0 ? void 0 : _resolveOptions_server.port) && env === "development") {
|
|
97
|
+
chain.output.publicPath(`//localhost:${resolveOptions.server.port}/`);
|
|
98
|
+
}
|
|
99
|
+
if (webpack.BannerPlugin) {
|
|
100
|
+
chain.plugin(CHAIN_ID.PLUGIN.BANNER).use(webpack.BannerPlugin, [
|
|
101
|
+
{
|
|
102
|
+
banner: "Micro front-end"
|
|
103
|
+
}
|
|
104
|
+
]);
|
|
105
|
+
}
|
|
106
|
+
const { enableHtmlEntry, externalBasicLibrary } = getDefaultMicroFrontedConfig((_resolveOptions_deploy1 = resolveOptions.deploy) === null || _resolveOptions_deploy1 === void 0 ? void 0 : _resolveOptions_deploy1.microFrontend);
|
|
107
|
+
if (externalBasicLibrary) {
|
|
108
|
+
chain.externals(externals);
|
|
109
|
+
}
|
|
110
|
+
if (!enableHtmlEntry) {
|
|
111
|
+
chain.output.filename("index.js");
|
|
112
|
+
chain.plugins.delete(`${CHAIN_ID.PLUGIN.HTML}-main`);
|
|
113
|
+
chain.optimization.runtimeChunk(false);
|
|
114
|
+
chain.optimization.splitChunks({
|
|
115
|
+
chunks: "async"
|
|
116
|
+
});
|
|
117
|
+
}
|
|
132
118
|
}
|
|
119
|
+
const resolveWebpackConfig = chain.toConfig();
|
|
120
|
+
logger("webpackConfig", {
|
|
121
|
+
output: resolveWebpackConfig.output,
|
|
122
|
+
externals: resolveWebpackConfig.externals,
|
|
123
|
+
env,
|
|
124
|
+
alias: (_resolveWebpackConfig_resolve = resolveWebpackConfig.resolve) === null || _resolveWebpackConfig_resolve === void 0 ? void 0 : _resolveWebpackConfig_resolve.alias,
|
|
125
|
+
plugins: resolveWebpackConfig.plugins
|
|
126
|
+
});
|
|
133
127
|
}
|
|
134
|
-
const resolveWebpackConfig = chain.toConfig();
|
|
135
|
-
logger("webpackConfig", {
|
|
136
|
-
output: resolveWebpackConfig.output,
|
|
137
|
-
externals: resolveWebpackConfig.externals,
|
|
138
|
-
env,
|
|
139
|
-
alias: (_e = resolveWebpackConfig.resolve) == null ? void 0 : _e.alias,
|
|
140
|
-
plugins: resolveWebpackConfig.plugins
|
|
141
|
-
});
|
|
142
128
|
}
|
|
129
|
+
};
|
|
130
|
+
},
|
|
131
|
+
addRuntimeExports() {
|
|
132
|
+
const config = useResolvedConfigContext();
|
|
133
|
+
const { masterApp } = getRuntimeConfig(config);
|
|
134
|
+
if (masterApp) {
|
|
135
|
+
const addExportStatement = `export { default as garfish, default as masterApp } from '${pluginName}/runtime'`;
|
|
136
|
+
logger("exportStatement", addExportStatement);
|
|
137
|
+
pluginsExportsUtils.addExport(addExportStatement);
|
|
138
|
+
}
|
|
139
|
+
const otherExportStatement = `export { hoistNonReactStatics } from '${pluginName}/deps'`;
|
|
140
|
+
logger("otherExportStatement", otherExportStatement);
|
|
141
|
+
pluginsExportsUtils.addExport(otherExportStatement);
|
|
142
|
+
},
|
|
143
|
+
modifyEntryImports({ entrypoint, imports }) {
|
|
144
|
+
const config = useResolvedConfigContext();
|
|
145
|
+
const { masterApp } = getRuntimeConfig(config);
|
|
146
|
+
if (masterApp) {
|
|
147
|
+
imports.push({
|
|
148
|
+
value: runtimePluginName,
|
|
149
|
+
specifiers: [
|
|
150
|
+
{
|
|
151
|
+
imported: "garfish"
|
|
152
|
+
}
|
|
153
|
+
]
|
|
154
|
+
});
|
|
155
|
+
imports.push({
|
|
156
|
+
value: runtimePluginName,
|
|
157
|
+
specifiers: [
|
|
158
|
+
{
|
|
159
|
+
imported: "masterApp"
|
|
160
|
+
}
|
|
161
|
+
]
|
|
162
|
+
});
|
|
143
163
|
}
|
|
144
|
-
};
|
|
145
|
-
},
|
|
146
|
-
addRuntimeExports() {
|
|
147
|
-
const config = useResolvedConfigContext();
|
|
148
|
-
const { masterApp } = getRuntimeConfig(config);
|
|
149
|
-
if (masterApp) {
|
|
150
|
-
const addExportStatement = `export { default as garfish, default as masterApp } from '${pluginName}/runtime'`;
|
|
151
|
-
logger("exportStatement", addExportStatement);
|
|
152
|
-
pluginsExportsUtils.addExport(addExportStatement);
|
|
153
|
-
}
|
|
154
|
-
const otherExportStatement = `export { hoistNonReactStatics } from '${pluginName}/deps'`;
|
|
155
|
-
logger("otherExportStatement", otherExportStatement);
|
|
156
|
-
pluginsExportsUtils.addExport(otherExportStatement);
|
|
157
|
-
},
|
|
158
|
-
modifyEntryImports({ entrypoint, imports }) {
|
|
159
|
-
const config = useResolvedConfigContext();
|
|
160
|
-
const { masterApp } = getRuntimeConfig(config);
|
|
161
|
-
if (masterApp) {
|
|
162
164
|
imports.push({
|
|
163
165
|
value: runtimePluginName,
|
|
164
166
|
specifiers: [
|
|
165
167
|
{
|
|
166
|
-
imported: "
|
|
168
|
+
imported: "hoistNonReactStatics"
|
|
167
169
|
}
|
|
168
170
|
]
|
|
169
171
|
});
|
|
170
172
|
imports.push({
|
|
171
|
-
value:
|
|
173
|
+
value: "react-dom",
|
|
172
174
|
specifiers: [
|
|
173
175
|
{
|
|
174
|
-
imported: "
|
|
176
|
+
imported: "unmountComponentAtNode"
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
imported: "createPortal"
|
|
175
180
|
}
|
|
176
181
|
]
|
|
177
182
|
});
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
imported: "createPortal"
|
|
195
|
-
}
|
|
196
|
-
]
|
|
197
|
-
});
|
|
198
|
-
return { imports, entrypoint };
|
|
199
|
-
},
|
|
200
|
-
modifyEntryRuntimePlugins({ entrypoint, plugins }) {
|
|
201
|
-
const config = useResolvedConfigContext();
|
|
202
|
-
const { masterApp } = getRuntimeConfig(config);
|
|
203
|
-
if (masterApp) {
|
|
204
|
-
logger("garfishPlugin options", masterApp);
|
|
205
|
-
plugins.push({
|
|
206
|
-
name: "garfish",
|
|
207
|
-
args: "masterApp",
|
|
208
|
-
options: masterApp === true ? JSON.stringify({}) : JSON.stringify(masterApp)
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
return { entrypoint, plugins };
|
|
212
|
-
},
|
|
213
|
-
modifyEntryRenderFunction({ entrypoint, code }) {
|
|
214
|
-
var _a;
|
|
215
|
-
const config = useResolvedConfigContext();
|
|
216
|
-
if (!((_a = config == null ? void 0 : config.deploy) == null ? void 0 : _a.microFrontend)) {
|
|
217
|
-
return { entrypoint, code };
|
|
218
|
-
}
|
|
219
|
-
const nCode = makeRenderFunction(code);
|
|
220
|
-
logger("makeRenderFunction", nCode);
|
|
221
|
-
return {
|
|
222
|
-
entrypoint,
|
|
223
|
-
code: nCode
|
|
224
|
-
};
|
|
225
|
-
},
|
|
226
|
-
modifyAsyncEntry({ entrypoint, code }) {
|
|
227
|
-
var _a, _b;
|
|
228
|
-
const config = useResolvedConfigContext();
|
|
229
|
-
let finalCode = code;
|
|
230
|
-
if (((_a = config == null ? void 0 : config.deploy) == null ? void 0 : _a.microFrontend) && ((_b = config == null ? void 0 : config.source) == null ? void 0 : _b.enableAsyncEntry)) {
|
|
231
|
-
finalCode = generateAsyncEntry(code);
|
|
183
|
+
return {
|
|
184
|
+
imports,
|
|
185
|
+
entrypoint
|
|
186
|
+
};
|
|
187
|
+
},
|
|
188
|
+
modifyEntryRuntimePlugins({ entrypoint, plugins }) {
|
|
189
|
+
const config = useResolvedConfigContext();
|
|
190
|
+
const { masterApp } = getRuntimeConfig(config);
|
|
191
|
+
if (masterApp) {
|
|
192
|
+
logger("garfishPlugin options", masterApp);
|
|
193
|
+
plugins.push({
|
|
194
|
+
name: "garfish",
|
|
195
|
+
args: "masterApp",
|
|
196
|
+
options: masterApp === true ? JSON.stringify({}) : JSON.stringify(masterApp)
|
|
197
|
+
});
|
|
198
|
+
}
|
|
232
199
|
return {
|
|
233
200
|
entrypoint,
|
|
234
|
-
|
|
201
|
+
plugins
|
|
235
202
|
};
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
const
|
|
247
|
-
logger("
|
|
203
|
+
},
|
|
204
|
+
modifyEntryRenderFunction({ entrypoint, code }) {
|
|
205
|
+
var _config_deploy;
|
|
206
|
+
const config = useResolvedConfigContext();
|
|
207
|
+
if (!(config === null || config === void 0 ? void 0 : (_config_deploy = config.deploy) === null || _config_deploy === void 0 ? void 0 : _config_deploy.microFrontend)) {
|
|
208
|
+
return {
|
|
209
|
+
entrypoint,
|
|
210
|
+
code
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
const nCode = makeRenderFunction(code);
|
|
214
|
+
logger("makeRenderFunction", nCode);
|
|
215
|
+
return {
|
|
216
|
+
entrypoint,
|
|
217
|
+
code: nCode
|
|
218
|
+
};
|
|
219
|
+
},
|
|
220
|
+
modifyAsyncEntry({ entrypoint, code }) {
|
|
221
|
+
var _config_deploy, _config_source;
|
|
222
|
+
const config = useResolvedConfigContext();
|
|
223
|
+
let finalCode = code;
|
|
224
|
+
if ((config === null || config === void 0 ? void 0 : (_config_deploy = config.deploy) === null || _config_deploy === void 0 ? void 0 : _config_deploy.microFrontend) && (config === null || config === void 0 ? void 0 : (_config_source = config.source) === null || _config_source === void 0 ? void 0 : _config_source.enableAsyncEntry)) {
|
|
225
|
+
finalCode = generateAsyncEntry(code);
|
|
226
|
+
return {
|
|
227
|
+
entrypoint,
|
|
228
|
+
code: `${finalCode}`
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
return {
|
|
232
|
+
entrypoint,
|
|
233
|
+
code: finalCode
|
|
234
|
+
};
|
|
235
|
+
},
|
|
236
|
+
modifyEntryExport({ entrypoint, exportStatement }) {
|
|
237
|
+
var _config_deploy;
|
|
238
|
+
const config = useResolvedConfigContext();
|
|
239
|
+
if (config === null || config === void 0 ? void 0 : (_config_deploy = config.deploy) === null || _config_deploy === void 0 ? void 0 : _config_deploy.microFrontend) {
|
|
240
|
+
const exportStatementCode = makeProvider();
|
|
241
|
+
logger("exportStatement", exportStatementCode);
|
|
242
|
+
return {
|
|
243
|
+
entrypoint,
|
|
244
|
+
exportStatement: exportStatementCode
|
|
245
|
+
};
|
|
246
|
+
}
|
|
248
247
|
return {
|
|
249
248
|
entrypoint,
|
|
250
|
-
exportStatement
|
|
249
|
+
exportStatement
|
|
251
250
|
};
|
|
252
251
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
export {
|
|
262
|
-
cli_default as default,
|
|
263
|
-
externals,
|
|
264
|
-
getDefaultMicroFrontedConfig
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
};
|
|
265
255
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const makeProvider = () => `
|
|
1
|
+
export const makeProvider = () => `
|
|
2
2
|
export const provider = function ({basename, dom}) {
|
|
3
3
|
return {
|
|
4
4
|
render({basename, dom, props, appName}) {
|
|
@@ -76,7 +76,7 @@ function generateRootDom ({ dom, props, basename }) {
|
|
|
76
76
|
return { mountNode, props: mergedProps }
|
|
77
77
|
}
|
|
78
78
|
`;
|
|
79
|
-
const makeRenderFunction = (code) => {
|
|
79
|
+
export const makeRenderFunction = (code) => {
|
|
80
80
|
const inGarfishToRender = `
|
|
81
81
|
let { basename, props, dom, appName } = typeof arguments[0] === 'object' && arguments[0] || {};
|
|
82
82
|
if (!canContinueRender({ dom, appName })) return null;
|
|
@@ -84,38 +84,30 @@ const makeRenderFunction = (code) => {
|
|
|
84
84
|
let mountNode = rootDomInfo.mountNode;
|
|
85
85
|
props = rootDomInfo.props;
|
|
86
86
|
`;
|
|
87
|
-
return inGarfishToRender + code.replace(`router(`, `generateRouterPlugin(basename,`).replace(/MOUNT_ID/g, "mountNode").replace(`createApp({`, "createApp({ props,").replace(
|
|
88
|
-
`bootstrap(AppWrapper, mountNode, root`,
|
|
89
|
-
"bootstrap(AppWrapper, mountNode, root = IS_REACT18 ? ReactDOM.createRoot(mountNode) : null"
|
|
90
|
-
).replace(
|
|
91
|
-
`customBootstrap(AppWrapper`,
|
|
92
|
-
"customBootstrap(AppWrapper, mountNode"
|
|
93
|
-
);
|
|
87
|
+
return inGarfishToRender + code.replace(`router(`, `generateRouterPlugin(basename,`).replace(/MOUNT_ID/g, "mountNode").replace(`createApp({`, "createApp({ props,").replace(`bootstrap(AppWrapper, mountNode, root`, "bootstrap(AppWrapper, mountNode, root = IS_REACT18 ? ReactDOM.createRoot(mountNode) : null").replace(`customBootstrap(AppWrapper`, "customBootstrap(AppWrapper, mountNode");
|
|
94
88
|
};
|
|
95
|
-
function getRuntimeConfig(config) {
|
|
96
|
-
var
|
|
97
|
-
if (
|
|
98
|
-
|
|
89
|
+
export function getRuntimeConfig(config) {
|
|
90
|
+
var _config_runtime;
|
|
91
|
+
if (config === null || config === void 0 ? void 0 : (_config_runtime = config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.features) {
|
|
92
|
+
var _config_runtime1;
|
|
93
|
+
return config === null || config === void 0 ? void 0 : (_config_runtime1 = config.runtime) === null || _config_runtime1 === void 0 ? void 0 : _config_runtime1.features;
|
|
99
94
|
}
|
|
100
|
-
return (config
|
|
95
|
+
return (config === null || config === void 0 ? void 0 : config.runtime) || {};
|
|
101
96
|
}
|
|
102
|
-
function setRuntimeConfig(config, key, value) {
|
|
103
|
-
var
|
|
104
|
-
if ((
|
|
97
|
+
export function setRuntimeConfig(config, key, value) {
|
|
98
|
+
var _config_runtime, _config_runtime1;
|
|
99
|
+
if ((config === null || config === void 0 ? void 0 : (_config_runtime = config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.features) && (config === null || config === void 0 ? void 0 : (_config_runtime1 = config.runtime) === null || _config_runtime1 === void 0 ? void 0 : _config_runtime1.features[key])) {
|
|
105
100
|
config.runtime.features[key] = value;
|
|
106
101
|
return void 0;
|
|
107
102
|
}
|
|
108
|
-
if ((config
|
|
103
|
+
if ((config === null || config === void 0 ? void 0 : config.runtime) && (config === null || config === void 0 ? void 0 : config.runtime[key])) {
|
|
109
104
|
config.runtime[key] = value;
|
|
110
105
|
return void 0;
|
|
111
106
|
}
|
|
112
107
|
return void 0;
|
|
113
108
|
}
|
|
114
|
-
const generateAsyncEntry = (code) => {
|
|
115
|
-
const transformCode = code.replace(
|
|
116
|
-
`import('./bootstrap.js');`,
|
|
117
|
-
`if (!window.__GARFISH__) { import('./bootstrap.js'); }`
|
|
118
|
-
);
|
|
109
|
+
export const generateAsyncEntry = (code) => {
|
|
110
|
+
const transformCode = code.replace(`import('./bootstrap.js');`, `if (!window.__GARFISH__) { import('./bootstrap.js'); }`);
|
|
119
111
|
return `
|
|
120
112
|
export const provider = async (...args) => {
|
|
121
113
|
const exports = await import('./bootstrap');
|
|
@@ -127,10 +119,3 @@ const generateAsyncEntry = (code) => {
|
|
|
127
119
|
}
|
|
128
120
|
`;
|
|
129
121
|
};
|
|
130
|
-
export {
|
|
131
|
-
generateAsyncEntry,
|
|
132
|
-
getRuntimeConfig,
|
|
133
|
-
makeProvider,
|
|
134
|
-
makeRenderFunction,
|
|
135
|
-
setRuntimeConfig
|
|
136
|
-
};
|
package/dist/esm-node/index.js
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export {
|
|
5
|
-
default3 as Garfish,
|
|
6
|
-
default2 as default,
|
|
7
|
-
default4 as garfish,
|
|
8
|
-
useModuleApp,
|
|
9
|
-
useModuleApps
|
|
10
|
-
};
|
|
1
|
+
export { default } from "./plugin";
|
|
2
|
+
export { useModuleApps, useModuleApp } from "./useModuleApps";
|
|
3
|
+
export { default as Garfish, default as garfish } from "garfish";
|