Skip to content

Commit

Permalink
chore: update to [email protected] and remove ttf2woff2 (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArTiSTiX authored Mar 18, 2022
1 parent fcfcad4 commit a2cc27a
Show file tree
Hide file tree
Showing 4 changed files with 1,735 additions and 2,552 deletions.
10 changes: 4 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ const crypto = require('crypto')
const log = require('debug')('fontmin-webpack')

const _ = require('lodash')
const ttf2woff2 = require('ttf2woff2')
const Fontmin = require('fontmin')
const RawSource = require('webpack-sources').RawSource

const FONT_REGEX = /\.(eot|ttf|svg|woff|woff2)$/
const TEXT_REGEX = /\.(js|css|html)$/
const GLYPH_REGEX = /content\s*:[^};]*?('|")(.*?)\s*('|"|;)/g
const UNICODE_REGEX = /\\([0-9a-f]{4,6})/i
const FONTMIN_EXTENSIONS = ['eot', 'woff', 'svg']
const FONTMIN_EXTENSIONS = ['eot', 'woff', 'woff2', 'svg']

function getSurrogatePair(astralCodePoint) {
const highSurrogate = Math.floor((astralCodePoint - 0x10000) / 0x400) + 0xD800
Expand Down Expand Up @@ -154,14 +153,13 @@ class FontminPlugin {
const byExtension = _.keyBy(files, 'extname')
return group
.map(item => {
const isWoff2 = item.extension === '.woff2'
const extension = isWoff2 ? '.ttf' : item.extension
const extension = item.extension
const buffer = byExtension[extension] && byExtension[extension].contents
if (!buffer) {
return undefined
}

const minified = isWoff2 ? ttf2woff2(buffer) : buffer
const minified = buffer
return _.assign(item, {minified})
})
.filter(Boolean)
Expand Down Expand Up @@ -220,7 +218,7 @@ class FontminPlugin {
return prev
.then(() => this.minifyFontGroup(group, glyphs))
.then(files => {
files.forEach(file => {
return files.forEach(file => {
if (file.buffer.length > file.minified.length) {
if (appendHash) {
const newAssetName = this.appendMinifiedFileHash(file)
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"start:extract-text": "webpack --config test/fixtures/webpack.extract-text.config.js",
"start:debug": "node --inspect --debug-brk ./node_modules/.bin/webpack --config test/fixtures/webpack.config.js",
"test": "npm run test:lint && npm run test:unit",
"test:lint": "lint",
"test:lint": "lint node",
"test:unit": "mocha --reporter spec test/*.test.js test/**/*.test.js",
"test:watch": "mocha --watch --reporter dot test/*.test.js test/**/*.test.js"
},
Expand All @@ -29,9 +29,8 @@
},
"dependencies": {
"debug": "^4.3.1",
"fontmin": "^0.9.8",
"fontmin": "^0.9.9",
"lodash": "^4.17.21",
"ttf2woff2": "^4.0.1",
"webpack-sources": "^2.2.0"
},
"peerDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const FONT_AWESOME_FOLDER = path.join(__dirname, '../node_modules/font-awesome')

describe('FontminPlugin', () => {
let fontStats
const baseConfig = require('./fixtures/webpack.config.js')
const baseExtractConfig = require('./fixtures/webpack.extract-text.config.js')
const baseUnicodeConfig = require('./fixtures/webpack.unicode.config.js')
const baseConfig = require('./fixtures/webpack.config')
const baseExtractConfig = require('./fixtures/webpack.extract-text.config')
const baseUnicodeConfig = require('./fixtures/webpack.unicode.config')
const originalStats = collectFontStats(FONT_AWESOME_FOLDER + '/fonts', {
'fontawesome-webfont.eot': true,
'fontawesome-webfont.ttf': true,
Expand Down
Loading

0 comments on commit a2cc27a

Please sign in to comment.