What is babel-plugin-ember-template-compilation?
The babel-plugin-ember-template-compilation package is a Babel plugin designed to precompile Ember.js templates. This plugin allows developers to write templates in a more concise and readable format, which are then compiled into JavaScript functions that can be used within Ember applications.
What are babel-plugin-ember-template-compilation's main functionalities?
Precompiling Templates
This feature allows you to precompile Ember.js templates using the Ember template compiler. The precompiled templates are then transformed into JavaScript functions that can be used within your Ember application.
module.exports = function (babel) {
return {
plugins: [
['babel-plugin-ember-template-compilation', {
precompile: require('ember-source/dist/ember-template-compiler').precompile
}]
]
};
};
Custom Template Compiler
This feature allows you to use a custom template compiler instead of the default Ember template compiler. This can be useful if you have specific requirements for how your templates should be compiled.
module.exports = function (babel) {
return {
plugins: [
['babel-plugin-ember-template-compilation', {
precompile: customTemplateCompiler
}]
]
};
};
function customTemplateCompiler(templateString) {
// Custom compilation logic
return compiledTemplate;
}
Other packages similar to babel-plugin-ember-template-compilation
ember-cli-htmlbars
The ember-cli-htmlbars package is an Ember CLI addon that provides a preprocessor for compiling Handlebars templates in Ember.js applications. It is similar to babel-plugin-ember-template-compilation in that it precompiles templates, but it is specifically designed to work with Ember CLI and integrates more tightly with the Ember build process.
babel-plugin-htmlbars-inline-precompile
The babel-plugin-htmlbars-inline-precompile package is a Babel plugin that allows you to precompile Handlebars templates inline within JavaScript files. It is similar to babel-plugin-ember-template-compilation in that it precompiles templates, but it is designed to be used directly within JavaScript files rather than as part of a broader build process.
babel-plugin-ember-template-compilation
Babel plugin that implements Ember's low-level template-compilation API.
Requirements
Usage
This plugin implements precompileTemplate
from RFC 496:
import { precompileTemplate } from '@ember/template-compilation';
For backward compatibility, it also has an enableLegacyModules
option that can enable each of these widely-used older patterns:
import { hbs } from 'ember-cli-htmlbars';
import hbs from 'ember-cli-htmlbars-inline-precompile';
import hbs from 'htmlbars-inline-precompile';
Common Options
This package has both a Node implementation and a portable implementation that works in browsers. Both implementations share these common options:
interface Options {
outputModuleOverrides?: Record<string, Record<string, [string, string]>>;
enableLegacyModules?: LegacyModuleName[];
}
type LegacyModuleName =
| 'ember-cli-htmlbars'
| 'ember-cli-htmlbars-inline-precompile'
| 'htmlbars-inline-precompile';
Node Options
When used in Node, the Options are extended to include:
interface NodeOptions extends Options {
precompilerPath?: string;
precompile?: EmberPrecompile;
}
type EmberPrecompile = (templateString: string, options: Record<string, unknown>) => string;
Browser Options
For use in non-Node environments including browsers, when you import from this package you get a factory function that takes a callback and returns the plugin. Your callback receives the babel plugin options and should return the precompile: EmberPrecompile
function as defined above.
import makePlugin from 'babel-plugin-ember-template-compilation';
import * as babel from '@babel/core';
babel.transform(someCode, { plugins: [makePlugin(loadTemplateCompiler)] });
Acknowledgement / History
This repo derives from https://github.com/ember-cli/babel-plugin-htmlbars-inline-precompile