rollup-plugin-underscorify

raw JSON →
1.0.0 verified Mon Apr 27 auth: no javascript

A Rollup plugin (v1.0.0, single release) that converts Underscore templates into ES modules for use in Backbone/Marionette apps. Unlike other template compilers, it forces explicit namespace variable access (no `with` statement) to maintain ES2015 strict mode compatibility. Requires manual injection of Underscore or other libraries into template scope, as Rollup's module bundling can't guarantee global access. Minimal configuration with include/exclude patterns and custom variable name. Stable but essentially feature-complete.

error Error: Cannot find module 'rollup-plugin-underscorify'
cause Package not installed or only installed as devDependency but not available in build environment.
fix
Run npm install rollup-plugin-underscorify --save-dev and ensure node_modules path is correct.
error SyntaxError: Unexpected token 'export'
cause Using CJS require with an ESM-only package.
fix
Use import syntax in your Rollup config (requires Rollup ESM config support).
error TypeError: underscorify is not a function
cause Using named import `underscorify` instead of default import.
fix
Change import to import underscorify from 'rollup-plugin-underscorify'.
gotcha Namespace variable (e.g., `p`) MUST be used inside templates to access data; raw property names like `<%= username %>` will be undefined.
fix Always prefix data properties with the configured variable, e.g., `<%= p.username %>`.
gotcha Underscore (`_`) or any other library used inside templates must be explicitly passed in the data object. Rollup does not guarantee global import availability.
fix Pass `_` as part of the template data, e.g., `tplData._ = _;`.
gotcha The plugin compiles templates to ES modules; ensure your Rollup config outputs a format (e.g., iife, umd) that supports module imports if used in browsers.
fix Use a suitable `output.format` like 'iife' or 'umd'.
gotcha `with` statement is not used, so template code must reference data through the variable; this avoids strict mode issues but changes template syntax from standard Underscore templates.
fix Always use variable prefix (e.g., `p.`) in template expressions.
npm install rollup-plugin-underscorify
yarn add rollup-plugin-underscorify
pnpm add rollup-plugin-underscorify

Shows minimal Rollup config using the plugin to compile .tpl files into Underscore template modules.

import underscorify from 'rollup-plugin-underscorify';

export default {
  input: 'index.js',
  output: { file: 'bundle.js', format: 'iife' },
  plugins: [
    underscorify({
      include: ['**/*.tpl'],
      variable: 'p'
    })
  ]
};