@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.
Files changed (2) hide show
  1. package/dist/browser.js +24 -18
  2. 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 = 'preload-' + routeIdReplaced;
87
+ const preloadId = `preload-${routeIdReplaced}.js`;
88
88
  if (!document.getElementById(preloadId)) {
89
- const key = Object.keys(manifest).find((k) => k.startsWith(routeIdReplaced + '.'));
90
- if (!key)
91
- return;
92
- let file = manifest[key];
93
- const link = document.createElement('link');
94
- link.id = preloadId;
95
- link.rel = 'preload';
96
- link.as = 'script';
97
- // publicPath already in the manifest,
98
- // but if runtimePublicPath is true, we need to replace it
99
- if (opts.runtimePublicPath) {
100
- file = file.replace(new RegExp(`^${opts.publicPath}`),
101
- // @ts-ignore
102
- window.publicPath);
103
- }
104
- link.href = file;
105
- document.head.appendChild(link);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/renderer-react",
3
- "version": "4.0.6",
3
+ "version": "4.0.7",
4
4
  "description": "@umijs/renderer-react",
5
5
  "homepage": "https://github.com/umijs/umi/tree/master/packages/renderer-react#readme",
6
6
  "bugs": "https://github.com/umijs/umi/issues",