Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webpack 5 support #61

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/icons-to-woff.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>} Base64 encoded font
* @return {Promise<Buffer>} Base64 encoded font
*/
module.exports = function createIconFont (fs, icons, options) {
assert(typeof options === 'object', 'Options are mandatory.');
Expand Down Expand Up @@ -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));
};
9 changes: 7 additions & 2 deletions lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,"';
Expand Down