亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

html-webpack-plugin, 嵌套引入 html, 無法解析

html-webpack-plugin, 嵌套引入 html, 無法解析

鴻蒙傳說 2018-07-23 20:01:48
index.html<div class="center-table-wrapper">     <%= require('html-loader!../components/systemMainTab/index.html') %></div>systemMainTab/index.html<div class="containerDY">     <div class="container-list">         <div class="container-table">             <table id="showTable" style="width:100%"></table>         </div>         <div class="container-pagination">             <!-- 無法引入html 內容 -->             <%= require('html-loader!../systemPagination/index.html') %>          </div>     </div>     <!-- <div class="container-dy">     </div> --></div>systemPagination/index.html<div class="system-pagination"></div>第一層 <%= require('html-loader!../components/systemMainTab/index.html') %> 能正常引入, 而systemMainTab/index.html 的 <%= require('html-loader!../systemPagination/index.html') %> 未能解析, 有什么方法能嵌套解析否?一種方式是通過 js 來引入模塊在組裝, 不過這種方式實現不佳
查看完整描述

1 回答

?
慕標5832272

TA貢獻1966條經驗 獲得超4個贊

你既然已經用了 html-loader 了,實際上就不需要通過 html-webpack-plugin 的模板來渲染 html 了。在 webpack 里配置 html-loader 開啟 interpolate 后,通過 ES6 字符串模板進行引用。

webpack:

{    test: /\.html$/,    use: [{        loader: "html-loader",        options: {            interpolate: true
        }
    }]}

html:

<!DOCTYPE html><html lang="en"><head>
    ${require("./common.html")}</head>

然后在 common.html 中,可以繼續使用 ${require("xxx.html")} 進行引用。這個寫起來應該比你用 <%= ... %> 更簡潔一些。


查看完整回答
反對 回復 2018-07-29
  • 1 回答
  • 0 關注
  • 1692 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號