iyonaga / ejs-templates-loader

EJS loader module for webpack

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ejs-templates-loader

EJS loader module for webpack

Installation

npm install --save ejs-templates-loader

Usage

webpack.config.js

module: {
  rules: [
    {
      test: /\.ejs$/,
      use: {
        loader: 'ejs-templates-loader',
        options: {}
      }
    }
  ]
},

plugins: [
  new HtmlWebpackPlugin({
    filename: 'index.html',
    template: './index.ejs'
  })
]

Advanced configuration example

webpack.config.js

module: {
  rules: [
    {
      test: /\.ejs$/,
      use: {
        loader: 'ejs-templates-loader',
        options: {
          delimiter: '$'
        }
      }
    }
  ]
},

plugins: [
  new HtmlWebpackPlugin({
    title: 'title',
    filename: 'index.html',
    template: './index.ejs'
  })
]

index.ejs

<!DOCTYPE html>
<html>
  <head>
    <title><%= htmlWebpackPlugin.options.title %></title>
  </head>
  <body>
    <$- include('./_header', {foo: 'foo'}) $>
    <img src="<%= require('./img/image.jpg') %>">
    <$- include _footer $>
  </body>
</html>

Options

  • delimiter — Character to use with angle brackets for open/close (default: "%")

  • beautify — Enable/Disable beautification (default: false)

  • beautifyOptions See js-beautify#options (default: {})

About

EJS loader module for webpack

License:MIT License


Languages

Language:JavaScript 100.0%