本文介绍了入口点 undefined = index.html 使用 HtmlWebpackPlugin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Webpack 4 并且我正在创建配置文件,当尝试使用 HtmlWebpackPlugin 时,它在控制台上得到了这个:Entrypoint undefined = index.html,它打开浏览器并显示 HTML,但我在控制台上收到这条奇怪的消息,如何解决这个问题?

I'm using Webpack 4 and I'm creating the config file, when trying to use the HtmlWebpackPlugin it got this on the console: Entrypoint undefined = index.html, it opens the browser and the HTML does appear but I'm getting this weird message on the console, how to solve this?

这就是我的配置文件的样子:

That is how my config file looks like:

'use strict'

const webpack = require('webpack')
const { join, resolve } = require('path')

const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
  mode: 'development', // dev
  devtool: 'cheap-module-eval-source-map', // dev
  entry: join(__dirname, 'src', 'index.js'),
  output: {
    filename: 'bundle.js',
    path: resolve(__dirname, 'dist')
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'babel-loader'
      }
    ]
  },
  resolve: {
    extensions: ['*', '.js', '.jsx']
  },
  devServer: {
    contentBase: resolve(__dirname, 'build')
  },
  plugins: [
    new webpack.ProgressPlugin(),
    new HtmlWebpackPlugin({
      template: join(__dirname, 'public', 'index.html')
    }),

    new webpack.HotModuleReplacementPlugin(), // dev
    new webpack.NoEmitOnErrorsPlugin() // dev
  ]
}

推荐答案

试试这个;您可能制作了错误的模板路径:

Try this; you might be making wrong template path :

 new HtmlWebpackPlugin({
        template: resolve(__dirname, 'src/public', 'index.html'),
        filename: './index.html'
      }),

如果 public 在 src 文件夹中,这应该可以工作这是我的假设.如果问题仍然存在,请告诉我.

If public is in src folder this should work It's my assumption.Let me know if the issue still persists.

这篇关于入口点 undefined = index.html 使用 HtmlWebpackPlugin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 00:24