简体   繁体   English

当 webpack 服务器运行时,如何运行不同的 html 文件而不是 index.html?

[英]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.

相关问题 使用webpack-dev-server时,html-webpack-plugin不会将js文件注入index.html - html-webpack-plugin not inject js file into index.html when using webpack-dev-server Webpack 开发服务器未找到索引。html - Webpack dev server not finding index.html 如何从index.html访问webpack生成的js文件 - How to access webpack generated js file from index.html 使用webpack时如何移动“index.html”? - How can I move “index.html” when using webpack? 为什么在浏览器中打开index.html而不是通过节点服务器提供index.html时,“ this”有何不同? - Why is `this` different when opening index.html in the browser as opposed to serving index.html with a node server? HTML Webpack插件未创建正确的index.html文件 - HTML Webpack Plugin not creating correct index.html file Express 正在提供 index.html 而不是我的 Webpack 包。 我的配置文件有问题吗? - Express is serving up index.html instead of my Webpack bundle. Is the issue with my config file? 如何在没有任何本地服务器的情况下通过单击 index.html 文件来运行 React 应用程序 - How to run React application by clicking index.html file without any local server 如何使用HTML Webpack插件将文件加载器所需的CSS文件包含到index.html中 - how to include css file required with file loader into index.html using html webpack plugin 从index.html在其他服务器上部署React / Webpack静态目录 - Deploy React/Webpack static directory on different server from index.html
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM