【问题标题】:Webpack not showing index.html in browserWebpack 未在浏览器中显示 index.html
【发布时间】:2021-05-18 20:06:08
【问题描述】:

我正在使用 webpack 来观察我的代码中的变化。代码编译成功,但我去浏览器看不到任何东西。

package.json

   "dev:server": "webpack server --hot",
   "prod:build": "webpack"

项目结构

- webpack.config.js
- package.json
- src/
  - index.hbs
  - sass/
  - js/

webpack.config.json

module.exports = {
entry: {
  "main-page": "./src/js/index.js",
},
  output: {
    filename: "bundle.[name].[contenthash].js",
    path: path.resolve(__dirname, "./dist"),
    publicPath: "dist/",
  },
  mode: "production",
  module: ,
    optimization:,
      plugins: [
        new CleanWebpackPlugin({
          cleanOnceBeforeBuildPatterns: ["**/*"],
        }),
        new HTMLWebpackPlugin({
          chunks: ["main-page"],
          template: "src/index.hbs",
        }),
      ],
    };

【问题讨论】:

    标签: webpack webpack-dev-server


    【解决方案1】:

    刚刚在 webpack.config.js 中添加了以下内容,它就起作用了。

    mode: "development", //change in production
    devServer: {
      // remove in production
      contentBase: path.resolve(__dirname, "./dist"),
      index: "index.html",
    },
    

    【讨论】:

      猜你喜欢
      • 2017-04-15
      • 2013-05-03
      • 1970-01-01
      • 2014-12-07
      • 2018-12-02
      • 2021-03-05
      • 2011-07-15
      • 2011-04-03
      • 2019-04-23
      相关资源
      最近更新 更多