Skip to content

Commit

Permalink
chore: fixed id error
Browse files Browse the repository at this point in the history
  • Loading branch information
vtrbo committed Aug 12, 2023
1 parent 53173e4 commit aaed0ad
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/index.ts
@@ -1,30 +1,28 @@
import { createUnplugin } from 'unplugin'
import chokidar from 'chokidar'
import createDebugger from 'debug'
import type { ResolvedConfig, ViteDevServer } from 'vite'
import type { Options } from './types'
import { UNPLUGIN_NAME } from './core/constants'
import { generateComponentFromPath, generateImagePath, isImagePath, normalizeImagePath } from './core/loader'
import { Context } from './core/context'

const debug = createDebugger(`${UNPLUGIN_NAME}:unplugin`)

const unplugin = createUnplugin<Options>((options = {}) => {
const ctx = new Context(options)

return {
name: UNPLUGIN_NAME,
enforce: 'pre',
resolveId(id) {
if (isImagePath(id))
return generateImagePath(normalizeImagePath(id))
return null
},
loadInclude(id) {
return isImagePath(id)
},
load(id) {
if (isImagePath(id)) {
debug('load id =>', id)
id = generateImagePath(normalizeImagePath(id))
debug('resolved id =>', id)
const config = ctx.options
debug('load config =>', config)
return generateComponentFromPath(id, config, ctx)
}
return null
Expand Down

0 comments on commit aaed0ad

Please sign in to comment.