File tree Expand file tree Collapse file tree 2 files changed +16
-17
lines changed Expand file tree Collapse file tree 2 files changed +16
-17
lines changed Original file line number Diff line number Diff line change @@ -10,12 +10,17 @@ import fg from 'fast-glob'
1010import consola from 'consola'
1111import { dim } from 'colorette'
1212import history from 'connect-history-api-fallback'
13+ import * as vite from 'vite'
1314
1415const DEFAULT_TEMPLATE = 'index.html'
1516const ignoreDirs = [ '.' , '' , '/' ]
1617
1718const bodyInjectRE = / < \/ b o d y > /
1819
20+ function getViteMajorVersion ( ) {
21+ return vite ?. version ? Number ( vite . version . split ( '.' ) [ 0 ] ) : 2
22+ }
23+
1924export 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
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments