mikado icon indicating copy to clipboard operation
mikado copied to clipboard

Question about nested partial module loading

Open hsnoil opened this issue 1 year ago • 6 comments

Currently, to load up partials you need to do:

import { register } from "./dist/module/mikado.js"
import tpl_header from "./tpl/header.es6.js";

register(tpl_header);
<main>
<section include="header"></section>
</main>

Is there any reason why the template compiler can't have an option to auto import and register all includes that show up in the template? Otherwise you have to manually import all nested partials. To be clear I mean nested template files, not tags.

hsnoil avatar Jan 21 '24 23:01 hsnoil

Just the ES5 version do automatically register named templates. A module can't, because the template module otherwise needs to import Mikado from a irregular file path.

ts-thomas avatar Jan 22 '24 13:01 ts-thomas

If you came up with an idea, let me know :)

ts-thomas avatar Jan 22 '24 14:01 ts-thomas

Though when you bundle it, doesn't it resolve the path to Mikado?

hsnoil avatar Jan 22 '24 17:01 hsnoil

A template function basically looks like:

export default {
    name: "app",
    tpl: {},
    fn: []
}

We can't just import Mikado on top, because templates are nested in different folders and I would like to support the browser native ES6 module resolution. The ES5 version bundles everything on window.Mikado, that's why es5 compiled templates will automatically register (they need, because here we can't import).

ts-thomas avatar Jan 22 '24 17:01 ts-thomas

So how about an optional flag that if someone wants to bundle their stuff it would register it?

hsnoil avatar Jan 22 '24 17:01 hsnoil

That sounds good. I will add a compiler flag to set Mikado source root, so it can automatically register then. 👍

ts-thomas avatar Jan 22 '24 17:01 ts-thomas