@@ -19,7 +19,8 @@ export interface GetOutputHTMLParams {
1919 emittedAssets : EmittedAssets ;
2020 pluginOptions : RollupPluginHTMLOptions ;
2121 entrypointBundles : Record < string , EntrypointBundle > ;
22- externalTransformHtmlFns ?: TransformHtmlFunction [ ] ;
22+ inputExternalTransformHtmlFns ?: TransformHtmlFunction [ ] ;
23+ outputExternalTransformHtmlFns ?: TransformHtmlFunction [ ] ;
2324 defaultInjectDisabled : boolean ;
2425 serviceWorkerPath : string ;
2526 injectServiceWorker : boolean ;
@@ -31,7 +32,8 @@ export async function getOutputHTML(params: GetOutputHTMLParams) {
3132 const {
3233 pluginOptions,
3334 entrypointBundles,
34- externalTransformHtmlFns,
35+ inputExternalTransformHtmlFns,
36+ outputExternalTransformHtmlFns,
3537 input,
3638 outputDir,
3739 emittedAssets,
@@ -44,8 +46,20 @@ export async function getOutputHTML(params: GetOutputHTMLParams) {
4446 const { default : defaultBundle , ...multiBundles } = entrypointBundles ;
4547 const { absoluteSocialMediaUrls = true , rootDir = process . cwd ( ) } = pluginOptions ;
4648
49+ let inputHtml = input . html ;
50+
51+ // run transform functions on input HTML
52+ const inputTransforms = [ ...( inputExternalTransformHtmlFns ?? [ ] ) ] ;
53+ for ( const transform of inputTransforms ) {
54+ inputHtml = await transform ( inputHtml , {
55+ bundle : defaultBundle ,
56+ bundles : multiBundles ,
57+ htmlFileName : input . name ,
58+ } ) ;
59+ }
60+
4761 // inject rollup output into HTML
48- let document = parse ( input . html ) ;
62+ let document = parse ( inputHtml ) ;
4963 if ( pluginOptions . extractAssets !== false ) {
5064 injectedUpdatedAssetPaths ( {
5165 document,
@@ -75,17 +89,17 @@ export async function getOutputHTML(params: GetOutputHTMLParams) {
7589
7690 let outputHtml = serialize ( document ) ;
7791
78- const transforms = [ ...( externalTransformHtmlFns ?? [ ] ) ] ;
92+ const outputTransforms = [ ...( outputExternalTransformHtmlFns ?? [ ] ) ] ;
7993 if ( pluginOptions . transformHtml ) {
8094 if ( Array . isArray ( pluginOptions . transformHtml ) ) {
81- transforms . push ( ...pluginOptions . transformHtml ) ;
95+ outputTransforms . push ( ...pluginOptions . transformHtml ) ;
8296 } else {
83- transforms . push ( pluginOptions . transformHtml ) ;
97+ outputTransforms . push ( pluginOptions . transformHtml ) ;
8498 }
8599 }
86100
87101 // run transform functions on output HTML
88- for ( const transform of transforms ) {
102+ for ( const transform of outputTransforms ) {
89103 outputHtml = await transform ( outputHtml , {
90104 bundle : defaultBundle ,
91105 bundles : multiBundles ,
0 commit comments