Skip to content

Commit

Permalink
feat: also expose correspodning chunk in build html transform
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jan 6, 2021
1 parent caf4bef commit b2f4836
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion docs/guide/api-plugin.md
Expand Up @@ -246,7 +246,8 @@ Vite plugins can also provide hooks that serve Vite-specific purposes. These hoo
path: string
filename: string
server?: ViteDevServer
bundle?: OutputBundle
bundle?: import('rollup').OutputBundle
chunk?: import('rollup').OutputChunk
}
) =>
| IndexHtmlTransformResult
Expand Down
12 changes: 8 additions & 4 deletions packages/vite/src/node/plugins/html.ts
Expand Up @@ -295,7 +295,8 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
id,
postHooks,
undefined,
bundle
bundle,
chunk
)

this.emitFile({
Expand Down Expand Up @@ -337,6 +338,7 @@ export interface IndexHtmlTransformContext {
filename: string
server?: ViteDevServer
bundle?: OutputBundle
chunk?: OutputChunk
}

export type IndexHtmlTransformHook = (
Expand Down Expand Up @@ -377,17 +379,19 @@ export async function applyHtmlTransforms(
filename: string,
hooks: IndexHtmlTransformHook[],
server?: ViteDevServer,
bundle?: OutputBundle
bundle?: OutputBundle,
chunk?: OutputChunk
): Promise<string> {
const headTags: HtmlTagDescriptor[] = []
const headPrependTags: HtmlTagDescriptor[] = []
const bodyTags: HtmlTagDescriptor[] = []

const ctx = {
const ctx: IndexHtmlTransformContext = {
path,
filename,
server,
bundle
bundle,
chunk
}

for (const hook of hooks) {
Expand Down

0 comments on commit b2f4836

Please sign in to comment.