Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Webpack 使用网页包提供index.html以外的服务_Webpack_Webpack Dev Server - Fatal编程技术网

Webpack 使用网页包提供index.html以外的服务

Webpack 使用网页包提供index.html以外的服务,webpack,webpack-dev-server,Webpack,Webpack Dev Server,在公用文件夹中,有index.html和altIndex.html。我想提供altIndex.html devServer: { contentBase: path.join(__dirname, "public"), historyApiFallback: { index: 'altIndex.html', rewrites: [ { from: /^\/$/, to: '/altIndex.html' } ] }

在公用文件夹中,有index.html和altIndex.html。我想提供altIndex.html

devServer: {
    contentBase: path.join(__dirname, "public"),
    historyApiFallback: {
      index: 'altIndex.html',
      rewrites: [
        { from: /^\/$/, to: '/altIndex.html' }
      ]
    }
  }
运行webpack devserver时,它提供index.html服务。按照下面的配置

 devServer: {
    contentBase: path.join(__dirname, "public"),
    historyApiFallback: true
    }
  }
按照下面的配置,配置不起作用。仍然提供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
  }
};
试试这个(如上所述):


看看,这应该是
index:'/altIndex.html'
,即带有前导斜杠吗?
historyapi回退:{index:'/altIndex.html'}
不起作用。仍然呈现index.htmltried
devServer:{contentBase:path.join(uu dirname,“public”),索引:'altIndex.html',historyApiFallback:{index:'altIndex.html'}
不起作用