简体   繁体   中英

How to compile glimmer2 template for Ember 2.8+

Recently we have started a wide scale upgrade of our EmberJS system. And currently we are at 2.11 version of ember. With EmberJS 2.11

Ember.HTMLBars.template

and

Ember.Handlebars.template

all come via a single template function and expect JSON (ie. compiled glimmer2 template)

Currently trying to get a simple "Hello world" message appeared. I have routes working, but Ember.HTMLBars.template expect glimmer2 JSON.

How do I make "Hello world" glimmer template and compile it to JSON?

Ember expects JSON something like

Ember.TEMPLATES["test/fixtures/simple"] = Ember.HTMLBars.template({"id":null,"block":"{\"statements\":[[\"open-element\",\"p\",[]],[\"flush-element\"],[\"text\",\"Hello, my name is \"],[\"append\",[\"unknown\",[\"name\"]],false],[\"text\",\".\"],[\"close-element\"]],\"locals\":[],\"named\":[],\"yields\":[],\"blocks\":[],\"hasPartials\":false}","meta":{}});

I have got https://github.com/tildeio/glimmer built, but not sure what to do next. At the end, I need to get basic hello_world.hbs to compile into JSON. I am a very new person in this area.

Any help appreciated

Thank you

Dimi

Not sure what the purpose of this is.

You can use ember-cli-htmlbars-inline-precompile to precompile a template like

const layout = hbs`{{if foo "bar" "baz"}}`;

Yeah, that's valid JS. See tagged template strings .

Then you can use the compiled template in a component like this:

import Component from 'ember-component';

export default Component.extend({
  layout;
});

There might be better options. Please read http://xyproblem.info , then provide details about your original problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM