Registry / web-framework / kdu-template-compiler

kdu-template-compiler

JSON →
library2.7.16jsnpmunverified

Pre-compiles Kdu 2.0 templates into render functions to avoid runtime compilation overhead and support CSP restrictions. v2.7.16 is the latest stable release. The package is auto-generated from the main Kdu repo. Compiles templates to JavaScript code with `with` statements, not compatible with strict mode. Provides `compile` and `compileToFunctions` methods. Unlike the full build, this allows compile-time optimization and directive transformations. Deprecated `preserveWhitespace` option (use `whitespace` instead). Ships TypeScript types.

npm install kdu-template-compiler
INSTALL
IMPORT
SIG · KDU-TEMPLATE-COMPI
K
kdu-template-compiler
web-frameworkjavascriptv2.7.16
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

compile
const { compile } = require('kdu-template-compiler')
import { compile } from 'kdu-template-compiler'
CJS-only package; ESM import will fail. Use require or bundler that handles CJS.
compileToFunctions
const { compileToFunctions } = require('kdu-template-compiler')
import compileToFunctions from 'kdu-template-compiler'
Named export, not default. Also accessed via require.
compiler
const compiler = require('kdu-template-compiler')
import compiler from 'kdu-template-compiler'
Common pattern: import entire module as 'compiler' object.

Shows how to require the package, use compile() to get render function string, and compileToFunctions() to get instantiated functions.

const compiler = require('kdu-template-compiler'); const template = '<div>{{ message }}</div>'; const result = compiler.compile(template); console.log(result.render); // 'with(this){return _c("div",[_v(_s(message))])}' const html = '<p k-if="ok">yes</p>'; const compiled = compiler.compile(html); console.log(compiled.errors); // [] console.log(compiled.render); const { compileToFunctions } = require('kdu-template-compiler'); const { render, staticRenderFns } = compileToFunctions('<div>{{ msg }}</div>'); // render is a function, can be used in Kdu options const vm = new Kdu({ render, data: { msg: 'hello' } });
Debug
Known issues
deprecatedOption `preserveWhitespace` is deprecated and will be removed in future versions. Use `whitespace` instead.
fix
Replace `preserveWhitespace` with `whitespace: 'preserve'` or `whitespace: 'condense'`.
affects: >=2.6.0
gotchaCompiled render function uses `with` statement, which is forbidden in strict mode code and may be disabled in some environments (e.g. ES modules).
fix
Use the runtime-only build of Kdu with pre-compiled render functions, or use `kdu-loader` which handles compilation.
affects: >=2.0.0
gotchaDo not use ESM `import`; this package only provides CommonJS exports. Using `import` will fail.
fix
Use `require()` or ensure your bundler handles CJS packages.
affects: >=2.0.0
breakingIn Kdu 3, the template compiler is completely different and is not compatible with kdu-template-compiler v2. This package only works with Kdu 2.
fix
Use @kdujs/compiler-sfc for Kdu 3 template compilation.
affects: >=3.0.0
Errors
Common errors & fixes
Cannot find module 'kdu-template-compiler'
Package not installed or incorrectly required in ESM context.
fix
Run `npm install kdu-template-compiler` and use `const compiler = require('kdu-template-compiler')`.
TypeError: compiler.compile is not a function
Importing default export instead of named exports.
fix
Use `const { compile } = require('kdu-template-compiler')` or `const compiler = require('kdu-template-compiler')` then `compiler.compile()`.
SyntaxError: With statement cannot be used in strict mode
Using compiled render function code in an ES module or 'use strict' context.
fix
Pre-compile templates with Kdu SFC loader (e.g., kdu-loader) or use the runtime-only build of Kdu.
Upgrade
Version history
2.7.16latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
kdu-template-compiler — npm install kdu-template-compiler · libregistry