Skip to content

Commit db853cb

Browse files
committed
fix: vitest need a require to find node-html-parser parse function
1 parent 2ef8732 commit db853cb

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

packages/core/src/htmlPlugin.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ import type { InjectOptions, PageOption, Pages, UserOptions } from './typing'
33
import { render } from 'ejs'
44
import { isDirEmpty, loadEnv } from './utils'
55
import { normalizePath } from 'vite'
6-
import parse from 'node-html-parser'
76
import fs from 'fs-extra'
87
import path from 'pathe'
98
import fg from 'fast-glob'
109
import consola from 'consola'
1110
import { dim } from 'colorette'
1211
import history from 'connect-history-api-fallback'
1312

13+
// needed for vitest to find parse function
14+
// eslint-disable-next-line @typescript-eslint/no-var-requires
15+
const htmlParser = require('node-html-parser')
16+
1417
const DEFAULT_TEMPLATE = 'index.html'
1518
const ignoreDirs = ['.', '', '/']
1619

@@ -254,8 +257,7 @@ export function removeEntryScript(html: string, verbose = false) {
254257
if (!html) {
255258
return html
256259
}
257-
258-
const root = parse(html, { comment: true })
260+
const root = htmlParser.parse(html, { comment: true })
259261
const scriptNodes = root.querySelectorAll('script[type=module]') || []
260262
const removedNode: string[] = []
261263
scriptNodes.forEach((item) => {

0 commit comments

Comments
 (0)