@umijs/renderer-react 4.0.6 → 4.0.7
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/dist/browser.js +24 -18
- package/package.json +1 -1
package/dist/browser.js
CHANGED
|
@@ -84,25 +84,31 @@ export function renderClient(opts) {
|
|
|
84
84
|
const manifest = window.__umi_manifest__;
|
|
85
85
|
if (manifest) {
|
|
86
86
|
const routeIdReplaced = id.replace(/[\/\-]/g, '_');
|
|
87
|
-
const preloadId =
|
|
87
|
+
const preloadId = `preload-${routeIdReplaced}.js`;
|
|
88
88
|
if (!document.getElementById(preloadId)) {
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
89
|
+
const keys = Object.keys(manifest).filter((k) => k.startsWith(routeIdReplaced + '.'));
|
|
90
|
+
keys.forEach((key) => {
|
|
91
|
+
if (!/\.(js|css)$/.test(key)) {
|
|
92
|
+
throw Error(`preload not support ${key} file`);
|
|
93
|
+
}
|
|
94
|
+
let file = manifest[key];
|
|
95
|
+
const link = document.createElement('link');
|
|
96
|
+
link.rel = 'preload';
|
|
97
|
+
link.as = 'style';
|
|
98
|
+
if (key.endsWith('.js')) {
|
|
99
|
+
link.as = 'script';
|
|
100
|
+
link.id = preloadId;
|
|
101
|
+
}
|
|
102
|
+
// publicPath already in the manifest,
|
|
103
|
+
// but if runtimePublicPath is true, we need to replace it
|
|
104
|
+
if (opts.runtimePublicPath) {
|
|
105
|
+
file = file.replace(new RegExp(`^${opts.publicPath}`),
|
|
106
|
+
// @ts-ignore
|
|
107
|
+
window.publicPath);
|
|
108
|
+
}
|
|
109
|
+
link.href = file;
|
|
110
|
+
document.head.appendChild(link);
|
|
111
|
+
});
|
|
106
112
|
}
|
|
107
113
|
}
|
|
108
114
|
// server loader
|
package/package.json
CHANGED