Skip to content

Commit

Permalink
fix transformId
Browse files Browse the repository at this point in the history
  • Loading branch information
imal1 committed Sep 18, 2024
1 parent e5033bd commit f7cd0ff
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 12 deletions.
2 changes: 1 addition & 1 deletion playground/iconfont.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default defineConfig([
{
url: '//at.alicdn.com/t/c/font_3998853_ms3o2yu816s.js',
fileName: 'iconfont-common.js',
prefix: 'iconfont-',
prefix: 'iconfont',
iconJson: true,
iconifyJson: true,
},
Expand Down
2 changes: 1 addition & 1 deletion playground/iconfont.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion playground/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import Unplugin from '../src/vite'
export default defineConfig({
plugins: [
Inspect(),
Unplugin(),
Unplugin({ configFile: './iconfont.config.ts' }),
],
})
12 changes: 3 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ let frameConfig: any

export const unpluginFactory: UnpluginFactory<Options | undefined> = options => ({
name: 'unplugin-iconfont',
transformInclude(id) {
return (
id.endsWith('iconfont.config.', id.length - 2)
|| id.endsWith('iconfont.config.', id.length - 3)
)
},
async transform() {
let config = Array.isArray(options) ? options : options ? [options] : [] as any[]
config = (await loadConfig({
Expand All @@ -30,10 +24,10 @@ export const unpluginFactory: UnpluginFactory<Options | undefined> = options =>
],
defaults: config,
})).config
if (!config.length || !config.every(c => c.url))
if (!config.length || !config.every(c => c.url || c.configFile))
this.error(`Options url parameter is required`)

config = config.map((c) => {
config = config.filter(c => c.url).map((c) => {
const urlArr = c.url.split(/\//g)
return Object.assign(
{
Expand Down Expand Up @@ -66,7 +60,7 @@ export const unpluginFactory: UnpluginFactory<Options | undefined> = options =>
if (c.prefix) {
URL_CONTENT = URL_CONTENT.replace(
/<symbol id="/g,
`<symbol id="${c.prefix}`,
`<symbol id="${c.prefix}${c.separator}`,
)
}

Expand Down

0 comments on commit f7cd0ff

Please sign in to comment.