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

Remove base64 fallbacks and set as default option #18

Merged
merged 1 commit into from
Aug 5, 2024
Merged
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export default defineNuxtConfig({
targetDirPath: "icon-font",
// font formats to generate, fallback to ["woff2"] in case browserslist is not used, example for manual configuration: ["svg", "ttf", "woff", "woff2", "eot"] in any order
formats: getFontFormatsList(browserslist()),
// Support of generating the most popular font as base64
base64: false,
// Generates font in memory as "woff" and injects it as base64 to reduce page jump effect, ignores "formats" option
base64: true,
// unicode symbol for first icon in iconfont (makes sense to change only if you're not going to use custom properties)
unicode: "0xE900",
// generated custom properties (variables) format. Other options are: "snake", "pascal", "camel", "header", "constant"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coremyslo/nuxt-icon-font",
"version": "1.1.0",
"version": "1.2.0",
"description": "Nuxt icon font generator",
"repository": {
"type": "git",
Expand Down
26 changes: 14 additions & 12 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default defineNuxtModule<ModuleOptions>({
sourceDirPath: "assets/icon-font",
targetDirPath: "icon-font",
formats: getFontFormatsList(browserslist(), true),
base64: false,
base64: true,
unicode: FontGenerator.optionsDefault.unicode,
case: IconGenerator.optionsDefault.case,
},
Expand Down Expand Up @@ -101,22 +101,24 @@ export default defineNuxtModule<ModuleOptions>({
hash: "iefix",
},
};
options.formats.slice().reverse().forEach((value, index) => {
options.formats.slice().forEach((value, index) => {
const font = fontGenerator.fonts.get(value);
const url = `${targetDirPath}/${options.name}`.replace(new RegExp(`^.*\/${nuxt.options.dir.public}\/`), "");
if (font) {
if (index === 0) {
if (value === "eot") {
text += `url('/${url}.eot?${font.uuid}');\n`;
text += " src: ";
if (options.base64) {
if (value === "woff") {
const base64 = Buffer.from(font.value).toString("base64");
text += `url(data:${meta[value].data};charset=utf-8;base64,${base64}) format('${meta[value].format || value}')`;
}
} else {
text += ",\n ";
}
if (options.base64 && options.formats[0] === value) {
const base64 = Buffer.from(font.value).toString("base64");
text += `url(data:${meta[value].data};charset=utf-8;base64,${base64}) format('${meta[value].format || value}')`;
} else {
if (index === 0) {
if (value === "eot") {
text += `url(/'${url}.eot?${font.uuid}');\n`;
text += " src: ";
}
} else {
text += ",\n ";
}
text += `url('/${url}.${value}?${font.uuid}${meta[value].hash ? `#${meta[value].hash}` : ""}') format('${meta[value].format || value}')`;
}
}
Expand Down