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

Allow customizing the fontFace URL for production environment through cssFontsUrl. #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { promisify } from 'util';
import { relative } from 'path';
import _webfontGenerator from '@vusion/webfonts-generator';
import { setupWatcher, MIME_TYPES, guid, ensureDirExistsAndWriteFile } from './utils';
import { parseOptions, parseFiles } from './optionParser';
Expand Down Expand Up @@ -81,9 +82,12 @@ export function viteSvgToWebfont<T extends GeneratedFontTypes = GeneratedFontTyp
}
await generate();
if (isBuild) {
const cssFontsUrl = processedOptions.cssFontsUrl ? relative(processedOptions.dest, processedOptions.cssFontsUrl) : 'assets';
const emitted = processedOptions.types.map<[T, string]>(type => [
type,
`/${this.getFileName(this.emitFile({ type: 'asset', fileName: `assets/${processedOptions.fontName}-${guid()}.${type}`, source: generatedFonts?.[type] }))}`,
`/${this.getFileName(
this.emitFile({ type: 'asset', fileName: `assets/${processedOptions.fontName}-${guid()}.${type}`, source: generatedFonts?.[type] }),
).replace('assets', cssFontsUrl)}`,
Comment on lines +89 to +90
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this work also?

Suggested change
this.emitFile({ type: 'asset', fileName: `assets/${processedOptions.fontName}-${guid()}.${type}`, source: generatedFonts?.[type] }),
).replace('assets', cssFontsUrl)}`,
this.emitFile({ type: 'asset', fileName: `${cssFontsUrl}/${processedOptions.fontName}-${guid()}.${type}`, source: generatedFonts?.[type] }),
)`,

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried, but unfortunately, it appears to be unsuccessful.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this mean we emit the file to 1 location (assets), and then import it from another location (cssFontsUrl)?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, indeed. It may be because I specified rollupOptions.build.out, so the emitted files will be placed in the assets folder under the out directory.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this work when not setting that setting as you have?
Would you be willing to fix this if not?

]);
fileRefs = Object.fromEntries(emitted) as { [Ref in T]: string };
}
Expand Down