ember-cli-defeatureify
ember-cli-defeatureify copied to clipboard
Defeatureify templates
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:
- [ ] Do we have the tools in ember-cli to do this? If not, what is needed should be identified and then issues created there to get it working.
- [ ] Syntax. It doesn't really matter as it will be stripped, but maybe it should look like handlebars for syntax highlighting's sake? Or maybe it shouldn't, so it's clear it's not a part of the template?
There were some interest in solving this by @rwjblue, @mmun and @alexBaizeau
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...
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.
I think it would be nice to have also removing whole template files .hbs from production code when certain feature is disabled.
@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?