Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility upgrade #140

Merged
merged 2 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading