簡體   English   中英

webpack 可以自動更改 HTML 頁面中的 href 鏈接嗎?

[英]Can webpack automatically change href links in an HTML page?

我是使用 webpack 的新手,現在我剛剛有了一個帶有 index.html 頁面的基本設置,該頁面引用了如下測試頁面: <a href="/test.html">license</a>

現在,webpack 正在使用 HTMLWebpackPlugin 將 index.html 頁面加載到 dist 文件夾中,而我的 test.html 文件保留在我的 src 文件夾中。 我想要實現的是將 test.html 文件也加載到 dist 文件夾中,但自動更新 index.html 文件中的 href。 這是因為當我使用 HTMLWebpackPlugin 時,為了清楚起見,我將 HTML 文件 go 重命名為 dist 文件夾,名稱如 dist-index.html 和 dist-test.HTML。 這可能嗎?

如果你想使用多個 HTML 頁面和 webpack 你應該使用這個代碼示例:

plugins: [
  new HtmlWebpackPlugin({
    filename: 'index.html',
    template: 'src/index.html',
    chunks: ['main']
  }),
  new HtmlWebpackPlugin({
    filename: 'example.html',
    template: 'src/example.html',
    chunks: ['exampleEntry']
  })
]

相反,如果你正在使用像 React 這樣的庫,你應該安裝 react-router-dom 並使用默認配置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM