diff --git a/packages/core/src/htmlPlugin.ts b/packages/core/src/htmlPlugin.ts
index dea54f0..1a1dff2 100644
--- a/packages/core/src/htmlPlugin.ts
+++ b/packages/core/src/htmlPlugin.ts
@@ -26,6 +26,27 @@ export function createPlugin(userOptions: UserOptions = {}): PluginOption {
let viteConfig: ResolvedConfig
let env: Record = {}
+ const transformIndexHtmlHandler = async (html, ctx) => {
+ const url = ctx.filename
+ const base = viteConfig.base
+ const excludeBaseUrl = url.replace(base, '/')
+ const htmlName = path.relative(process.cwd(), excludeBaseUrl)
+
+ const page = getPage(userOptions, htmlName, viteConfig)
+ const { injectOptions = {} } = page
+ const _html = await renderHtml(html, {
+ injectOptions,
+ viteConfig,
+ env,
+ entry: page.entry || entry,
+ verbose,
+ })
+ const { tags = [] } = injectOptions
+ return {
+ html: _html,
+ tags: tags,
+ }
+ }
return {
name: 'vite:html',
@@ -93,30 +114,18 @@ export function createPlugin(userOptions: UserOptions = {}): PluginOption {
)
},
- transformIndexHtml: {
- enforce: 'pre',
- async transform(html, ctx) {
- const url = ctx.filename
- const base = viteConfig.base
- const excludeBaseUrl = url.replace(base, '/')
- const htmlName = path.relative(process.cwd(), excludeBaseUrl)
-
- const page = getPage(userOptions, htmlName, viteConfig)
- const { injectOptions = {} } = page
- const _html = await renderHtml(html, {
- injectOptions,
- viteConfig,
- env,
- entry: page.entry || entry,
- verbose,
- })
- const { tags = [] } = injectOptions
- return {
- html: _html,
- tags: tags,
- }
+ transformIndexHtml: userOptions.viteNext
+ ?
+ {
+ // @ts-ignore
+ order: 'pre',
+ handler: transformIndexHtmlHandler,
+ }
+ :
+ {
+ enforce: 'pre',
+ transform: transformIndexHtmlHandler,
},
- },
async closeBundle() {
const outputDirs: string[] = []
diff --git a/packages/core/src/typing.ts b/packages/core/src/typing.ts
index b50ddf6..9c2d17a 100644
--- a/packages/core/src/typing.ts
+++ b/packages/core/src/typing.ts
@@ -58,4 +58,9 @@ export interface UserOptions {
* @default false
*/
verbose?: boolean
+
+ /**
+ * fit vite2+
+ */
+ viteNext?: boolean
}