rollup-plugin-dot
raw JSON → 1.1.0 verified Mon Apr 27 auth: no javascript
Rollup plugin that compiles doT.js template files (.dot, .tpl) into JavaScript functions during bundling. Current stable version is 1.1.0. The plugin provides a seamless integration of doT templates with Rollup, enabling imports like `import view from './view.dot'`. It supports include/exclude patterns, custom doT template settings, and template defines. Key differentiators: minimal configuration, TypeScript type definitions included, and supports both .dot and .tpl extensions. Unlike alternatives, it focuses solely on doT without additional template engine overhead.
Common errors
error Error: Could not load ... (imported by ...): Cannot find module 'dot' ↓
cause Missing doT runtime dependency; 'dot' is a peer dependency.
fix
Run
npm install -D dot or yarn add -D dot error TypeError: dot is not a function ↓
cause Using named import `import { dot } from 'rollup-plugin-dot'` instead of default.
fix
Use
import dot from 'rollup-plugin-dot' error Error: Unexpected token (Note that you need plugins to import files that are not JavaScript) ↓
cause Rollup cannot process .dot files without the plugin.
fix
Add the dot plugin to the plugins array in rollup.config.js
Warnings
gotcha Default Export Only; Named Import Fails Silently ↓
fix Use default import: `import dot from 'rollup-plugin-dot'`
gotcha Exports Undefined if Named Export Used ↓
fix Use default import: `import dot from 'rollup-plugin-dot'`
gotcha Require Returns Function Directly, Not an Object ↓
fix Use `const dot = require('rollup-plugin-dot')` instead of destructuring
gotcha Only .dot Files Processed by Default ↓
fix Add `include: ['**/*.tpl']` to process .tpl files
gotcha Template Settings Are Passed to doT Compiler; Typos Not Validated ↓
fix Ensure templateSettings keys match doT documentation exactly
Install
npm install rollup-plugin-dot yarn add rollup-plugin-dot pnpm add rollup-plugin-dot Imports
- default wrong
import { dot } from 'rollup-plugin-dot'correctimport dot from 'rollup-plugin-dot' - dot wrong
const { dot } = require('rollup-plugin-dot')correctconst dot = require('rollup-plugin-dot') - DotPluginOptions
import type { DotPluginOptions } from 'rollup-plugin-dot'
Quickstart
// rollup.config.js
import dot from 'rollup-plugin-dot';
export default {
input: 'src/index.js',
output: {
file: 'dist/bundle.js',
format: 'iife',
},
plugins: [
dot({
include: ['**/*.dot'],
templateSettings: { strip: false },
defines: {
env: process.env.NODE_ENV || 'development',
},
}),
],
};