# ejs-webpack-loader

> EJS webpack 4.x loader (without frontend dependencies)

Latest version **2.2.2** (published 2018-04-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install ejs-webpack-loader
pnpm add ejs-webpack-loader
yarn add ejs-webpack-loader
bun add ejs-webpack-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 | 2.2.2 |
| Published | 2018-04-18 |
| First published | 2018-04-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 7.7 KB |
| Known vulnerabilities | 0 (+5 in 4 direct dependencies) |
| Install scripts | no |
| GitHub stars | 19 |
| Author | Ashot Gasparyan |
| Maintainers | rork |
| Keywords | ejs, webpack, loader, template |

## Links

- npm: https://www.npmjs.com/package/ejs-webpack-loader
- Repository: https://github.com/rorkflash/ejs-webpack-loader
- Issues: https://github.com/rorkflash/ejs-webpack-loader/issues
- npm.io page: https://npm.io/package/ejs-webpack-loader

## Dependencies (5)

- [ejs](https://npm.io/package/ejs.md) ^2.0.0
- [merge](https://npm.io/package/merge.md) ^1.2.0
- [uglify-js](https://npm.io/package/uglify-js.md) ~2.6.1
- [loader-utils](https://npm.io/package/loader-utils.md) ^0.2.7
- [html-minifier](https://npm.io/package/html-minifier.md) ^3

## 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

- 2.2.2 (latest) — 2018-04-18
- 2.2.1 — 2018-04-18
- 2.2.0 — 2018-04-17

## README

# ejs-webpack-loader for webpack 4.x

EJS loader for [webpack](http://webpack.github.io/). Uses [ejs](https://github.com/mde/ejs) function to compile templates.

## Installation

`npm install ejs-webpack-loader`

## Config Setup examples as module loader

ejs example
```ejs
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title><%= title %></title>
</head>
<body>
    <p><%= someVar %></p>
</body>
</html>
```

webpack.config.js

``` javascript

const path = require('path');

const config = {
  output: {
    filename: 'my-first-webpack.bundle.js'
  },
  module: {
    rules: [
      {
          test: /\.ejs$/,
          use: [
              {
                loader: "ejs-webpack-loader",
                options: {
                  data: {title: "New Title", someVar:"hello world"},
                  htmlmin: true
                }
              }
          ]
      }
    ]
  }
};

```

## Config Setup examples with separate extractor

``` javascript

const path = require('path');

const config = {
  entry: [
    './src/index.ejs',
    './src/main.ejs',
  ]
  output: {
    filename: 'my-first-webpack.bundle.js'
  },
  module: {
      rules: [
          {
              test: /\.ejs$/,
              use: [
                  {
                      loader: 'file-loader',
                      options: {
                          name: '[name].html',
                          context: './src/',
                          outputPath: '/'
                      }
                  },
                  {
                      loader: 'extract-loader'
                  },
                  {
                      loader: "ejs-webpack-loader",
                      {
                        data: {title: "New Title", someVar:"hello world"},
                        htmlmin: true
                      }
                  }
              ]
          }
      ]
  }
};

```

## Config Setup examples (via HtmlWebpackPlugin)

``` javascript

const path = require('path');

const config = {
  output: {
    filename: 'my-first-webpack.bundle.js'
  },
  module: {
    ...
  },
  plugin: {
    new HtmlWebpackPlugin({
        template: '!!ejs-webpack-loader!src/index.ejs'
    })
  }
};

module.exports = config;

```

## EJS Example

[Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html)

``` javascript
var template = require("ejs-compiled!./file.ejs");
// => returns the template function compiled with ejs templating engine.

// And then use it somewhere in your code
template(data) // Pass object with data

// Child Templates
// path is relative to where webpack is being run
<%- include templates/child -%>
```

## Options

Following options can be specified in query:

`beautify` — enable or disable uglify-js beautify of template ast

`compileDebug` — see ejs compileDebug option

`htmlmin` — see [htmlminify section](#htmlminify)

## htmlminify

```javascript
module: {
    rules: [
        {
            test: /\.ejs$/,
            use: [
                {
                  loader: "ejs-webpack-loader",
                  options: {
                    htmlmin: true
                  }
                }
            ]
        }
    ]
}
```

See [all options reference](https://github.com/kangax/html-minifier#options-quick-reference)

## License

MIT (http://www.opensource.org/licenses/mit-license.php)

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