Skip to content

Commit

Permalink
refactor: simplify the transformIndexHtml utility function (#1147)
Browse files Browse the repository at this point in the history
Co-authored-by: Alec Larson <1925840+aleclarson@users.noreply.github.com>
  • Loading branch information
victornpb and aleclarson authored Nov 26, 2020
1 parent 7a298b7 commit 6ea0e85
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/node/utils/transformUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,14 @@ export async function transformIndexHtml(
apply: 'pre' | 'post',
isBuild = false
) {
const trans = transforms
.map((t) => {
return typeof t === 'function' && apply === 'post'
? t
: t.apply === apply
? t.transform
: undefined
})
.filter(Boolean)
let code = html
for (const transform of trans) {
code = await transform!({ isBuild, code })
for (let t of transforms) {
if (typeof t === 'function') {
t = { apply: 'post', transform: t }
}
if (t.apply === apply) {
code = await t.transform({ isBuild, code })
}
}
return code
}

0 comments on commit 6ea0e85

Please sign in to comment.