【发布时间】:2017-04-11 05:42:08
【问题描述】:
我试图在不执行 EJS 模板的情况下动态插入 bundle.js,但出现以下错误。有没有办法只插入JS而不执行EJS模板?
ERROR in Template execution failed: ReferenceError: description is not defined
ERROR in ReferenceError: description is not defined
我实际上是使用节点渲染模板,我只是希望捆绑文件动态插入到 template.ejs 中
res.status(200).render('template',
{
description: description,
title:title
});
webpack 配置:
output: {
path: path.join(__dirname, 'dist'),
filename: "output.[hash].bundle.js",
publicPath: '/'
},
new HtmlWebpackPlugin({
inject: 'body',
template: 'views/template.ejs'
}),
模板.ejs
<!DOCTYPE html>
<html lang="en" class="ddhub-site">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="format-detection" content="telephone=no">
<meta description=<%=description%>/>
<title> <%= title %> </title>
</head>
<body></body>
</html>
【问题讨论】:
标签: node.js templates webpack ejs html-webpack-plugin