jkarsrud / ember-cli-defeatureify

Ember-CLI addon to defeatureify your apps
MIT License
18 stars 6 forks source link

Defeatureify templates #12

Open kimroen opened 9 years ago

kimroen commented 9 years ago

Here's a thing that would be great to get working: Stripping out parts of templates based on features being enabled or disabled. This originated as a discussion in this issue: https://github.com/ember-cli/ember-cli/issues/3200

Things to figure out:

There were some interest in solving this by @rwjblue, @mmun and @alexBaizeau

kimroen commented 9 years ago

https://github.com/ember-cli/ember-cli/issues/3200#issuecomment-73380479:

I've been chatting with @mmun and I think we can also make a way to do the same kind of stripping for templates (by walking the AST on precompile), ember-cli-defeatureify seems like a great place for this...

jkarsrud commented 9 years ago

I've been thinking a little bit about how this could be done, and perhaps a Handlebars block helper registered by this addon could be a solution?

{{#is-feature-enabled "some-feature"}}
Template code to include or strip out
{{/is-feature-enabled}}

For a production build, I guess this feature would need to check the template AST for that particular BlockStatement, check its params against the features, include or strip it, and then pass that new AST through to the actual template compiler. For development, the helper itself would just do the same kind of check as you would in your JS, but it would also need to know about the namespace that holds the FEATURES object.

I'm not sure if there's an appropriate hook in ember-cli at the moment, though.

e00dan commented 9 years ago

I think it would be nice to have also removing whole template files .hbs from production code when certain feature is disabled.

mmun commented 9 years ago

@jkarsrud Yes that's how I'd do it. Keep in mind that AST transforms are not intended to be public yet (the AST is still in flux, awaiting for glimmer to merge) but any breaking changes should be relatively easy to stay on top of. You can check out ember-cli-htmlbars to see how they register AST plugins.

@rwjblue What do you think about using -ast for the registry key? Too late?