java-template-engine-webpack-plugin

0.2.3 • Public • Published

Java Template Engine Webpack Plugin

npm_version build workflow

A plugin extension for html-webpack-plugin that injects code for Java template engines.

Supported engines

  • Thymeleaf (thymeleaf)
  • Java Server Pages (jsp)

Installation

npm i --save-dev java-template-engine-webpack-plugin

Usage

const HtmlWebpackPlugin = require('html-webpack-plugin')
const JavaTemplateEngineWebpackPlugin = require('java-template-engine-webpack-plugin');

module.exports = {
  entry: 'index.js',
  output: {
    path: __dirname + '/dist',
    filename: 'bundle.js'
  },
  plugins: [
    new HtmlWebpackPlugin(),
    new JavaTemplateEngineWebpackPlugin(HtmlWebpackPlugin, {engine: 'thymeleaf'})
  ]
}

The example below shows how the output of index.html is changed after adding the plugin with thymeleaf as the engine.

Before

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Webpack App</title>
    <link rel="stylesheet" href="styles.css">
  </head>
  <body>
    <div id="root"></div>
    <script src="bundle.js"></script>
  </body>
</html>

After

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Webpack App</title>
    <link rel="stylesheet" th:href="@{styles.css}">
  </head>
  <body>
    <div id="root"></div>
    <script th:src="@{bundle.js}"></script>
  </body>
</html>

Options

Name Type Default Description
engine String '' The engine to be used, please check supported engines section.
addLeadingSlash Boolean false Adds a leading slash to the attribute if its missing.
static/image.png becomes /static/image.png
removeLeadingSlash Boolean false Removes a leading slash from the attribute if its present.
/static/image.png becomes static/image.png
removeDotSegments Boolean false Removes dot-segments from the attribute.
../../static/image.png becomes static/image.png
./static/image.png becomes static/image.png
.static/image.png becomes static/image.png
removeOriginalAttributes Boolean true Removes the original src and href attributes. Only valid when using thymeleaf engine.
useJSTL Boolean true Uses the JSTL <c:url> tag when modifying attributes. Only valid when using jsp engine.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.2.3
    2
    • latest

Version History

Package Sidebar

Install

npm i java-template-engine-webpack-plugin

Weekly Downloads

4

Version

0.2.3

License

MIT

Unpacked Size

16.2 kB

Total Files

19

Last publish

Collaborators

  • kushtrimh