当webpack编译包含以下html的应用程序时,它抱怨 theme
变量是未定义的。
这是我的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使用" HTML-LOADER",例如:
new HtmlWebpackPlugin({
template: '!!html-loader!index.html'
})
ps:不要忘记使用NPM安装;)
将其放入:
中webpack.config
new HtmlWebpackPlugin({
template: './index.ejs',
filename: './index.html',
minify: { collapseWhitespace: true },
csrf: '${_csrf.token}',
}),
在您的index.ejs文件中:
<meta name="_csrf" th:content="<%= htmlWebpackPlugin.options.csrf %>"/>