Skip to content

Commit 4c5f042

Browse files
authored
Compatibility upgrade (#140)
* docs: perfect README.md for the UserOptions of viteNext * feat: remove viteNext, compatibility with different versions of vite using new way
1 parent ad22da1 commit 4c5f042

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

packages/core/src/htmlPlugin.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@ import fg from 'fast-glob'
1010
import consola from 'consola'
1111
import { dim } from 'colorette'
1212
import history from 'connect-history-api-fallback'
13+
import * as vite from 'vite'
1314

1415
const DEFAULT_TEMPLATE = 'index.html'
1516
const ignoreDirs = ['.', '', '/']
1617

1718
const bodyInjectRE = /<\/body>/
1819

20+
function getViteMajorVersion() {
21+
return vite?.version ? Number(vite.version.split('.')[0]) : 2
22+
}
23+
1924
export function createPlugin(userOptions: UserOptions = {}): PluginOption {
2025
const {
2126
entry,
@@ -114,18 +119,17 @@ export function createPlugin(userOptions: UserOptions = {}): PluginOption {
114119
)
115120
},
116121

117-
transformIndexHtml: userOptions.viteNext
118-
?
119-
{
120-
// @ts-ignore
121-
order: 'pre',
122-
handler: transformIndexHtmlHandler,
123-
}
124-
:
125-
{
126-
enforce: 'pre',
127-
transform: transformIndexHtmlHandler,
128-
},
122+
transformIndexHtml:
123+
getViteMajorVersion() >= 5
124+
? {
125+
// @ts-ignore
126+
order: 'pre',
127+
handler: transformIndexHtmlHandler,
128+
}
129+
: {
130+
enforce: 'pre',
131+
transform: transformIndexHtmlHandler,
132+
},
129133
async closeBundle() {
130134
const outputDirs: string[] = []
131135

packages/core/src/typing.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,4 @@ export interface UserOptions {
5858
* @default false
5959
*/
6060
verbose?: boolean
61-
62-
/**
63-
* fit vite2+
64-
*/
65-
viteNext?: boolean
6661
}

0 commit comments

Comments
 (0)