Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
fix defaultImportMap
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangHongEn committed Nov 14, 2023
1 parent 419410b commit 027b9be
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
8 changes: 8 additions & 0 deletions packages/wpmjs/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ const prototype = Config.prototype
* @returns
*/
prototype.requestFormatConfig = function requestFormatConfig(obj = "") {
const [_, globalKey, url] = (typeof obj === "string" && obj.match(/([\w]+)\@(https?\:\/\/.*)/)) || []
if (url) {
return {
moduleType: "mf",
global: globalKey,
url,
}
}
if (/https?:\/\//.test(obj)) {
return {
url: obj,
Expand Down
2 changes: 1 addition & 1 deletion packages/wpmjs/src/wpmjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function wimportWrapper(request) {
* @returns
*/
async function wimport(request) {
const useConfig = getPkgConfig(parseRequest(request).name, this.config)
const useConfig = getPkgConfig(parseRequest(request).name, this.config) || this.config.requestFormatConfig.call(this, request)
let requestObj = resolveRequest(request, this.config, useConfig)

const {
Expand Down
4 changes: 3 additions & 1 deletion packages/wpmjs/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ wpmjs1.addImportMap({
"mf-app-01": {
package: "[email protected]/dist/remoteEntry.js",
global: "mfapp01"
}
},
"mf-app-01": "mfapp01@https://cdn.jsdelivr.net/npm/[email protected]/dist/remoteEntry.js"
})

wpmjs.addImportMap({
Expand All @@ -67,6 +68,7 @@ wpmjs.addImportMap({
package: "[email protected]/dist/remoteEntry.js",
global: "mfapp01"
},
"mf-app-01": "mfapp01@https://cdn.jsdelivr.net/npm/[email protected]/dist/remoteEntry.js",
"mf-app-02": {
package: "[email protected]/dist/remoteEntry.js",
global: "mfapp02"
Expand Down

0 comments on commit 027b9be

Please sign in to comment.