【问题标题】:How to assemble HTML documents with Webpack?如何使用 Webpack 组装 HTML 文档?
【发布时间】:2015-11-18 20:05:36
【问题描述】:

有没有办法用 Webpack 来拼凑你的 HTML,这样你就有 HTML 块而不是大的 HTML 文件?

例子:

<html>
    <body>
        <div>Here is the main page </div>
        <script>
        // inject a chunk of HTML here
            require.include('./header.html');
        </script>
   </body>
</html>

我看到了 HTML 加载器,但我认为我不能将它用于此目的。

【问题讨论】:

    标签: html webpack


    【解决方案1】:

    也许你需要这个html-loader

    已编辑:

    您可以使用 interpolate 标志为 ES6 模板字符串启用插值语法,如下所示:

    require("html?interpolate!./file.html");
    
    <img src="${require(`./images/gallery.png`)}" />
    <div>${require('./partials/gallery.html')}</div>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-27
      • 2012-11-11
      • 2014-03-26
      • 2019-04-13
      • 1970-01-01
      相关资源
      最近更新 更多