[英]how to run a different html file instead of index.html when webpack server runs?
When I run webpack server, Below config by default opens index.html available in public folder.当我运行 webpack 服务器时,默认情况下,下面的配置会打开公共文件夹中的 index.html。 so, Instead of index.html, I want to create another.html or may be like a folder inside which an html eg.
所以,而不是 index.html,我想创建另一个。html 或者可能就像一个文件夹,里面有一个 html 例如。 public/someFolder/another.html and want to open it, when webpack server is run.
public/someFolder/another.html 并想在 webpack 服务器运行时打开它。
how to run a different html file instead of index.html when webpack server runs?当 webpack 服务器运行时,如何运行不同的 html 文件而不是 index.html?
webpack.config.js 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,
},
};
Have a look at HtmlWebpackPlugin看看HtmlWebpackPlugin
You can specify a custom path and a custom.html file.您可以指定自定义路径和 custom.html 文件。
output: {
filename: './dist/subdirectory/myindex.html'
},
plugins: [new HtmlWebpackPlugin()]
The default is of course index.html默认当然是index.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.