这是我的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"
。
我有一些CSS样式化了一些关于type="text"
存在的组件。
有没有办法阻止Webpack的制作过程(uglifying?)删除这个HTML属性?
答案 0 :(得分:1)
对于 webpack 5,尝试为 HtmlWebpackPlugin 的 minifier 禁用 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