我有一个使用Twig进行模板化的项目。其中的所有数据都是静态的,但为了清楚起见,我在其他树枝文件中分离出了部分页面(否则一个文件中会有数百行标记)。
我使用webpack作为构建工具,以及HTML Webpack插件。
例如,我们说我有以下内容:
视图/ index.html中
<h1>This is my main index page</h1>
{% includes './welcome/hello.html' %}
视图/欢迎/ hello.html的
<p>Hello from the templated page.</p>
现在我想做的是使用webpack捆绑任何js,css,并使用HTML Webpack Plugin创建HTML页面并将这些样式和脚本注入:
dist/index.html
dist/bundle.js
dist/styles.css
在我的 dist / index.html 中,我希望得到这样的内容,其中生成的html页面显示为HTML:
DIST / index.html中
<h1>This is my main index page</h1>
<p>Hello from the templated page.</p>
然而,我得到的是这样的东西,它仍然显示我的&#39;包括&#39;模板:
DIST / index.html中
<h1>This is my main index page</h1>
{% includes './welcome/hello.html' %}
如果无法编译模板,是否可以使用Html Webpack插件复制所有模板(所有模板文件的整个目录为 / dist ,以便它们保持他们的路径?)
谢谢!
答案 0 :(得分:2)
您可以使用ejs-render-loader
。 see package
// webpack
new HtmlWebpackPlugin({
filename: 'a.html',
hash: true,
template: 'ejs-render?a.ejs',
})
// a.ejs
<%- include components/menu -%>
// components/menu.ejs
<p>hei hei hei hei</p>
我认为您可以将.html
更改为.ejs
文件。并使用上面的插件。