HtmlWebpackPlugin擦除模板分区

HtmlWebpackPlugin erase template div

本文关键字:分区 擦除 HtmlWebpackPlugin      更新时间:2023-09-26

我以这个例子为例(http://courses.reactjsprogram.com/courses/reactjsfundamentals/lectures/760301)启动一个reactj应用程序,所以这是我的webpack.config.js

var HtmlWebpackPlugin = require('html-webpack-plugin');
var HtmlWebpackPluginConfig = new HtmlWebpackPlugin({
  tempalte : __dirname + '/app/index.html',
  filename : 'index.html',
  inject : 'body'
})
module.exports = {
  entry: [
    './app/index.js'
  ],
  output: {
    path : __dirname + '/dist',
    filename : "index_bundle.js"
  },
  module : {
    loaders :[
      {test: /'.js$/, include: __dirname + '/app', loader: "babel-loader"}
    ]
  },
  plugins : [HtmlWebpackPluginConfig]
}

这是我的index.html模板:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title> teste</title>
</head>
<body>
  <div id="app"></div>
</body>
</html>

这是我的index.html由webpack 生成

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Webpack App</title>
  </head>
  <body>
  <script src="index_bundle.js"></script></body>
</html>

注意:我的被删除了,所以当我尝试运行我的应用程序时,我得到了错误:

Uncaught Invariant Violation: _registerComponent(...): Target container is not a DOM element.

如何解决不删除div的问题?我使用"巴氏合金芯":"^6.7.6","babel loader":"^6.2.4","babel preset react":"^6.5.0","html webpack插件":"^2.15.0","webpack":"^1.13.0","webpack开发服务器":"^1.14.1"

tks

配置中template键的拼写错误意味着它使用的是默认模板,而不是您试图包含的模板。默认行为使此错误难以发现。

tempalte : __dirname + '/app/index.html'应该是template : __dirname + '/app/index.html'