本文介绍了webpack.config.js 不断将 bundle.js 的脚本标签添加到我的 index.html 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有如下所示的 webpack.config.js

I have the webpack.config.js like the following

var path = require('path')
var webpack = require('webpack')
var HtmlWebpackPlugin = require('html-webpack-plugin')
var PORT = process.env.PORT || 3333
var PRODUCTION = process.env.NODE_ENV === 'production'
var SRC_DIR = path.resolve(__dirname, './src')
var Webpack_isomorphic_tools_plugin = require('webpack-isomorphic-tools/plugin')

var config = {
  entry: [
    './src/index'
  ],
  output: {
    path: path.join(__dirname, '/'),
    filename: 'bundle.js',
    publicPath: '/'
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin(),
    new HtmlWebpackPlugin({ template: './index.html' })
  ],
  resolve: {
    extensions: ['', '.js', '.jsx']
  },
  module: {
    loaders: [
      {
        test: /\.jsx?$/,
        loaders: ['react-hot', 'babel'],
        include: SRC_DIR
      },{ test: /\.css$/, loader: "style-loader!css-loader" }
    ]
  }
}

if (!PRODUCTION) {
  config.devtool = 'eval'
}

module.exports = config

每当我使用

webpack -p

它插入一个脚本标签

<script type="text/javascript" src="/bundle.js"></script>

进入我的 index.html我无法弄清楚 webpack.config.js 的哪一部分正在执行此操作...我怎样才能阻止这种情况?

into my index.htmlI could not figure out which part of the webpack.config.js is doing this...How can I stop this?

谢谢

标记

推荐答案

负责执行此操作的插件是 HTMLWebpackPlugin 如果您将选项 inject 传递为 >false,然后它将停止将您的资产注入 HTML.

The plugin in charge of doing that is HTMLWebpackPlugin which if you pass the option inject as false, then it will stop injecting your assets to the HTML.

这里有完整的文档 https://github.com/jantimon/html-webpack-插件

希望有帮助.

这篇关于webpack.config.js 不断将 bundle.js 的脚本标签添加到我的 index.html 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 12:46