ecomfe / fontmin

Minify font seamlessly
http://ecomfe.github.io/fontmin
MIT License
5.62k stars 311 forks source link

Support ESM #99

Closed edwardnyc closed 3 weeks ago

edwardnyc commented 2 years ago

Do you have any plans to support ESM? It will be very helpful for vite developers

la3rence commented 1 year ago

i've published a package called fontmin-esm as a work around with this this branch for ESM support: https://github.com/ecomfe/fontmin/pull/96

VFVrPQ commented 1 year ago

how to use fontmin-esm, I have a error when use import Fontmin from'fontmin-esm'` @ @Lonor

eltorio commented 1 year ago

@VFVrPQ Hi I had the same issue as you so I ported fontmin to Typescript and target it as ESM/ES2020 but it is now a strict ES module my rep is https://github.com/highcanfly-club/fontminify I change the name for avoiding conflicts

for using:

npm i @sctg/fontminify
import Fontmin from '@sctg/fontminify';

const fontminify = new Fontmin()
    .src('*.ttf')
    .dest('./fonts');

fontminify.run(function (err, files) {
    if (err) {
        throw err;
    }

    console.log(files[0]);
    // => { contents: <Buffer 00 01 00 ...> }
});

or in Typescript®

import Fontminify from '@sctg/fontminify';
import type {FontminifyFile} from '@sctg/fontminify';

const fontminify = new Fontminify()
    .src('*.ttf')
    .dest('./fonts');

fontminify.run(function (err:Error, files:FontminifyFile[]) {
    if (err) {
        throw err;
    }

    console.log(files[0]);
    // => { contents: <Buffer 00 01 00 ...> }
});

CLI is full of bug with options…

VFVrPQ commented 1 year ago

@eltorio I got a error when I use @sctg/fontminify. Uncaught TypeError: util.inherits is not a function at node_modules/_ordered-read-streams@1.0.1@ordered-read-streams/index.js (index.js:95:6) at __require2 (chunk-S5KM4IGW.js?v=1997ebc3:18:50) at node_modules/_glob-stream@6.1.0@glob-stream/index.js (index.js:3:15) at __require2 (chunk-S5KM4IGW.js?v=1997ebc3:18:50) at node_modules/_vinyl-fs@3.0.3@vinyl-fs/lib/src/index.js (index.js:3:10) at __require2 (chunk-S5KM4IGW.js?v=1997ebc3:18:50) at node_modules/_vinyl-fs@3.0.3@vinyl-fs/index.js (index.js:4:8) at __require2 (chunk-S5KM4IGW.js?v=1997ebc3:18:50) at node_modules/_@sctg_fontminify@1.0.1@@sctg/fontminify/index.js (index.js:13:11) at __require2 (chunk-S5KM4IGW.js?v=1997ebc3:18:50)