@lynx-js/externals-loading-webpack-plugin-canary 0.1.0 → 0.1.1-canary-20260415-04be21a8
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 +19 -6
- package/lib/index.js +18 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @lynx-js/externals-loading-webpack-plugin
|
|
2
2
|
|
|
3
|
+
## 0.1.1-canary-20260415035435-04be21a8ef6457a93b238930f449bb17759006ef
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- fix: deduplicate `loadScript` calls for externals sharing the same (bundle, section) pair ([#2465](https://github.com/lynx-family/lynx-stack/pull/2465))
|
|
8
|
+
|
|
9
|
+
When multiple externals had different `libraryName` values but pointed to the same
|
|
10
|
+
bundle URL and section path, `createLoadExternalSync`/`createLoadExternalAsync` was
|
|
11
|
+
called once per external, causing `lynx.loadScript` to execute redundantly for the
|
|
12
|
+
same section. Now only the first external in each `(url, sectionPath)` group triggers
|
|
13
|
+
the load; subsequent externals in the group are assigned the already-loaded result
|
|
14
|
+
directly.
|
|
15
|
+
|
|
3
16
|
## 0.1.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
|
@@ -42,18 +55,18 @@
|
|
|
42
55
|
|
|
43
56
|
```js
|
|
44
57
|
// webpack.config.js
|
|
45
|
-
import { ExternalsLoadingPlugin } from
|
|
58
|
+
import { ExternalsLoadingPlugin } from "@lynx-js/externals-loading-webpack-plugin";
|
|
46
59
|
|
|
47
60
|
export default {
|
|
48
61
|
plugins: [
|
|
49
62
|
new ExternalsLoadingPlugin({
|
|
50
|
-
mainThreadLayer:
|
|
51
|
-
backgroundLayer:
|
|
63
|
+
mainThreadLayer: "main-thread",
|
|
64
|
+
backgroundLayer: "background",
|
|
52
65
|
externals: {
|
|
53
66
|
lodash: {
|
|
54
|
-
url:
|
|
55
|
-
background: { sectionPath:
|
|
56
|
-
mainThread: { sectionPath:
|
|
67
|
+
url: "http://lodash.lynx.bundle",
|
|
68
|
+
background: { sectionPath: "background" },
|
|
69
|
+
mainThread: { sectionPath: "main-thread" },
|
|
57
70
|
},
|
|
58
71
|
},
|
|
59
72
|
}),
|
package/lib/index.js
CHANGED
|
@@ -159,6 +159,10 @@ function createLoadExternalSync(handler, sectionPath, timeout) {
|
|
|
159
159
|
}
|
|
160
160
|
`;
|
|
161
161
|
const hasUrlLibraryNamePairInjected = new Set();
|
|
162
|
+
// Track which (urlKey, sectionPath) pairs have already generated a loadScript call.
|
|
163
|
+
// Maps to the mountVar of the first external that triggered the load, so subsequent
|
|
164
|
+
// externals sharing the same section can reuse the result without calling loadScript again.
|
|
165
|
+
const sectionLoadTracker = new Map();
|
|
162
166
|
for (const [pkgName, external] of finalExternals) {
|
|
163
167
|
const { libraryName, url, bundlePath, async = true, timeout: timeoutInMs = externalsLoadingPluginOptions.timeout
|
|
164
168
|
?? 2000, } = external;
|
|
@@ -189,6 +193,20 @@ function createLoadExternalSync(handler, sectionPath, timeout) {
|
|
|
189
193
|
: `${compiler.webpack.RuntimeGlobals.publicPath} + ${JSON.stringify(normalizedExternal.bundlePath)}`;
|
|
190
194
|
url2fetchCode.set(urlKey, `lynx.fetchBundle(${fetchExpr}, {});`);
|
|
191
195
|
const mountVar = `${getLynxExternalGlobal(externalsLoadingPluginOptions.globalObject)}[${JSON.stringify(libraryNameStr)}]`;
|
|
196
|
+
// If another external already generated a loadScript call for this exact
|
|
197
|
+
// (bundle, section, async) triple, reuse its result instead of calling
|
|
198
|
+
// loadScript again. async is included in the key because sync and async
|
|
199
|
+
// externals resolve to different runtime shapes (plain value vs Promise),
|
|
200
|
+
// so they must not be merged even when they share the same section.
|
|
201
|
+
const sectionKey = `${urlKey}||${layerOptions.sectionPath}||${async}`;
|
|
202
|
+
const existingMountVar = sectionLoadTracker.get(sectionKey);
|
|
203
|
+
if (existingMountVar !== undefined) {
|
|
204
|
+
// Preserve any value the host may have pre-populated for this global,
|
|
205
|
+
// matching the same === undefined guard used on the primary load path.
|
|
206
|
+
loadCode.add(`${mountVar} = ${mountVar} === undefined ? ${existingMountVar} : ${mountVar};`);
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
sectionLoadTracker.set(sectionKey, mountVar);
|
|
192
210
|
if (async) {
|
|
193
211
|
loadCode.add(`${mountVar} = ${mountVar} === undefined ? createLoadExternalAsync(handler${[...url2fetchCode.keys()].indexOf(urlKey)}, ${JSON.stringify(layerOptions.sectionPath)}) : ${mountVar};`);
|
|
194
212
|
continue;
|