Skip to content

Commit

Permalink
refactor: inject attr
Browse files Browse the repository at this point in the history
  • Loading branch information
hemengke1997 committed Sep 15, 2023
1 parent 60327a6 commit dfde99e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { assert } from './helper/assert'
import { globalConfigBuilder } from './helper/GlobalConfigBuilder'
import { initCacheProcessor } from './helper/processor'
import { ManifestCache } from './helper/ManifestCache'
import { VPPT_DATA_ATTR, getScriptInfo, nodeIsElement, traverseHtml } from './helper/html'
import { getScriptInfo, nodeIsElement, traverseHtml } from './helper/html'
import { injectScripts } from './plugins/inject-script'

const debug = createDebug('vite-plugin-public-typescript:index ===> ')
Expand Down Expand Up @@ -287,10 +287,15 @@ export default function publicTypescript(options: VPPTPluginOptions = {}) {
const fileName = path.basename(src.value).split('.')[0]
cacheItem = c[fileName]
}
if (cacheItem) {

if (cacheItem.path) {
const attrs = node.attrs
.reduce((acc, attr) => {
if (attr.name === VPPT_DATA_ATTR) {
if (attr.name === vppt.name) {
return acc
}
if (attr.name === src.name) {
acc += ` ${attr.name}="${cacheItem!.path}"`
return acc
}
acc += ` ${attr.name}="${attr.value}"`
Expand Down

0 comments on commit dfde99e

Please sign in to comment.