mirror of
https://github.com/iconify/iconify.git
synced 2024-12-13 22:18:24 +00:00
feat(next): split modern loader for node and browser support
This commit is contained in:
parent
65dfecf963
commit
062a852a79
@ -2,6 +2,7 @@ import type { Awaitable } from '@antfu/utils';
|
|||||||
import { promises as fs, Stats } from 'fs';
|
import { promises as fs, Stats } from 'fs';
|
||||||
import type { CustomIconLoader } from './types';
|
import type { CustomIconLoader } from './types';
|
||||||
import { camelize, pascalize } from '../misc/strings';
|
import { camelize, pascalize } from '../misc/strings';
|
||||||
|
import { isNode } from './loader';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns CustomIconLoader for loading icons from a directory
|
* Returns CustomIconLoader for loading icons from a directory
|
||||||
@ -10,7 +11,8 @@ export function FileSystemIconLoader(
|
|||||||
dir: string,
|
dir: string,
|
||||||
transform?: (svg: string) => Awaitable<string>
|
transform?: (svg: string) => Awaitable<string>
|
||||||
): CustomIconLoader {
|
): CustomIconLoader {
|
||||||
return async (name) => {
|
return isNode
|
||||||
|
? async (name) => {
|
||||||
const paths = [
|
const paths = [
|
||||||
`${dir}/${name}.svg`,
|
`${dir}/${name}.svg`,
|
||||||
`${dir}/${camelize(name)}.svg`,
|
`${dir}/${camelize(name)}.svg`,
|
||||||
@ -30,5 +32,5 @@ export function FileSystemIconLoader(
|
|||||||
: svg;
|
: svg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
} : () => undefined;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user