juliendargelos / rollup-plugin-html-minifier

Rollup plugin to minify HTML output files using html-minifier.
MIT License
4 stars 0 forks source link

Doesn't work with @rollup/plugin-html #5

Closed DrSensor closed 3 years ago

DrSensor commented 4 years ago

Somehow it doesn't minify index.html produced by @rollup/plugin-html

my config (more or less)

plugins: [...
      require('@rollup/plugin-html')({
        title: pkg.name,
        attributes: {
          link: [
            { rel: 'manifest', href: '/manifest.json' }
          ],
        },
        meta: [
          { charset: 'utf-8' },
          { name: 'author', content: pkg.author },
          { name: 'description', content: pkg.description },
          { name: 'keywords', content: pkg.keywords },
          { // https://www.smashingmagazine.com/2012/10/design-your-own-mobile-game
            name: 'viewport',
            content: 'width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1, user-scalable=0'
          },
          { name: 'theme-color', content: 'transparent' }, // transparent statusbar
          { name: 'color-scheme', content: 'normal' }, // no dark mode
          { name: 'mobile-web-app-capable', content: 'yes' },
        ],
      }),
      require('rollup-plugin-html-minifier')(),
...]

related https://github.com/rollup/plugins/issues/120

ruddenchaux commented 3 years ago

@juliendargelos thank you for the plugin. I have used this plugin with @rollup/plugin-html and work well toghether. My rollup configs is:

import html from '@rollup/plugin-html';
import htmlMinifier from 'rollup-plugin-html-minifier';

export default {
  input: 'src/index.js',
  output: {
    file: './dist/main.js',
    format: 'iife'
  },
  plugins: [
    // generate html for serve bundle
    html(),
    // minify the html
    htmlMinifier({
      collapseWhitespace: true,
      removeComments: true,
      removeRedundantAttributes: true,
      removeScriptTypeAttributes: true,
      removeStyleLinkTypeAttributes: true,
      useShortDoctype: true,
      minifyCSS: true,
      minifyJS: true
    })
  ]
};
juliendargelos commented 3 years ago

@DrSensor The plugin does work, but as said on the html-minifier readme:

Most of the options are disabled by default.

You need to provide some options to get an actual minification (see @ruddenchaux's answer for instance).