@webhandle/external-resource-manager 1.0.0 → 1.0.2
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/README.md
CHANGED
|
@@ -188,6 +188,27 @@ code to create an importmap based on mime type `application/javascript` with res
|
|
|
188
188
|
so extensability is really easy if you wanted to add `meta` element or `title` element handling
|
|
189
189
|
(or something).
|
|
190
190
|
|
|
191
|
+
### Data URLs
|
|
192
|
+
|
|
193
|
+
It's also possible to pass data as part of the provided resource. This is good if you need a configuration
|
|
194
|
+
for the javascript on the page. Be careful with this though because it can result in some really big pages.
|
|
195
|
+
|
|
196
|
+
```js
|
|
197
|
+
externalResourceManager.provideResource({
|
|
198
|
+
mimeType: 'application/javascript'
|
|
199
|
+
, resourceType: 'module'
|
|
200
|
+
, name: '@webhandle/moduleone/configuration'
|
|
201
|
+
, data: {url: '/something/here'}
|
|
202
|
+
})
|
|
203
|
+
```
|
|
204
|
+
It results in an importmap entry like:
|
|
205
|
+
|
|
206
|
+
```
|
|
207
|
+
"@webhandle/module-one/configuration":"data:text/javascript,export default {\"url\":\"/something/here\"}"
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
191
212
|
|
|
192
213
|
### Integration
|
|
193
214
|
|
|
@@ -6,7 +6,12 @@ export default function createApplicationJavascriptRenderer(webhandle) {
|
|
|
6
6
|
|
|
7
7
|
let vrsc = ''
|
|
8
8
|
if (!webhandle.development && resource.cachable) {
|
|
9
|
-
|
|
9
|
+
if (resource.url.startsWith('data:')) {
|
|
10
|
+
// We don't want to prefix a data url
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
vrsc = '/vrsc/' + webhandle.resourceVersion
|
|
14
|
+
}
|
|
10
15
|
}
|
|
11
16
|
|
|
12
17
|
let html = `<script src="${vrsc}${escapeAttributeValue(resource.url)}" `
|
package/create-css-renderer.mjs
CHANGED
|
@@ -2,12 +2,17 @@ import createAttributes from "./create-attributes.mjs"
|
|
|
2
2
|
import escapeAttributeValue from "./escape-attribute-value.mjs"
|
|
3
3
|
export default function createTextCssRenderer(webhandle) {
|
|
4
4
|
function renderTextCss(resource) {
|
|
5
|
-
|
|
5
|
+
|
|
6
6
|
let vrsc = ''
|
|
7
|
-
if(!webhandle.development && resource.cachable) {
|
|
8
|
-
|
|
7
|
+
if (!webhandle.development && resource.cachable) {
|
|
8
|
+
if (resource.url.startsWith('data:')) {
|
|
9
|
+
// We don't want to prefix a data url
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
vrsc = '/vrsc/' + webhandle.resourceVersion
|
|
13
|
+
}
|
|
9
14
|
}
|
|
10
|
-
|
|
15
|
+
|
|
11
16
|
let html = `<link href="${vrsc}${escapeAttributeValue(resource.url)}" rel="stylesheet" `
|
|
12
17
|
|
|
13
18
|
html += createAttributes(resource.attributes)
|
|
@@ -10,9 +10,21 @@ export default function createImportmapGenerator(webhandle) {
|
|
|
10
10
|
continue
|
|
11
11
|
}
|
|
12
12
|
found = true
|
|
13
|
+
|
|
14
|
+
if(resource.data && !resource.url) {
|
|
15
|
+
let content = `export default ${JSON.stringify(resource.data)}`
|
|
16
|
+
let url = `data:text/javascript,${content}`
|
|
17
|
+
resource.url = url
|
|
18
|
+
}
|
|
19
|
+
|
|
13
20
|
let vrsc = ''
|
|
14
21
|
if(!webhandle.development && resource.cachable) {
|
|
15
|
-
|
|
22
|
+
if(resource.url && resource.url.startsWith('data:')) {
|
|
23
|
+
// We don't want to prefix a data url
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
vrsc = '/vrsc/' + webhandle.resourceVersion
|
|
27
|
+
}
|
|
16
28
|
}
|
|
17
29
|
if (resource.mimeType === 'application/javascript' && resource.resourceType === 'module') {
|
|
18
30
|
imports[resource.name] = vrsc + resource.url
|