dynamic bundling

This commit is contained in:
Seth Trowbridge 2025-08-01 14:45:02 -04:00
parent e48f581b3c
commit eb12efae50
10 changed files with 151 additions and 184 deletions

File diff suppressed because one or more lines are too long

View File

@ -9,8 +9,7 @@
{
"work": "deno run -Ar ./scripts/dev_server.ts",
"scan": "deno run -Ar ./scripts/refresh_types.ts",
"html": "deno run -Ar ./scripts/scaffold.ts --html",
"make": "deno bundle --no-lock --platform=browser --inline-imports=true --output=bundle.js --minify src/bundle_entry.ts"
"html": "deno run -Ar ./scripts/scaffold.ts --html"
},
"imports":
{

24
dist/core.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,15 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- css reset --><style>*{margin:0;padding:0;box-sizing:border-box;}html, body{height:100%;width:100%;font-family:Arial, sans-serif;line-height:1.6;}body{-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;}img, video{max-width:100%;height:auto;}a{text-decoration:none;color:inherit;}ul, ol{list-style:none;}button, input, textarea{font-family:inherit;font-size:inherit;line-height:inherit;border:none;background:none;padding:0;margin:0;outline:none;}table{border-collapse:collapse;width:100%;}</style>
<script src="./bundle.js"></script>
<script>
console.log(Gale);
console.log(van);
console.log(vanX);
</script>
</head>
<body></body>
</html>

View File

@ -4,7 +4,11 @@ globalThis.van = Van;
import * as VanX from "npm:vanjs-ext@^0.6.3";
globalThis.vanX = VanX;
import Gale from "./gale.js";
import Gale from "../src/gale.js";
globalThis.Gale = Gale;
import "./hmr.js";
import BindHMR from "../src/hmr.js";
BindHMR();
import Boot from "../src/boot.js";
Boot();

View File

@ -1,8 +1,12 @@
const command = new Deno.Command("deno bundle", {});
const decode = new TextDecoder("utf-8");
const output = await command.output();
console.assert()
const command = new Deno.Command("deno", {
args:[
"bundle",
"--no-lock",
"--platform=browser",
"--inline-imports=true",
"--output=dist/core.js",
"--minify",
"scripts/bundle_entry.ts"
]
});
command.outputSync();

View File

@ -4,7 +4,7 @@ import {HTML} from "./assemble_files.ts";
// Parse the port from the command-line arguments, defaulting to 8000
const port = parseInt(Deno.args[0] || "8000", 10);
const sockets: WebSocket[] = [];
const devinc = await fetch(import.meta.resolve("../src/dev.js")).then(r=>r.text());
//const devinc = await fetch(import.meta.resolve("../src/dev.js")).then(r=>r.text());
let html: string;
try {
@ -12,7 +12,7 @@ try {
} catch (_) {
html = HTML;
}
html = html.replace("</head>", `<script>${devinc}</script></head>`);
//html = html.replace("</head>", `<script>${devinc}</script></head>`);
function extension(path: string): string {
// Remove trailing slash if it exists

View File

@ -1,7 +1,6 @@
(
(root="/")=>fetch(root+"deno.json")
.then(text=>text.json())
.then(json=>{
export default (root="/")=>fetch(root+"deno.json")
.then(text=>text.json())
.then(json=>{
const n=(t,e)=>{let n=document.createElement("script");n.type=t,n.textContent=e,document.head.appendChild(n)};
const imports = json.imports;
for(let n in imports)
@ -11,5 +10,4 @@
}
n("importmap",JSON.stringify({imports})),
n("module",'import "entry"; ')
})
)();
})

View File

@ -1,33 +0,0 @@
// added in devmode to index.html
new WebSocket('ws://'+window.location.host+'/ws').addEventListener('message',e=>e.data==='reload'&&window.location.reload());
vanX.Store =(obj, key)=>
{
let checkInit = JSON.stringify(obj);
let checkStore = localStorage.getItem(key+"check");
localStorage.setItem(key+"check", checkInit);
let recallJSON;
if(checkInit == checkStore)
{
let recallText = localStorage.getItem(key);
try
{
recallJSON = JSON.parse(recallText) || obj;
}
catch(e)
{
recallJSON = obj;
}
}
else
{
recallJSON = obj;
}
const store = vanX.reactive( recallJSON );
van.derive(() => localStorage.setItem(key, JSON.stringify(vanX.compact(store))));
return store;
}

View File

@ -1,50 +1,53 @@
export default {
Time: 0,
/** @type {Record<string, string>} */
Temp:{},
Tick()
let Time = 0;
/** @type {Record<string, string>} */
let Temp = {};
function Tick()
{
for(const k in Temp)
{
for(const k in HMR.Temp)
{
sessionStorage.setItem(k, HMR.Temp[k]);
sessionStorage.setItem(k, Temp[k]);
}
HMR.Temp = {};
HMR.Time = 0;
},
/** @type {(key:string, value:string)=>void} */
Save(key, value)
Temp = {};
Time = 0;
}
/** @type {(key:string, value:string)=>void} */
function Save(key, value)
{
Temp[key] = value;
if(!Time)
{
this.Temp[key] = value;
if(!this.Time)
{
this.Time = setTimeout(this.Tick, 500);
Time = setTimeout(Tick, 500);
}
console.log("SAVE", key, value);
},
/** @type {(key:string)=>string|null} */
Load(key)
{
};
/** @type {(key:string)=>string|null} */
function Load(key)
{
const value = sessionStorage.getItem(key);
console.log("LOAD", key, value);
return value;
},
}
/** @type {string|undefined} */
_ID: undefined,
_index: 0,
/** @type {(id:string|undefined = undefined)=>void} */
StartID(id)
{
this._index = 0;
this._ID = id;
},
NextID()
{
return this._ID ? this._ID + "_" + (this._index++) + "_" : "";
},
/** @type {string|undefined} */
let _ID = undefined;
let _index = 0;
BindVan()
{
/** @type {(id:string|undefined = undefined)=>void} */
function StartID(id)
{
_index = 0;
_ID = id;
}
function NextID()
{
return _ID ? _ID + "_" + (_index++) + "_" : "";
}
export default()=>{
//bind Van
const origninalState = globalThis.van.state;
globalThis.van.state =(value, key="")=>
@ -65,26 +68,54 @@ export default {
break;
}
const fullKey = "HMR_" + HMR.NextID() + key;
const stringValue = HMR.Load(fullKey);
const fullKey = "HMR_" + NextID() + key;
const stringValue = Load(fullKey);
const signal = origninalState((stringValue ? reader(stringValue) : value));
van.derive(()=>HMR.Save(fullKey, writer(signal.val)));
van.derive(()=>Save(fullKey, writer(signal.val)));
return signal;
};
},
BindVanX()
{
//bind VanX
const originalReactive = globalThis.vanX.reactive;
globalThis.vanX.reactive =(obj, id)=>
{
HMR.StartID(id);
StartID(id);
const state = originalReactive(obj);
HMR.StartID();
StartID();
return state;
}
// added in devmode to index.html
new WebSocket('ws://'+window.location.host+'/ws').addEventListener('message',e=>e.data==='reload'&&window.location.reload());
vanX.Store =(obj, key)=>
{
let checkInit = JSON.stringify(obj);
let checkStore = localStorage.getItem(key+"check");
localStorage.setItem(key+"check", checkInit);
let recallJSON;
if(checkInit == checkStore)
{
let recallText = localStorage.getItem(key);
try
{
recallJSON = JSON.parse(recallText) || obj;
}
catch(e)
{
recallJSON = obj;
}
}
else
{
recallJSON = obj;
}
const store = vanX.reactive( recallJSON );
van.derive(() => localStorage.setItem(key, JSON.stringify(vanX.compact(store))));
return store;
}
}