Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ import type { LoaderOptions } from '../types';

type LocalFontSrc = string | Array<{ path: string; weight?: string; style?: string }>;

export async function getFontFaceDeclarations(options: LoaderOptions, rootContext: string) {
export async function getFontFaceDeclarations(
options: LoaderOptions,
rootContext: string,
swcMode: boolean
) {
const localFontSrc = options.props.src as LocalFontSrc;

// Parent folder relative to the root context
const parentFolder = path
.dirname(path.join(getProjectRoot(), options.filename))
.replace(rootContext, '');
const parentFolder = swcMode
? path.dirname(path.join(getProjectRoot(), options.filename)).replace(rootContext, '')
: path.dirname(options.filename).replace(rootContext, '');

const { validateData } = require('../utils/local-font-utils');
const { weight, style, variable } = validateData('', options.props);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type FontFaceDeclaration = {

export default async function storybookNextjsFontLoader(this: any) {
const loaderOptions = this.getOptions() as LoaderOptions;
let swcMode = false;
let options;

if (Object.keys(loaderOptions).length > 0) {
Expand All @@ -23,6 +24,7 @@ export default async function storybookNextjsFontLoader(this: any) {
} else {
// handles SWC mode
const importQuery = JSON.parse(this.resourceQuery.slice(1));
swcMode = true;

options = {
filename: importQuery.path,
Expand All @@ -42,7 +44,7 @@ export default async function storybookNextjsFontLoader(this: any) {
}

if (options.source.endsWith('next/font/local') || options.source.endsWith('@next/font/local')) {
fontFaceDeclaration = await getLocalFontFaceDeclarations(options, rootCtx);
fontFaceDeclaration = await getLocalFontFaceDeclarations(options, rootCtx, swcMode);
}

if (typeof fontFaceDeclaration !== 'undefined') {
Expand Down
Loading