Skip to content

iyonaga/ejs-templates-loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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: {})