由于 Thymeleaf 变量未定义,HTML Webpack 插件将无法编译 [英] HTML Webpack Plugin will not compile as Thymeleaf variables are undefined
本文介绍了由于 Thymeleaf 变量未定义,HTML Webpack 插件将无法编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当 Webpack 编译包含以下 HTML 的应用程序时,它会抱怨 theme
变量未定义.
When Webpack compiles my app which contains the below HTML, it complains the theme
variable is undefined.
这是我的 index.html
文件:
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"/>
</head>
<body th:class="${theme}">
<div id="root"></div>
</body>
</html>
这是我得到的错误:
Failed to compile.
Error in Template execution failed: ReferenceError: theme is not defined
- loader.js:4 eval
/src/main/resources/templates/index.html?./~/html-webpack-plugin/lib/loader.js:4:10
推荐答案
把这个放进去:
webpack.config
webpack.config
new HtmlWebpackPlugin({
template: './index.ejs',
filename: './index.html',
minify: { collapseWhitespace: true },
csrf: '${_csrf.token}',
}),
在你的 index.ejs 文件中:
in your index.ejs file put :
<meta name="_csrf" th:content="<%= htmlWebpackPlugin.options.csrf %>"/>
这篇关于由于 Thymeleaf 变量未定义,HTML Webpack 插件将无法编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文