这是我的 Webpack 配置的有趣摘录:
module: {
loaders: [
{
test: /\.js$/, exclude: /node_modules/,
loader: 'ng-annotate!babel?presets[]=es2015'
},
{
test: /\.scss$/, loader: ExtractTextPlugin.extract("style", "css!sass")
},
{
test: /\.(ttf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/, loader: "file-loader?name=fonts/[name].[ext]"
},
{
test: /\.(jpe?g|png|gif|svg)$/i, loader: "file-loader?name=images/[name].[ext]?[hash]"
},
{
test: /\.tpl\.html$/, exclude: /node_modules/, loader: "html-loader"
}
]
}
当我运行 webpack -p
时,我提示从某些 HTML 输入中删除了 type="text"
。
我有一些关于 type="text"
存在的 CSS 样式组件。
有没有办法阻止Webpack的制作过程(丑化?)去掉这个HTML属性?
最佳答案
对于 webpack 5,尝试禁用 HtmlWebpackPlugin 压缩器的 removeRedundantAttributes
:
new HtmlWebpackPlugin({
template: `./src/index.html`,
filename: `index.html`,
minify: {
collapseWhitespace: true,
keepClosingSlash: true,
removeComments: true,
removeRedundantAttributes: false, // do not remove type="text"
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
useShortDoctype: true
}
});
文档:https://github.com/jantimon/html-webpack-plugin#minification
关于html - 如何防止 Webpack 进程从输入标记中删除类型 ="text",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35162942/