使用webpack进行除index.html以外的其他服务

问题描述 投票:0回答:1

在公共文件夹中,有index.html,altIndex.html。我要提供altIndex.html。

运行webpack devserver时,它会提供index.html。按照下面的配置。

 devServer: {
    contentBase: path.join(__dirname, "public"),
    historyApiFallback: true
    }
  }

按照下面https://webpack.js.org/configuration/dev-server/的配置不起作用。仍提供index.html

devServer: {
    contentBase: path.join(__dirname, "public"),
    historyApiFallback: {
      index: 'altIndex.html'
    }
  }

在配置下面也行不通。仍投放index.html。

devServer: {
    contentBase: path.join(__dirname, "public"),
    historyApiFallback: {
      index: 'altIndex.html',
      rewrites: [
        { from: /^\/$/, to: '/altIndex.html' }
      ]
    }
  }

如何从公用文件夹提供除index.html之外的其他html?

webpack.config.json

const path = require("path");
module.exports = {
  entry: "./index.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
  }
};
webpack webpack-dev-server
1个回答
0
投票

请尝试(如here所述:]

devServer: {
  contentBase: path.join(__dirname, "public"),
  index: 'altIndex.html',
  historyApiFallback: {
    index: 'altIndex.html'
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.