feat: script HMR
This commit is contained in:
parent
a2a33536e7
commit
782fdfc28c
|
@ -39,7 +39,13 @@ export default class Script {
|
|||
if (!fn) {
|
||||
return undefined;
|
||||
}
|
||||
return new this(fn, locals);
|
||||
const script = new this(fn, locals);
|
||||
if (import.meta.hot) {
|
||||
import.meta.hot.accept('./scripts.js', ({default: scripts}) => {
|
||||
script.fn = scripts[`../..${pathOrFunction}`];
|
||||
});
|
||||
}
|
||||
return script;
|
||||
}
|
||||
|
||||
static register(path, fn) {
|
||||
|
@ -101,11 +107,16 @@ export default class Script {
|
|||
|
||||
}
|
||||
|
||||
const imports = import.meta.glob(
|
||||
'../../resources/**/*.js',
|
||||
{eager: true, import: 'default'},
|
||||
);
|
||||
|
||||
for (const path in imports) {
|
||||
Script.register(path.slice('../..'.length), imports[path]);
|
||||
function register({default: scripts}) {
|
||||
for (const path in scripts) {
|
||||
Script.register(path.slice('../..'.length), scripts[path]);
|
||||
}
|
||||
}
|
||||
|
||||
register(await import('./scripts.js'));
|
||||
|
||||
if (import.meta.hot) {
|
||||
import.meta.hot.accept('./scripts.js', (M) => {
|
||||
register(M);
|
||||
});
|
||||
}
|
||||
|
|
5
app/util/scripts.js
Normal file
5
app/util/scripts.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
export default import.meta.glob(
|
||||
'../../resources/**/*.js',
|
||||
{eager: true, import: 'default'},
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user