html - 如何防止 Webpack 进程从输入标记中删除类型 ="text"

标签 html webpack

这是我的 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/

相关文章:

html - 即使在 div 中,转换(缩小)的 iframe 仍然占用空间

javascript - 如何显示和存储按钮值?

php - 发布数据并刷新页面

javascript - 无法读取未定义的属性 'setState'

reactjs - 生成附加类名 : CSS module is undefined

jquery - Yii2 - 如何用下拉列表隐藏 block

javascript - React、webpack 热重载的“导入”问题

javascript - Vue CLI 3 vue.config.js 与插件的 webpack.config.js

css - Less:导入带有 url 的另一个 css 的 import css 不起作用

java - 如何从带有嵌入标记的子文件夹中加载 Java applet 类?