template-bundler
raw JSON → 0.1.1 verified Sat Apr 25 auth: no javascript abandoned
Templates to TypeScript bundler (v0.1.1). Converts HTML files with script[type='text/template'] into a TypeScript module with a hash of stringified templates. Recursively crawls directories; generates internal modules. Highly specific utility; no active maintenance since 2016. Differentiator: direct TS output without runtime dependencies.
Common errors
error tb: command not found ↓
cause Package not installed globally or not in PATH.
fix
Run npm install -g template-bundler and ensure npm global bin is in PATH.
error Cannot find module 'output.ts' ↓
cause Generated output uses internal module syntax; cannot be imported with ES import.
fix
Use /// <reference path='./output.ts' /> in a TypeScript file that uses the module, or include output.ts in your tsconfig.json files list.
Warnings
breaking CLI arguments order is positional: directory, output file, module name. No flags or defaults. ↓
fix Provide all three arguments in the correct order: tb <dir> <output> <moduleName>
gotcha Generated code uses internal TypeScript modules (module X { export var Y }) which is a deprecated syntax. Cannot be used with ES module imports. ↓
fix Use /// <reference path='output.ts' /> or compile with --module amd/commonjs and include the file. Consider using a modern bundler instead.
deprecated Project is unmaintained since 2016. No updates for TypeScript 2+ or modern workflows. ↓
fix Evaluate alternative template bundlers like lit-html or handlebars-loader.
gotcha Input HTML files must have .html extension; directory is crawled recursively. ↓
fix Ensure templates have .template.html extension (recommended) or just .html.
Install
npm install template-bundler yarn add template-bundler pnpm add template-bundler Imports
- Templates wrong
import { Templates } from './output'correct/// <reference path='output.ts' /> - foo.bar wrong
Templates.foocorrectfoo.bar.Templates["foo"]
Quickstart
# Given a directory my-templates with Foo.template.html:
# <script type="text/template" id="foo"><h1>Foo</h1></script>
tb my-templates output.ts myModule
echo "Generated output.ts with module myModule { export var Templates = {...} }"