Is there a way to include partial using html-webpack-plugin?(有没有办法使用 html-webpack-plugin 包含部分内容?)
问题描述
我正在使用 Webpack 来编译我的脚本和 HTML(使用 html-webpack-plugin
).问题是,我有 5 个包含相同部分的 HTML 文件,我想将这些部分移动到单独的 .html
文件中,然后在每个 HTML 文件中 include
这些部分.这样,如果我要更改这些较小的 HTML 文件,它将重新编译每个 HTML 文件以表示这些更改.
I am using Webpack to compile my scripts and HTML (using html-webpack-plugin
). The thing is, I have 5 HTML files that contains the same parts and I want to move these parts to separate .html
files and then include
these parts in every HTML file. This way, if I will change these smaller HTML files, it will recompile every HTML file to represent these changes.
Webpack 默认对 .js 文件执行此操作,但我可以对 HTML 文件使用类似的内容吗?
Webpack does this for .js files by default, but can I use something like that for HTML files?
推荐答案
您可以在模板中使用 <%= require('html!./partial.html') %>
.此处示例:https://github.com/jantimon/html-webpack-plugin/blob/master/examples/custom-template/template.html
You can use <%= require('html!./partial.html') %>
in your template. Example here: https://github.com/jantimon/html-webpack-plugin/blob/master/examples/custom-template/template.html
这篇关于有没有办法使用 html-webpack-plugin 包含部分内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:有没有办法使用 html-webpack-plugin 包含部分内容?


基础教程推荐
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01