From 41c8e30e2a80e283ef903dce1226c7053e0419e4 Mon Sep 17 00:00:00 2001 From: Jason Mitchell <jason.mitchell.w@gmail.com> Date: Thu, 12 May 2016 22:38:22 -0700 Subject: [PATCH] Update README --- README.md | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 46497960..fad610f3 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,32 @@ var HTMLBarsInlinePrecompile = require('babel-plugin-htmlbars-inline-precompile' var pluginConfiguredWithCompiler = HTMLBarsInlinePrecompile(HTMLBarsCompiler.precompile); require('babel').transform("code", { - plugins: [ pluginConfiguredWithCompiler ] + plugins: [ pluginConfiguredWithCompiler] +}); +``` + +### Passing options to the precompiler + +As of 0.0.6, there is now the ability to pass options to the HTMLBars precompiler. + +This enables passing `moduleName`, which can be used to retrieve from within the compiled template where it originated from. + +``` js +var HTMLBarsCompiler = require('./bower_components/ember/ember-template-compiler'); +var HTMLBarsInlinePrecompile = require('babel-plugin-htmlbars-inline-precompile'); + +var pluginConfiguredWithCompiler = HTMLBarsInlinePrecompile(HTMLBarsCompiler.precompile, { + precompileOptions: function(opts) { + // example of moduleName generation + var sourceRootRegEx = new RegExp("^" + opts.sourceRoot + "/?"); + + return { + moduleName: opts.filenameRelative.replace(sourceRootRegEx, "") + }; + } +}); + +require('babel').transform("code", { + plugins: [ pluginConfiguredWithCompiler] }); ```