如何在 webpack 中包含加载器? [英] how to include loaders in webpack?
本文介绍了如何在 webpack 中包含加载器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在 index.html
中包含 Header.html
和 footer.html
.因为我将使用这两个文件作为所有页面的通用文件.由于我的研究 webpack 不允许将文件导入为
我试过 grunt 我工作正常.但是在webpack中怎么做
这是我的 webpack 版本详情
"name": "webpack-boilerplate",版本":1.0.0",
这是我尝试过的...在我的 webpack.config.js 文件
<代码>{测试:/.html$/,装载机:'html-装载机'}
在我的 index.html 文件中
require("html-loader!./file.html");<div class="banner"><h3>横幅1</h3>
<div class="bannerbanner2"><h3>横幅2</h3>
但它显示在页面
这不是为了反应.这仅适用于网站和普通 html..
那怎么做呢?
解决方案
html-webpack-plugin 支持使用变量进行模板化.
你可以在你的 webpack.config.js
中定义变量
new HtmlWebpackPlugin({模板:'./src/index.html',header: 'hello world
',脚注:'<b>页脚</b>'}),
然后像这样将它们放在 index.html 中:
<头></头><身体><%= htmlWebpackPlugin.options.header %><!-- 所有标准模板都在这里--><%= htmlWebpackPlugin.options.footer %>