簡體   English   中英

Webpack 構建操縱索引。html

[英]Webpack build manipulated index.html

我的 package.json 中有兩個 webpack 腳本

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

當我運行“構建”腳本時,它每次都會操縱並重新格式化我的 index.html,我覺得這很煩人。 有什么明確的原因嗎?

下面是我的 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',
    }),
  ],
};

這是因為HtmlWebpackPlugin的縮小

看看這里的官方文檔:

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

要在生產模式下禁用縮小,請將 minify 選項設置為 false。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM