-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
30 lines (27 loc) · 950 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { tagYaz } from "../util/html";
import { splitFullExt } from "../util/paths";
import compiler from "./compiler/compiler";
import { getGlobals } from "./compiler/pageGlobals";
/**
* @param {Object} props
* @return {!Promise<string>}
*/
const Script = (props) => {
const globals = getGlobals();
for (const key in props)
if (key.charCodeAt(0) < 91) globals[key] = props[key];
const [file, ext] = splitFullExt(props.src);
const targetName = `/build/${file}-${props.Lang}.${ext}`;
return Promise.all([].concat(props.children ?? [])).then(() =>
compiler.bundleTarget(targetName, {
dynamicDeps: true,
childTargets: ["/" + props.src], // Used in BuildMode.Dev only
...props,
...globals
}).then((bundleName) => {
if (props.bundleKey) globals[props.bundleKey] = bundleName;
return tagYaz("script", { type: "module", src: bundleName }, false) + "</script>"
})
);
}
export { Script };