Skip to content

Broken minifications in CommonJS module #373

@maltsev

Description

@maltsev

I noticed a very weird bug. When importing htmlnano as an ESM module (import htmlnano from 'htmlnano') everything works well. But when importing as a CommonJS module (const htmlnano = require('htmlnano')), some minificators fail.

Here is an example:

const fs = require('fs'); 
const htmlnano = require('htmlnano');

const html = fs.readFileSync('./w3.org.html', 'utf8');

console.log(html.length);
// Shows 50000

htmlnano.process(html).then((result) => {
  console.log(result.html.length); 
  // Shows 49834
});
import fs from 'fs'; 
import htmlnano from 'htmlnano';

const html = fs.readFileSync('./w3.org.html', 'utf8');

console.log(html.length);
// Shows 50000

htmlnano.process(html).then((result) => {
  console.log(result.html.length); 
  // Shows 39557
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions