簡體   English   中英

當 webpack 服務器運行時,如何運行不同的 html 文件而不是 index.html?

[英]how to run a different html file instead of index.html when webpack server runs?

當我運行 webpack 服務器時,默認情況下,下面的配置會打開公共文件夾中的 index.html。 所以,而不是 index.html,我想創建另一個。html 或者可能就像一個文件夾,里面有一個 html 例如。 public/someFolder/another.html 並想在 webpack 服務器運行時打開它。

當 webpack 服務器運行時,如何運行不同的 html 文件而不是 index.html?

webpack.config.js

const path = require("path");
module.exports = {
  entry: "./myFile.js",
  output: {
    path: path.join(__dirname, "public"),
    filename: "bundle.js",
  },
  module: {
    rules: [
      {
        loader: "babel-loader",
        test: /\.js$/,
        exclude: /node_modules/,
      },
      {
        test: /\.s?css$/,
        use: ["style-loader", "css-loader", "sass-loader"],
      },
    ],
  },
  devtool: "cheap-module-eval-source-map",
  devServer: {
    contentBase: path.join(__dirname, "public"),
    historyApiFallback: true,
  },
};

看看HtmlWebpackPlugin

您可以指定自定義路徑和 custom.html 文件。

  output: {
    filename: './dist/subdirectory/myindex.html'
  },
  plugins: [new HtmlWebpackPlugin()]

默認當然是index.html

暫無
暫無

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

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