Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
babel-plugin-htmlbars-inline-precompile
Advanced tools
Babel plugin to replace tagged template strings with precompiled HTMLBars templates
The babel-plugin-htmlbars-inline-precompile package is a Babel plugin that allows you to precompile Handlebars templates inline within your JavaScript code. This is particularly useful in Ember.js applications where you want to use Handlebars templates directly in your JavaScript files.
Inline Precompilation of Handlebars Templates
This feature allows you to write Handlebars templates directly in your JavaScript code and have them precompiled at build time. This can improve performance by avoiding runtime compilation.
import hbs from 'htmlbars-inline-precompile';
const template = hbs`<div>{{name}}</div>`;
Integration with Ember.js
The plugin integrates seamlessly with Ember.js, allowing you to define component templates inline. This can make your code more modular and easier to manage.
import Component from '@glimmer/component';
import hbs from 'htmlbars-inline-precompile';
export default class MyComponent extends Component {
static template = hbs`<div>{{this.name}}</div>`;
}
The ember-cli-htmlbars package is an Ember CLI addon that provides Handlebars template compilation for Ember.js applications. Unlike babel-plugin-htmlbars-inline-precompile, which focuses on inline templates within JavaScript, ember-cli-htmlbars is more geared towards traditional .hbs template files.
The handlebars-loader package is a Webpack loader that precompiles Handlebars templates. It is similar to babel-plugin-htmlbars-inline-precompile in that it precompiles templates, but it is used in the context of Webpack rather than Babel.
Babel plugin to replace tagged .hbs
formatted strings with a precompiled version.
Can be used as either a normal function invocation or a tagged template string:
import hbs from 'htmlbars-inline-precompile';
hbs`some {{handlebarsthingy}}`;
hbs('some {{handlebarsthingy}}');
When used as a normal function invocation, you can pass additional options (e.g. to configure the resulting template's moduleName
metadata):
import hbs from 'htmlbars-inline-precompile';
hbs('some {{handlebarsthingy}}', { moduleName: 'some/path/to/file.hbs' });
var HTMLBarsCompiler = require('./bower_components/ember/ember-template-compiler');
var HTMLBarsInlinePrecompile = require('babel-plugin-htmlbars-inline-precompile');
require('babel').transform("code", {
plugins: [
[HTMLBarsInlinePrecompile, {precompile: HTMLBarsCompiler.precompile}],
],
});
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
module("my component", function(hooks) {
setupRenderingTest(hooks);
test('inline templates ftw', async function(assert) {
await render(hbs`hello!`);
assert.dom().hasText('hello!');
});
});
results in
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
module("my component", function(hooks) {
setupRenderingTest(hooks);
test('inline templates ftw', async function(assert) {
await render(Ember.HTMLBars.template(function() {
/* crazy HTMLBars template function stuff */
}));
assert.dom().hasText('hello!');
});
});
v4.0.1 (2020-05-06)
...
) (@chancancode)FAQs
Babel plugin to replace tagged template strings with precompiled HTMLBars templates
The npm package babel-plugin-htmlbars-inline-precompile receives a total of 170,645 weekly downloads. As such, babel-plugin-htmlbars-inline-precompile popularity was classified as popular.
We found that babel-plugin-htmlbars-inline-precompile demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.