# template-literals-loader

> module for webpack

Latest version **1.1.2** (published 2018-01-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install template-literals-loader
pnpm add template-literals-loader
yarn add template-literals-loader
bun add template-literals-loader
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2018-01-20 |
| First published | 2017-08-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Den Sumbaev @sumbad |
| Maintainers | sumbad |
| Keywords | webpack, tagged, template, literals |

## Links

- npm: https://www.npmjs.com/package/template-literals-loader
- Repository: https://github.com/sumbad/template-literals-loader
- Homepage: https://github.com/sumbad/template-literals-loader#readme
- Issues: https://github.com/sumbad/template-literals-loader/issues
- npm.io page: https://npm.io/package/template-literals-loader

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 1.1.2 (latest) — 2018-01-20
- 1.1.1 — 2018-01-19
- 1.1.0 — 2018-01-19
- 1.0.0 — 2017-10-28
- 0.1.1 — 2017-08-22
- 0.0.1 — 2017-08-22

## README

<div align="center">
    <h1>Template literals loader</h1>
</div>

The `template-literals-loader` is a module for webpack to use [Template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) as HTML template from a separate file.

This plugin adds a wrapper to a template file and returns it as a function.

## Installation

`npm install template-literals-loader -D`

## Usage



If you want to use this module with new browsers you can just setting webpack.

**webpack.config.js**
``` javascript
...
{
    test: /\.html?$/,
    loader: "template-literals-loader"
},
...
```

## Examples


**template.html**
``` html
<h1>Hello, ${name}</h1>
```

**main.js**  with tagged template literals
``` javascript
const template = require('./template.html');

function myTagFunc(chunks, ...interpolations) {
  console.log(chunks);
  console.log(interpolations);
}

const config = { 
  scope: {name: 'world'}, // optional
  tag: myTagFunc          // optional
};

template(config);
```

The result:

``` javascript
// ["<h1>Hello, ", "</h1>", raw: ["<h1>Hello, ", "</h1>"]]
// ["world"]
```


**main.js**  without tagged template literals
``` javascript
const template = require('./template.html');

const config = { 
  scope: {name: 'world'}, 
};
console.log(template(config));
```

The result:

``` javascript
// <h1>Hello, world</h1>
```

You can set a config or not. If you don't use the config.scope it will use current [[Scope]]. I.e. in a tepmplate you will have to write `<h1>Hello, ${this.name}</h1>` and set  the `name` variable in your code.


Usage with a class:

**template.html**
``` html
<h1>Hello, ${this.name}</h1>
```

**main.js** 
``` javascript
const template = require('./template.html');

class Hello {
  name = 'Den!';
  _template;

  constructor() {
    this._template = template;

    console.log(this._template()); //<h1>Hello, Den!</h1>
  }
}
```

---
_Source: https://npm.io/package/template-literals-loader · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
