@hyperspan/framework 0.5.0 → 0.5.1
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/assets.js +2 -2
- package/dist/server.js +2 -2
- package/package.json +1 -1
- package/src/assets.ts +6 -2
- package/src/plugins.ts +2 -2
package/dist/assets.js
CHANGED
|
@@ -22,12 +22,12 @@ async function buildClientJS() {
|
|
|
22
22
|
const jsFile = output.outputs[0].path.split("/").reverse()[0];
|
|
23
23
|
clientJSFiles.set("_hs", { src: `${CLIENTJS_PUBLIC_PATH}/${jsFile}` });
|
|
24
24
|
}
|
|
25
|
-
function renderClientJS(module,
|
|
25
|
+
function renderClientJS(module, loadScript) {
|
|
26
26
|
if (!module.__CLIENT_JS) {
|
|
27
27
|
throw new Error(`[Hyperspan] Client JS was not loaded by Hyperspan! Ensure the filename ends with .client.ts to use this render method.`);
|
|
28
28
|
}
|
|
29
29
|
return html.raw(module.__CLIENT_JS.renderScriptTag({
|
|
30
|
-
|
|
30
|
+
loadScript: loadScript ? typeof loadScript === "string" ? loadScript : functionToString(loadScript) : undefined
|
|
31
31
|
}));
|
|
32
32
|
}
|
|
33
33
|
function functionToString(fn) {
|
package/dist/server.js
CHANGED
|
@@ -54,8 +54,8 @@ export const __CLIENT_JS = {
|
|
|
54
54
|
esmName: "${esmName}",
|
|
55
55
|
sourceFile: "${args.path}",
|
|
56
56
|
outputFile: "${result.outputs[0].path}",
|
|
57
|
-
renderScriptTag: ({
|
|
58
|
-
const fn =
|
|
57
|
+
renderScriptTag: ({ loadScript }) => {
|
|
58
|
+
const fn = loadScript ? (typeof loadScript === 'string' ? loadScript : \`const fn = \${functionToString(loadScript)}; fn(${fnArgs});\`) : '';
|
|
59
59
|
return \`<script type="module" data-source-id="${jsId}">import ${exports} from "${esmName}";
|
|
60
60
|
\${fn}</script>\`;
|
|
61
61
|
},
|
package/package.json
CHANGED
package/src/assets.ts
CHANGED
|
@@ -36,7 +36,7 @@ export async function buildClientJS() {
|
|
|
36
36
|
/**
|
|
37
37
|
* Render a client JS module as a script tag
|
|
38
38
|
*/
|
|
39
|
-
export function renderClientJS<T>(module: T,
|
|
39
|
+
export function renderClientJS<T>(module: T, loadScript?: ((module: T) => void) | string) {
|
|
40
40
|
// @ts-ignore
|
|
41
41
|
if (!module.__CLIENT_JS) {
|
|
42
42
|
throw new Error(
|
|
@@ -47,7 +47,11 @@ export function renderClientJS<T>(module: T, onLoad?: (module: T) => void | stri
|
|
|
47
47
|
return html.raw(
|
|
48
48
|
// @ts-ignore
|
|
49
49
|
module.__CLIENT_JS.renderScriptTag({
|
|
50
|
-
|
|
50
|
+
loadScript: loadScript
|
|
51
|
+
? typeof loadScript === 'string'
|
|
52
|
+
? loadScript
|
|
53
|
+
: functionToString(loadScript)
|
|
54
|
+
: undefined,
|
|
51
55
|
})
|
|
52
56
|
);
|
|
53
57
|
}
|
package/src/plugins.ts
CHANGED
|
@@ -71,8 +71,8 @@ export const __CLIENT_JS = {
|
|
|
71
71
|
esmName: "${esmName}",
|
|
72
72
|
sourceFile: "${args.path}",
|
|
73
73
|
outputFile: "${result.outputs[0].path}",
|
|
74
|
-
renderScriptTag: ({
|
|
75
|
-
const fn =
|
|
74
|
+
renderScriptTag: ({ loadScript }) => {
|
|
75
|
+
const fn = loadScript ? (typeof loadScript === 'string' ? loadScript : \`const fn = \${functionToString(loadScript)}; fn(${fnArgs});\`) : '';
|
|
76
76
|
return \`<script type="module" data-source-id="${jsId}">import ${exports} from "${esmName}";\n\${fn}</script>\`;
|
|
77
77
|
},
|
|
78
78
|
}
|