@@ -60,27 +60,17 @@ export function createPlugin(userOptions: UserOptions = {}): PluginOption {
6060 const url = cleanUrl ( req . url || '' )
6161 const base = viteConfig . base
6262 const excludeBaseUrl = url . replace ( base , '/' )
63-
6463 if ( ! htmlFilter ( url ) && excludeBaseUrl !== '/' ) {
6564 return next ( )
6665 }
67-
6866 try {
6967 const htmlName =
7068 excludeBaseUrl === '/' ? DEFAULT_TEMPLATE : url . replace ( '/' , '' )
7169
7270 const page = getPage ( userOptions , htmlName , viteConfig )
7371
74- const { injectOptions = { } } = page
7572 let html = await getHtmlInPages ( page , viteConfig . root )
7673
77- html = await renderHtml ( html , {
78- injectOptions,
79- viteConfig,
80- env,
81- entry : page . entry || entry ,
82- verbose,
83- } )
8474 if ( server . transformIndexHtml ) {
8575 html = await server . transformIndexHtml ( url , html , req . originalUrl )
8676 }
@@ -90,6 +80,30 @@ export function createPlugin(userOptions: UserOptions = {}): PluginOption {
9080 }
9181 } )
9282 } ,
83+
84+ transformIndexHtml : {
85+ enforce : 'pre' ,
86+ async transform ( html , ctx ) {
87+ const url = ctx . filename
88+ const base = viteConfig . base
89+ const excludeBaseUrl = url . replace ( base , '/' )
90+ const htmlName = path . relative ( process . cwd ( ) , excludeBaseUrl )
91+ const page = getPage ( userOptions , htmlName , viteConfig )
92+ const { injectOptions = { } } = page
93+ const _html = await renderHtml ( html , {
94+ injectOptions,
95+ viteConfig,
96+ env,
97+ entry : page . entry || entry ,
98+ verbose,
99+ } )
100+ const { tags = [ ] } = injectOptions
101+ return {
102+ html : _html ,
103+ tags : tags ,
104+ }
105+ } ,
106+ } ,
93107 transform ( code , id ) : Promise < TransformResult > | TransformResult {
94108 if ( viteConfig . command === 'build' && htmlFilter ( id ) ) {
95109 const htmlName = id
0 commit comments