Skip to content

Commit

Permalink
Compatibility upgrade (vbenjs#140)
Browse files Browse the repository at this point in the history
* docs: perfect README.md for the UserOptions of viteNext

* feat: remove viteNext, compatibility with different versions of vite using new way
  • Loading branch information
ryomahan authored and gao.boyu committed Feb 19, 2024
1 parent 85e88ad commit bd8c27a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
28 changes: 16 additions & 12 deletions packages/core/src/htmlPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@ import fg from 'fast-glob'
import consola from 'consola'
import { dim } from 'colorette'
import history from 'connect-history-api-fallback'
import * as vite from 'vite'

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

const bodyInjectRE = /<\/body>/

function getViteMajorVersion() {
return vite?.version ? Number(vite.version.split('.')[0]) : 2
}

export function createPlugin(userOptions: UserOptions = {}): PluginOption {
const {
entry,
Expand Down Expand Up @@ -114,18 +119,17 @@ export function createPlugin(userOptions: UserOptions = {}): PluginOption {
)
},

transformIndexHtml: userOptions.viteNext
?
{
// @ts-ignore
order: 'pre',
handler: transformIndexHtmlHandler,
}
:
{
enforce: 'pre',
transform: transformIndexHtmlHandler,
},
transformIndexHtml:
getViteMajorVersion() >= 5
? {
// @ts-ignore
order: 'pre',
handler: transformIndexHtmlHandler,
}
: {
enforce: 'pre',
transform: transformIndexHtmlHandler,
},
async closeBundle() {
const outputDirs: string[] = []

Expand Down
5 changes: 0 additions & 5 deletions packages/core/src/typing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,4 @@ export interface UserOptions {
* @default false
*/
verbose?: boolean

/**
* fit vite2+
*/
viteNext?: boolean
}

0 comments on commit bd8c27a

Please sign in to comment.