@modern-js/plugin-garfish 1.3.0 → 1.3.1
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/.eslintrc.js +1 -1
- package/CHANGELOG.md +12 -0
- package/dist/js/modern/cli/index.js +190 -209
- package/dist/js/modern/cli/utils.js +1 -6
- package/dist/js/modern/index.js +2 -1
- package/dist/js/modern/runtime/index.js +2 -1
- package/dist/js/modern/runtime/loadable.js +36 -19
- package/dist/js/modern/runtime/plugin.js +14 -17
- package/dist/js/modern/runtime/utils/MApp.js +7 -10
- package/dist/js/modern/runtime/utils/apps.js +1 -4
- package/dist/js/node/cli/index.js +192 -213
- package/dist/js/node/cli/utils.js +1 -6
- package/dist/js/node/index.js +18 -3
- package/dist/js/node/runtime/index.js +25 -12
- package/dist/js/node/runtime/loadable.js +36 -19
- package/dist/js/node/runtime/plugin.js +11 -16
- package/dist/js/node/runtime/utils/MApp.js +7 -10
- package/dist/js/node/runtime/utils/apps.js +1 -4
- package/dist/js/treeshaking/cli/index.js +183 -199
- package/dist/js/treeshaking/cli/utils.js +2 -2
- package/dist/js/treeshaking/index.js +2 -1
- package/dist/js/treeshaking/runtime/index.js +2 -1
- package/dist/js/treeshaking/runtime/loadable.js +39 -25
- package/dist/js/treeshaking/runtime/plugin.js +15 -19
- package/dist/js/treeshaking/runtime/utils/MApp.js +23 -31
- package/dist/js/treeshaking/runtime/utils/apps.js +1 -2
- package/dist/types/cli/index.d.ts +1 -9
- package/dist/types/cli/utils.d.ts +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/runtime/index.d.ts +3 -1
- package/dist/types/runtime/loadable.d.ts +2 -8
- package/dist/types/runtime/plugin.d.ts +29 -3
- package/dist/types/runtime/useModuleApps.d.ts +7 -9
- package/dist/types/runtime/utils/MApp.d.ts +1 -15
- package/dist/types/runtime/utils/apps.d.ts +1 -1
- package/package.json +20 -8
- package/tests/cli.test.tsx +21 -43
- package/tests/hooks.test.tsx +1 -0
- package/tests/index.test.tsx +6 -3
- package/tsconfig.json +3 -2
- package/tests/__snapshots__/cli.test.tsx.snap +0 -71
package/.eslintrc.js
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @modern-js/plugin-garfish
|
|
2
2
|
|
|
3
|
+
## 1.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 53aca274: modify garfish-plugin config type
|
|
8
|
+
- Updated dependencies [53aca274]
|
|
9
|
+
- Updated dependencies [78279953]
|
|
10
|
+
- Updated dependencies [e116ace5]
|
|
11
|
+
- Updated dependencies [4d72edea]
|
|
12
|
+
- @modern-js/core@1.4.1
|
|
13
|
+
- @modern-js/utils@1.3.1
|
|
14
|
+
|
|
3
15
|
## 1.3.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
const _excluded = ["validateSchema", "externals", "componentKey"];
|
|
2
|
-
|
|
3
1
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
2
|
|
|
5
3
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
4
|
|
|
7
5
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
6
|
|
|
9
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
10
|
-
|
|
11
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
12
|
-
|
|
13
7
|
import path from 'path';
|
|
14
8
|
import { createRuntimeExportsUtils, getEntryOptions, PLUGIN_SCHEMAS } from '@modern-js/utils';
|
|
15
9
|
import { createPlugin, useAppContext, useResolvedConfigContext } from '@modern-js/core';
|
|
@@ -40,244 +34,231 @@ function setRuntimeConfig(config, key, value) {
|
|
|
40
34
|
}
|
|
41
35
|
}
|
|
42
36
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
setRuntimeConfig(nConfig.resolved, 'masterApp', Object.assign(typeof masterApp === 'object' ? _objectSpread({}, masterApp) : {}, {
|
|
71
|
-
basename: (router === null || router === void 0 ? void 0 : router.basename) || '/'
|
|
72
|
-
}));
|
|
73
|
-
}
|
|
37
|
+
const externals = {
|
|
38
|
+
'react-dom': 'react-dom',
|
|
39
|
+
react: 'react'
|
|
40
|
+
};
|
|
41
|
+
export default createPlugin(() => {
|
|
42
|
+
const configMap = new Map();
|
|
43
|
+
let pluginsExportsUtils;
|
|
44
|
+
let runtimeExportsUtils;
|
|
45
|
+
return {
|
|
46
|
+
resolvedConfig(config) {
|
|
47
|
+
const {
|
|
48
|
+
resolved
|
|
49
|
+
} = config;
|
|
50
|
+
const {
|
|
51
|
+
masterApp,
|
|
52
|
+
router
|
|
53
|
+
} = getRuntimeConfig(resolved);
|
|
54
|
+
const nConfig = {
|
|
55
|
+
resolved: _objectSpread({}, resolved)
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
if (masterApp) {
|
|
59
|
+
// basename does not exist use router's basename
|
|
60
|
+
setRuntimeConfig(nConfig.resolved, 'masterApp', Object.assign(typeof masterApp === 'object' ? _objectSpread({}, masterApp) : {}, {
|
|
61
|
+
basename: (router === null || router === void 0 ? void 0 : router.basename) || '/'
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
74
64
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
65
|
+
logger(`resolvedConfig`, {
|
|
66
|
+
runtime: nConfig.resolved.runtime,
|
|
67
|
+
deploy: nConfig.resolved.deploy,
|
|
68
|
+
server: nConfig.resolved.server
|
|
69
|
+
});
|
|
70
|
+
return nConfig;
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
config() {
|
|
74
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
75
|
+
const config = useAppContext();
|
|
76
|
+
pluginsExportsUtils = createRuntimeExportsUtils(config.internalDirectory, 'plugins');
|
|
77
|
+
runtimeExportsUtils = createRuntimeExportsUtils(config.internalDirectory, 'index');
|
|
78
|
+
return {
|
|
79
|
+
source: {
|
|
80
|
+
alias: {
|
|
81
|
+
'@modern-js/runtime/plugins': pluginsExportsUtils.getPath()
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
tools: {
|
|
85
|
+
webpack: (webpackConfig, {
|
|
86
|
+
chain,
|
|
87
|
+
webpack
|
|
88
|
+
}) => {
|
|
89
|
+
var _resolvedConfig$deplo, _resolveWebpackConfig;
|
|
100
90
|
|
|
101
|
-
|
|
91
|
+
const env = process.env.NODE_ENV; // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
102
92
|
|
|
103
|
-
|
|
93
|
+
const resolvedConfig = useResolvedConfigContext();
|
|
104
94
|
|
|
105
|
-
|
|
106
|
-
|
|
95
|
+
if (resolvedConfig !== null && resolvedConfig !== void 0 && (_resolvedConfig$deplo = resolvedConfig.deploy) !== null && _resolvedConfig$deplo !== void 0 && _resolvedConfig$deplo.microFrontend) {
|
|
96
|
+
var _resolvedConfig$deplo2, _resolvedConfig$deplo3;
|
|
107
97
|
|
|
108
|
-
|
|
98
|
+
chain.output.libraryTarget('umd');
|
|
109
99
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
100
|
+
if (resolvedConfig.server.port) {
|
|
101
|
+
chain.output.publicPath(env === 'development' ? `//localhost:${resolvedConfig.server.port}/` : webpackConfig.output.publicPath);
|
|
102
|
+
} // add comments avoid sourcemap abnormal
|
|
113
103
|
|
|
114
104
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
105
|
+
chain.plugin('banner').use(webpack.BannerPlugin, [{
|
|
106
|
+
banner: 'Micro front-end'
|
|
107
|
+
}]);
|
|
108
|
+
const {
|
|
109
|
+
enableHtmlEntry = true,
|
|
110
|
+
externalBasicLibrary = true
|
|
111
|
+
} = typeof (resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig$deplo2 = resolvedConfig.deploy) === null || _resolvedConfig$deplo2 === void 0 ? void 0 : _resolvedConfig$deplo2.microFrontend) === 'object' ? resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig$deplo3 = resolvedConfig.deploy) === null || _resolvedConfig$deplo3 === void 0 ? void 0 : _resolvedConfig$deplo3.microFrontend : {}; // external
|
|
122
112
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
113
|
+
if (externalBasicLibrary) {
|
|
114
|
+
chain.externals(externals);
|
|
115
|
+
} // use html mode
|
|
126
116
|
|
|
127
117
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
118
|
+
if (!enableHtmlEntry) {
|
|
119
|
+
chain.output.filename('index.js');
|
|
120
|
+
chain.plugins.delete('html-main');
|
|
121
|
+
chain.optimization.runtimeChunk(false);
|
|
122
|
+
chain.optimization.splitChunks({
|
|
123
|
+
chunks: 'async'
|
|
124
|
+
});
|
|
136
125
|
}
|
|
137
|
-
|
|
138
|
-
const resolveWebpackConfig = chain.toConfig();
|
|
139
|
-
logger('webpackConfig', {
|
|
140
|
-
output: resolveWebpackConfig.output,
|
|
141
|
-
externals: resolveWebpackConfig.externals,
|
|
142
|
-
env
|
|
143
|
-
});
|
|
144
126
|
}
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
},
|
|
148
127
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
validateSchema,
|
|
158
|
-
|
|
159
|
-
modifyEntryImports({
|
|
160
|
-
entrypoint,
|
|
161
|
-
imports
|
|
162
|
-
}) {
|
|
163
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
164
|
-
const resolvedConfig = useResolvedConfigContext(); // support legacy config
|
|
165
|
-
|
|
166
|
-
const {
|
|
167
|
-
masterApp
|
|
168
|
-
} = getRuntimeConfig(resolvedConfig); // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
169
|
-
|
|
170
|
-
const {
|
|
171
|
-
packageName
|
|
172
|
-
} = useAppContext();
|
|
173
|
-
const masterAppConfig = getEntryOptions(entrypoint.entryName, masterApp, resolvedConfig.runtimeByEntries, packageName);
|
|
174
|
-
configMap.set(entrypoint.entryName, masterAppConfig);
|
|
175
|
-
|
|
176
|
-
if (masterAppConfig) {
|
|
177
|
-
imports.push({
|
|
178
|
-
value: '@modern-js/runtime/plugins',
|
|
179
|
-
specifiers: [{
|
|
180
|
-
imported: 'garfish'
|
|
181
|
-
}]
|
|
182
|
-
});
|
|
128
|
+
const resolveWebpackConfig = chain.toConfig();
|
|
129
|
+
logger('webpackConfig', {
|
|
130
|
+
output: resolveWebpackConfig.output,
|
|
131
|
+
externals: resolveWebpackConfig.externals,
|
|
132
|
+
env,
|
|
133
|
+
alias: (_resolveWebpackConfig = resolveWebpackConfig.resolve) === null || _resolveWebpackConfig === void 0 ? void 0 : _resolveWebpackConfig.alias
|
|
134
|
+
});
|
|
135
|
+
}
|
|
183
136
|
}
|
|
184
|
-
|
|
137
|
+
};
|
|
138
|
+
},
|
|
139
|
+
|
|
140
|
+
addRuntimeExports() {
|
|
141
|
+
const mfPackage = path.resolve(__dirname, '../../../../');
|
|
142
|
+
const addExportStatement = `export { default as garfish } from '${mfPackage}'`;
|
|
143
|
+
logger('exportStatement', addExportStatement);
|
|
144
|
+
pluginsExportsUtils.addExport(addExportStatement);
|
|
145
|
+
runtimeExportsUtils.addExport(`export * from '${mfPackage}'`);
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
validateSchema() {
|
|
149
|
+
return PLUGIN_SCHEMAS['@modern-js/plugin-garfish'];
|
|
150
|
+
},
|
|
151
|
+
|
|
152
|
+
modifyEntryImports({
|
|
153
|
+
entrypoint,
|
|
154
|
+
imports
|
|
155
|
+
}) {
|
|
156
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
157
|
+
const resolvedConfig = useResolvedConfigContext(); // support legacy config
|
|
158
|
+
|
|
159
|
+
const {
|
|
160
|
+
masterApp
|
|
161
|
+
} = getRuntimeConfig(resolvedConfig); // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
162
|
+
|
|
163
|
+
const {
|
|
164
|
+
packageName
|
|
165
|
+
} = useAppContext();
|
|
166
|
+
const masterAppConfig = getEntryOptions(entrypoint.entryName, masterApp, resolvedConfig.runtimeByEntries, packageName);
|
|
167
|
+
configMap.set(entrypoint.entryName, masterAppConfig);
|
|
168
|
+
|
|
169
|
+
if (masterAppConfig) {
|
|
185
170
|
imports.push({
|
|
186
|
-
value: '
|
|
171
|
+
value: '@modern-js/runtime/plugins',
|
|
187
172
|
specifiers: [{
|
|
188
|
-
imported: '
|
|
189
|
-
}, {
|
|
190
|
-
imported: 'createPortal'
|
|
173
|
+
imported: 'garfish'
|
|
191
174
|
}]
|
|
192
175
|
});
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
imports.push({
|
|
179
|
+
value: 'react-dom',
|
|
180
|
+
specifiers: [{
|
|
181
|
+
imported: 'unmountComponentAtNode'
|
|
182
|
+
}, {
|
|
183
|
+
imported: 'createPortal'
|
|
184
|
+
}]
|
|
185
|
+
});
|
|
186
|
+
return {
|
|
187
|
+
imports,
|
|
188
|
+
entrypoint
|
|
189
|
+
};
|
|
190
|
+
},
|
|
191
|
+
|
|
192
|
+
modifyEntryRuntimePlugins({
|
|
193
|
+
entrypoint,
|
|
194
|
+
plugins
|
|
195
|
+
}) {
|
|
196
|
+
const masterAppConfig = configMap.get(entrypoint.entryName);
|
|
197
|
+
|
|
198
|
+
if (masterAppConfig) {
|
|
199
|
+
logger('garfishPlugin options', masterAppConfig);
|
|
200
|
+
plugins.push({
|
|
201
|
+
name: 'garfish',
|
|
202
|
+
args: 'masterApp',
|
|
203
|
+
options: JSON.stringify(masterAppConfig)
|
|
204
|
+
});
|
|
205
|
+
}
|
|
198
206
|
|
|
199
|
-
|
|
207
|
+
return {
|
|
200
208
|
entrypoint,
|
|
201
209
|
plugins
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
if (masterAppConfig) {
|
|
206
|
-
logger('garfishPlugin options', masterAppConfig);
|
|
207
|
-
plugins.push({
|
|
208
|
-
name: 'garfish',
|
|
209
|
-
args: 'masterApp',
|
|
210
|
-
options: JSON.stringify(masterAppConfig)
|
|
211
|
-
});
|
|
212
|
-
}
|
|
210
|
+
};
|
|
211
|
+
},
|
|
213
212
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
213
|
+
modifyEntryRenderFunction({
|
|
214
|
+
entrypoint,
|
|
215
|
+
code
|
|
216
|
+
}) {
|
|
217
|
+
var _config$deploy;
|
|
219
218
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
code
|
|
223
|
-
}) {
|
|
224
|
-
var _config$deploy;
|
|
225
|
-
|
|
226
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
227
|
-
const config = useResolvedConfigContext();
|
|
228
|
-
|
|
229
|
-
if (!(config !== null && config !== void 0 && (_config$deploy = config.deploy) !== null && _config$deploy !== void 0 && _config$deploy.microFrontend)) {
|
|
230
|
-
return {
|
|
231
|
-
entrypoint,
|
|
232
|
-
code
|
|
233
|
-
};
|
|
234
|
-
}
|
|
219
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
220
|
+
const config = useResolvedConfigContext();
|
|
235
221
|
|
|
236
|
-
|
|
237
|
-
logger('makeRenderFunction', nCode);
|
|
222
|
+
if (!(config !== null && config !== void 0 && (_config$deploy = config.deploy) !== null && _config$deploy !== void 0 && _config$deploy.microFrontend)) {
|
|
238
223
|
return {
|
|
239
224
|
entrypoint,
|
|
240
|
-
code
|
|
225
|
+
code
|
|
241
226
|
};
|
|
242
|
-
}
|
|
227
|
+
}
|
|
243
228
|
|
|
244
|
-
|
|
229
|
+
const nCode = makeRenderFunction(code);
|
|
230
|
+
logger('makeRenderFunction', nCode);
|
|
231
|
+
return {
|
|
245
232
|
entrypoint,
|
|
246
|
-
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
233
|
+
code: nCode
|
|
234
|
+
};
|
|
235
|
+
},
|
|
236
|
+
|
|
237
|
+
modifyEntryExport({
|
|
238
|
+
entrypoint,
|
|
239
|
+
exportStatement
|
|
240
|
+
}) {
|
|
241
|
+
var _resolvedConfig$deplo4;
|
|
242
|
+
|
|
243
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
244
|
+
const resolvedConfig = useResolvedConfigContext();
|
|
245
|
+
|
|
246
|
+
if (resolvedConfig !== null && resolvedConfig !== void 0 && (_resolvedConfig$deplo4 = resolvedConfig.deploy) !== null && _resolvedConfig$deplo4 !== void 0 && _resolvedConfig$deplo4.microFrontend) {
|
|
247
|
+
const exportStatementCode = makeProvider();
|
|
248
|
+
logger('exportStatement', exportStatementCode);
|
|
262
249
|
return {
|
|
263
250
|
entrypoint,
|
|
264
|
-
exportStatement
|
|
251
|
+
exportStatement: exportStatementCode
|
|
265
252
|
};
|
|
266
253
|
}
|
|
267
254
|
|
|
268
|
-
|
|
255
|
+
return {
|
|
256
|
+
entrypoint,
|
|
257
|
+
exportStatement
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
269
261
|
};
|
|
270
|
-
}
|
|
271
|
-
export default createPlugin(initializer({
|
|
272
|
-
validateSchema() {
|
|
273
|
-
return PLUGIN_SCHEMAS['@modern-js/plugin-garfish'];
|
|
274
|
-
},
|
|
275
|
-
|
|
276
|
-
externals: {
|
|
277
|
-
'react-dom': 'react-dom',
|
|
278
|
-
react: 'react'
|
|
279
|
-
},
|
|
280
|
-
componentKey: 'dynamicComponent'
|
|
281
|
-
}), {
|
|
262
|
+
}, {
|
|
282
263
|
name: '@modern-js/plugin-garfish'
|
|
283
264
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const makeProvider =
|
|
1
|
+
export const makeProvider = () => `
|
|
2
2
|
export const provider = function ({basename, dom, ...props}) {
|
|
3
3
|
return {
|
|
4
4
|
render({basename, dom}) {
|
|
@@ -17,11 +17,6 @@ export const makeProvider = componentKey => `
|
|
|
17
17
|
SubModuleComponent: (props) => {
|
|
18
18
|
const SubApp = render(props, basename);
|
|
19
19
|
|
|
20
|
-
return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);
|
|
21
|
-
},
|
|
22
|
-
${componentKey}: () => {
|
|
23
|
-
const SubApp = render(props, basename);
|
|
24
|
-
|
|
25
20
|
return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);
|
|
26
21
|
}
|
|
27
22
|
}
|
package/dist/js/modern/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { default } from "./
|
|
1
|
+
export { default } from "./runtime";
|
|
2
|
+
export * from "./runtime";
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
const _excluded = ["loadable"];
|
|
2
|
+
|
|
1
3
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
4
|
|
|
3
5
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
6
|
|
|
5
7
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
8
|
|
|
9
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
10
|
+
|
|
11
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
12
|
+
|
|
7
13
|
// logical reference to https://github.com/jamiebuilds/react-loadable/blob/6201c5837b212d6244c57f3748f2b1375096beeb/src/index.js
|
|
8
14
|
import React from 'react';
|
|
9
15
|
import { logger } from "../util";
|
|
@@ -11,14 +17,11 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
11
17
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
12
18
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
19
|
export function Loadable(WrapComponent) {
|
|
14
|
-
return function (
|
|
20
|
+
return function (defaultLoadable) {
|
|
15
21
|
return class LoadableComponent extends React.Component {
|
|
16
22
|
constructor(...args) {
|
|
17
23
|
super(...args);
|
|
18
24
|
this.state = {
|
|
19
|
-
LoadingComponent: defaultLoadingComponent,
|
|
20
|
-
timeout: 10000,
|
|
21
|
-
delay: 200,
|
|
22
25
|
error: null,
|
|
23
26
|
pastDelay: false,
|
|
24
27
|
timedOut: false,
|
|
@@ -42,19 +45,16 @@ export function Loadable(WrapComponent) {
|
|
|
42
45
|
UNSAFE_componentWillMount() {
|
|
43
46
|
this.mounted = true;
|
|
44
47
|
const {
|
|
45
|
-
|
|
48
|
+
loadable = defaultLoadable || {
|
|
49
|
+
delay: 200,
|
|
50
|
+
timeout: 10000,
|
|
51
|
+
loading: null
|
|
52
|
+
}
|
|
46
53
|
} = this.props;
|
|
47
|
-
|
|
48
|
-
if (loadingConfig !== null && loadingConfig !== void 0 && loadingConfig.LoadingComponent) {
|
|
49
|
-
this.setStateWithMountCheck({
|
|
50
|
-
LoadingComponent: loadingConfig.LoadingComponent
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
54
|
const {
|
|
55
55
|
delay,
|
|
56
56
|
timeout
|
|
57
|
-
} =
|
|
57
|
+
} = loadable;
|
|
58
58
|
|
|
59
59
|
if (typeof delay === 'number') {
|
|
60
60
|
if (delay === 0) {
|
|
@@ -93,7 +93,6 @@ export function Loadable(WrapComponent) {
|
|
|
93
93
|
return;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
logger('Loadable state', this.state);
|
|
97
96
|
this.setState(newState);
|
|
98
97
|
}
|
|
99
98
|
|
|
@@ -103,17 +102,35 @@ export function Loadable(WrapComponent) {
|
|
|
103
102
|
}
|
|
104
103
|
|
|
105
104
|
render() {
|
|
106
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
107
105
|
const {
|
|
108
106
|
isLoading,
|
|
109
107
|
error,
|
|
110
108
|
pastDelay,
|
|
111
|
-
timedOut
|
|
112
|
-
LoadingComponent
|
|
109
|
+
timedOut
|
|
113
110
|
} = this.state;
|
|
111
|
+
|
|
112
|
+
const _this$props = this.props,
|
|
113
|
+
{
|
|
114
|
+
loadable = defaultLoadable || {
|
|
115
|
+
delay: 200,
|
|
116
|
+
timeout: 10000,
|
|
117
|
+
loading: null
|
|
118
|
+
}
|
|
119
|
+
} = _this$props,
|
|
120
|
+
otherProps = _objectWithoutProperties(_this$props, _excluded);
|
|
121
|
+
|
|
122
|
+
const {
|
|
123
|
+
loading: LoadingComponent
|
|
124
|
+
} = loadable;
|
|
125
|
+
logger('Loadable render state', {
|
|
126
|
+
state: this.state,
|
|
127
|
+
props: otherProps,
|
|
128
|
+
loadable,
|
|
129
|
+
defaultLoadable
|
|
130
|
+
});
|
|
114
131
|
const showLoading = (isLoading || error) && LoadingComponent;
|
|
115
132
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
116
|
-
children: [showLoading &&
|
|
133
|
+
children: [showLoading && /*#__PURE__*/_jsx(LoadingComponent, {
|
|
117
134
|
isLoading: isLoading,
|
|
118
135
|
pastDelay: pastDelay,
|
|
119
136
|
timedOut: timedOut,
|
|
@@ -124,7 +141,7 @@ export function Loadable(WrapComponent) {
|
|
|
124
141
|
display: showLoading ? 'none' : 'block'
|
|
125
142
|
},
|
|
126
143
|
setLoadingState: props => this.setStateWithMountCheck(props)
|
|
127
|
-
},
|
|
144
|
+
}, otherProps))]
|
|
128
145
|
});
|
|
129
146
|
}
|
|
130
147
|
|