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

Commit c986657

Browse files
committed
update baseUrl
1 parent 324c992 commit c986657

File tree

3 files changed

+45
-28
lines changed

3 files changed

+45
-28
lines changed
Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,7 @@
11
##
22

33
## api
4-
5-
<!-- // Inject some code through initial (not required)
6-
initial: `
7-
console.log("Inject code wpmjsInstance", wpmjs)
8-
wpmjs.sleep(new Promise(resolve => {
9-
// fetch("https://xxxxx.json")
10-
const json = {
11-
"@remix-run/router": {
12-
packageVersion: "1.9.0"
13-
}
14-
}
15-
setTimeout(() => {
16-
console.log("Asynchronously obtain data and dynamically set the remotes version", json)
17-
wpmjs.addImportMap(json)
18-
resolve()
19-
}, 100)
20-
}))
21-
`, -->
4+
### set npm package url
225
``` js
236
const NPMFederation = require("npm-federation")
247
new NPMFederation({
@@ -30,6 +13,7 @@ new NPMFederation({
3013
})
3114
```
3215

16+
### Set npm package path
3317
``` js
3418
const NPMFederation = require("npm-federation")
3519
new NPMFederation({
@@ -45,6 +29,36 @@ new NPMFederation({
4529
})
4630
```
4731

48-
<!-- ## 自定义url规则
49-
50-
## systemjs多入口规范 -->
32+
### Dynamically set npm package version at runtime
33+
``` js
34+
const NPMFederation = require("npm-federation")
35+
new NPMFederation({
36+
initial: `
37+
console.log("Inject code wpmjsInstance", wpmjs)
38+
wpmjs.sleep(new Promise(resolve => {
39+
// fetch("https://xxxxx.json")
40+
const json = {
41+
"@remix-run/router": {
42+
packageVersion: "1.9.0"
43+
},
44+
"mf-app-02": {
45+
packageVersion: "1.0.6"
46+
}
47+
}
48+
setTimeout(() => {
49+
console.log("Asynchronously obtain data and dynamically set the remotes version", json)
50+
wpmjs.addImportMap(json)
51+
resolve()
52+
}, 100)
53+
}))`,
54+
baseUrl: "https://cdn.jsdelivr.net/npm",
55+
remotes: {
56+
"@remix-run/router": "@remix-run/router/dist/router.umd.min.js",
57+
"mf-app-02": {
58+
package: "mf-app-02/dist/remoteEntry.js",
59+
global: "mfapp02"
60+
},
61+
},
62+
shared: {react: {}}
63+
})
64+
```

packages/npm-federation-webpack/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "npm-federation",
3-
"version": "1.0.9",
3+
"version": "1.0.11",
44
"description": "Use systemjs to add npm and umd extensions to module-federation",
55
"main": "src/plugin.js",
66
"scripts": {
@@ -23,8 +23,7 @@
2323
"hmr",
2424
"npm"
2525
],
26-
"devDependencies": {
27-
},
26+
"devDependencies": {},
2827
"dependencies": {
2928
"wpmjs": "^4.0.19",
3029
"single-react-refresh-plugin": "^1.0.5",

packages/npm-federation-webpack/src/plugin.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@ class NpmFederationPlugin {
99
constructor(options = {}) {
1010
const {
1111
initial,
12-
config,
1312
debugQuery,
1413
remotes,
1514
workerFiles,
15+
baseUrl,
1616
...ops
1717
} = Object.assign({
1818
initial: "",
19-
config: {},
19+
baseUrl: "",
2020
debugQuery: "",
2121
remotes: {},
2222
workerFiles: undefined
2323
}, options)
2424
this.options = options
2525
this.mfOptions = ops
26+
this.baseUrl = baseUrl
2627
this.initial = initial
2728
this.remotes = remotes
28-
this.config = config
2929
this.debugQuery = debugQuery
3030
this.workerFiles = workerFiles
3131
this.instanceIndex = ++instanceIndex
@@ -62,7 +62,11 @@ class NpmFederationPlugin {
6262
name: ${JSON.stringify(name)}
6363
})
6464
${this.initial}
65-
wpmjs.setConfig(${JSON.stringify(this.config || {})})
65+
${(function(plugin) {
66+
if (plugin.baseUrl) {
67+
return `;wpmjs.setConfig({baseUrl: ${JSON.stringify(plugin.baseUrl)}});`
68+
}
69+
})(this)}
6670
wpmjs.addImportMap(${JSON.stringify(this.remotes)})
6771
const __mfList = []
6872
const __preloadSystemList = []

0 commit comments

Comments
 (0)