babel-plugin-htmlbars-inline-precompile

5.3.1 • Public • Published

babel-plugin-htmlbars-inline-precompile

Build Status

Babel plugin to replace tagged .hbs formatted strings with a precompiled version.

Requirements

  • Node 8+
  • Ember 2.10+
  • Babel 7

Usage

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' });

Babel Plugin Usage

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}],
  ],
});

Example

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!');
  });
});

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
5.3.152,248latest

Version History

VersionDownloads (Last 7 Days)Published
5.3.152,248
5.3.03,105
5.2.2249
5.2.184
5.2.01
5.1.04
5.0.0104
4.4.61,218
4.4.559
4.4.426
4.4.30
4.4.20
4.4.12
4.4.00
4.3.0171
4.2.11,807
3.2.026,727
4.2.01,055
4.1.085
4.0.11
4.0.00
3.1.01,640
3.0.11,859
3.0.0231
2.1.1408
2.1.04
2.0.023
1.0.011,185
0.2.66,771
0.2.599
0.2.4181
0.1.1705
0.2.32,779
0.2.20
0.2.10
0.2.00
0.1.0104
0.0.51,218
0.0.484
0.0.30
0.0.21
0.0.13

Package Sidebar

Install

npm i babel-plugin-htmlbars-inline-precompile

Weekly Downloads

77,486

Version

5.3.1

License

MIT

Unpacked Size

78.5 kB

Total Files

9

Last publish

Collaborators

  • rwjblue
  • turbo87
  • stefanpenner
  • ember-cli