Component & stache file structure

When migrating from v2.3 to v3 and trying to keep a similar neat component-based folder and file structure (as per the old tutorial), how do we load data from the stache file? We previously used can.view to load the template file but with can.stache this isn’t supported? Maybe I’m missing something?

I’ve got a new separate component js file, is it best to include the stache template directly in the component view as per the below example as this doesn’t seem as neat as before.

  tag: "my-tabs",
view: stache("<ul>{{#panels}}<li>{{title}}</li> ...")

An alternative is the below method but where do we load the stache file in this instance so that it sits neatly with the component?



If you are using StealJS to load your modules, you should use steal-stache to load your templates.

thanks @phillipskevin

We aren’t using steal and are loading Can from the CDN. Is there recommended way to load components in this scenario? I’ll investigate using StealJS and steal-stache though if that’s the way to go.

@phillipskevin can correct me on this, but I think the recommended way to load template files is through your module loader.

For StealJS, that’d be using steal-stache:

For webpack, something like this:


@pauldjackson, are you using a module loader for your files, or just <script> tags?

Thanks @chasen. Sorry I should have mentioned that, we’re just using <script> tags.

You can simply use the fetch API to get the stache template raw data

We should have better documentation on this. I created an issue for improving the migration guide:

If someone has the time to pick it up, please just assign it to yourself, otherwise I’ll try to get to it this week.