New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

dotjs-loader

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dotjs-loader

doT.js module loader for webpack

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
865
289.64%
Maintainers
1
Weekly downloads
 
Created
Source

dotjs-loader

npm Build Status Codecov Downloads Issues

doT.js module loader for webpack

Usage

Installation

Install using npm. doT is a peer dependency and should be installed separately:

npm install --save-dev dot dotjs-loader

Configuration

Configure the loader in webpack.config.js:

module: {
  loaders: [{ test: /\.dot$/, loader: 'dotjs-loader' }];
}

... and then load templates using require():

const template = require('./template.dot');
// => compiles template.dot content as template function

console.log(template());

Or, using ES6 modules:

import template from './template.dot';
// template function is the default export

console.log(template());

Pass any template data to the function:

template({ key: 'value' });

Alternatively you can explicitly call the loader without having configured it:

const template = require('dotjs-loader!./file.dot');

Options

The following options are available. They map directly to doT.templateSettings unless stated otherwise:

  • evaluate
  • interpolate
  • encode
  • use
  • define
  • conditional
  • iterate
  • varname
  • strip
  • append

Options are most conveniently passed in webpack.config.js:

module: {
  loaders: [
    {
      test: /\.dot$/,
      loader: 'dotjs-loader',
      options: {
        varname: 'context',
      },
    },
  ];
}

Similar projects

dot-loader is another loader for doT templates, but it doesn't allow configuration of templateSettings. At the time of writing there was a PR to add this feature, but it suffered from some drawbacks:

  • it's not merged
  • it takes configuration from a .dotrc file rather than loader options
  • it doesn't mark that file as a loader dependency

I've also taken the opportunity to include unit tests and hope to add more features as time permits.

Keywords

webpack

FAQs

Package last updated on 02 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts