0.2.3 • Published 1 year ago

java-template-engine-webpack-plugin v0.2.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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

NameTypeDefaultDescription
engineString''The engine to be used, please check supported engines section.
addLeadingSlashBooleanfalseAdds a leading slash to the attribute if its missing. static/image.png becomes /static/image.png
removeLeadingSlashBooleanfalseRemoves a leading slash from the attribute if its present. /static/image.png becomes static/image.png
removeDotSegmentsBooleanfalseRemoves 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
removeOriginalAttributesBooleantrueRemoves the original src and href attributes. Only valid when using thymeleaf engine.
useJSTLBooleantrueUses the JSTL <c:url> tag when modifying attributes. Only valid when using jsp engine.
0.2.3

1 year ago

0.2.2

2 years ago

0.1.0

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.0.1

2 years ago