A plugin extension for html-webpack-plugin that injects code for Java template engines.
- Thymeleaf (
thymeleaf) - Java Server Pages (
jsp)
npm i --save-dev java-template-engine-webpack-plugin
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>