Skip to content

Double quotes for attributes are removed #306

@chua1989

Description

@chua1989
  • Operating System: windows 10
  • Node Version: 10.15.3
  • NPM Version: 6.4.1
  • webpack Version: 4.41.5
  • html-loader Version: 1.1.0

Expected Behavior

<link rel="shortcut icon" href="data:image/vnd.microsoft.icon;base64,AAABAAEAIC.....A/wAAAf+AAAH/jgBx/5+D+f//E////7//8=">

Actual Behavior

Error: html-webpack-plugin could not minify the generated output.
In production mode the html minifcation is enabled by default.
If you are not generating a valid html output please disable it manually.
You can do so by adding the following setting to your HtmlWebpackPlugin config :
|
| minify: false
|
See https://github.com/jantimon/html-webpack-plugin#options for details.
For parser dedicated bugs please create an issue here:
https://danielruf.github.io/html-minifier-terser/
Parse Error: <link rel="shortcut icon" href=data:image/vnd.microsoft.icon;base 64,AAABAAEAIC......A/wAAAf+AA AH/jgBx/5+D+f//E////7//8=>

Code

// webpack.config.js
            {
                test: /\.(png|jpe?g|gif|svg|ico)(\?.*)?$/,
                loader: 'url-loader',
                options: {
                    limit: 10000,
                    name: utils.assetsPath('img/[name].[hash:7].[ext]'),
                    publicPath: '/'
                }
            }, {
                test: /\.html$/,
                loader: 'html-loader',
                options: {
                    minimize: true,
                    attributes: {
                        root: path.resolve(__dirname, '../src'),
                        list: [
                           {
                                tag: 'link',
                                attribute: 'href',
                                type: 'src'
                            }
                        ]
                    }
                }
            }
// index.html
<head>
    ...
    <link rel="shortcut icon" href="/assets/img/favicon.ico">
</head>

// But when I set minimize like this, I got the desired result

            {
                test: /\.html$/,
                loader: 'html-loader',
                options: {
                    minimize: {
                        caseSensitive: true,
                        collapseWhitespace: true,
                        conservativeCollapse: true,
                        keepClosingSlash: true,
                        minifyCSS: true,
                        minifyJS: true,
                        removeComments: true,
                        removeRedundantAttributes: true,
                        removeScriptTypeAttributes: true,
                        removeStyleLinkTypeAttributes: true,
                    },
                    attributes: {
                        root: path.resolve(__dirname, '../src'),
                        list: [
                            {
                                tag: 'link',
                                attribute: 'href',
                                type: 'src'
                            }
                        ]
                    }
                }
            }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions