在公共文件夹中,有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
}
};
请尝试(如here所述:]
devServer: {
contentBase: path.join(__dirname, "public"),
index: 'altIndex.html',
historyApiFallback: {
index: 'altIndex.html'
}
}