![](/img/trans.png)
[英]Webpack Build generates index.html but blank when loaded in browser
[英]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.