简体   繁体   English

Webpack 构建操纵索引。html

[英]Webpack build manipulated index.html

I have two webpack scripts in my package.json我的 package.json 中有两个 webpack 脚本

  "scripts": {
    "start": "webpack-dev-server --open --mode development --hot",
    "build": "webpack --mode production",
    "dev-server": "nodemon server/index.js"
  },

when i run the 'build' script it manipulates and reformats my index.html each time and I find this quite annoying.当我运行“构建”脚本时,它每次都会操纵并重新格式化我的 index.html,我觉得这很烦人。 Is there any clear reason as to why?有什么明确的原因吗?

below is my webpack.config.js下面是我的 webpack.config.js

const path = require('path');

const DIST_DIR = path.join(__dirname, 'client', 'dist');
const SRC_DIR = path.join(__dirname, 'client', 'src', 'index.jsx');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  mode: 'development',
  entry: SRC_DIR,
  devtool: 'inline-source-map',
  output: {
    path: DIST_DIR,
    filename: 'bundle.js',
  },
  devServer: {
    static: './dist',
    historyApiFallback: true
  },
  module: {
    rules: [
      {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
      },
      {
        test: /\.css$/i,
        use: ['style-loader', 'css-loader'],
      },
    ],
  },
  resolve: {
    extensions: ['.jsx', '.ts', '.js'],
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: './client/dist/index.html',
    }),
  ],
};

This is because of the minification of the HtmlWebpackPlugin这是因为HtmlWebpackPlugin的缩小

Take a look at the official document here:看看这里的官方文档:

https://github.com/jantimon/html-webpack-plugin#minification .https://github.com/jantimon/html-webpack-plugin#minification

To disable minification during production mode set the minify option to false.要在生产模式下禁用缩小,请将 minify 选项设置为 false。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM