ejs-webpack-loader for webpack 4.x
EJS loader for webpack. Uses ejs function to compile templates.
Installation
npm install ejs-webpack-loader
Config Setup examples as module loader
ejs example
<%= title %> <%= someVar %>
webpack.config.js
const 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
const 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)
const path = ;const config =output:filename: 'my-first-webpack.bundle.js'module:...plugin:template: '!!ejs-webpack-loader!src/index.ejs';moduleexports = config;
EJS Example
var template = ;// => returns the template function compiled with ejs templating engine.// And then use it somewhere in your code// 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
module: rules: test: /\.ejs$/ use: loader: "ejs-webpack-loader" options: htmlmin: true
License
MIT (http://www.opensource.org/licenses/mit-license.php)