From 587accab8a40e1bd29a8459c33303d7ba78a4aa3 Mon Sep 17 00:00:00 2001 From: Alexey Makarenya Date: Sun, 26 Sep 2021 14:55:07 +0300 Subject: [PATCH] webpack5 support --- lib/icons-to-woff.js | 4 ++-- lib/loader.js | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/icons-to-woff.js b/lib/icons-to-woff.js index 9052863..6728667 100644 --- a/lib/icons-to-woff.js +++ b/lib/icons-to-woff.js @@ -11,7 +11,7 @@ const Readable = require('stream').Readable; * @param {typeof import("fs")} fs An input file system * @param {String[]} icons Array of icon file paths * @param {{name: string, enforcedSvgHeight?: number}} options SVG-Font options - * @return {Promise} Base64 encoded font + * @return {Promise} Base64 encoded font */ module.exports = function createIconFont (fs, icons, options) { assert(typeof options === 'object', 'Options are mandatory.'); @@ -60,5 +60,5 @@ module.exports = function createIconFont (fs, icons, options) { }) .then((svgFont) => svg2ttf(svgFont, {}).buffer) .then((ttfFont) => ttf2woff(ttfFont).buffer) - .then((woffFont) => Buffer.from(woffFont).toString('base64')); + .then((woffFont) => Buffer.from(woffFont)); }; diff --git a/lib/loader.js b/lib/loader.js index 491440e..2ca0037 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -22,12 +22,17 @@ module.exports = function () { const query = loaderUtils.parseQuery(this.query); // Add svgs to webpack file watching: query.svgs.forEach((svg) => this.addDependency(path.resolve(svg))); + const v5 = typeof this.utils != 'undefined'; // Generate the fonts createIconFont(this._compiler.inputFileSystem, query.svgs, query) .then((result) => { // Return the font to webpack - const url = '"data:application/x-font-woff;charset=utf-8;base64,' + result + '"'; - callback(null, 'module.exports=' + JSON.stringify(url) + ';'); + if (v5) { + callback(null, result); + } else { + const url = '"data:application/x-font-woff;charset=utf-8;base64,' + result.toString('base64') + '"'; + callback(null, 'module.exports=' + JSON.stringify(url) + ';'); + } }, function (err) { // In case of an svg generation error return an invalid font and throw an error const url = '"data:application/x-font-woff;charset=utf-8;base64,"';