Plugin allowing to render compilation information as additional outputs.
npm install --save-dev webpack
(dependencies)npm install --save-dev compilation-info-webpack-plugin
interface CompilationInfoPluginOptions {
/**
* Template rendered for each compilation. Template model is `Compilation`.
*/
compilationTemplate?: CompilationInfoPluginTemplateOptions;
/**
* Template rendered for each entry point. Template model is `EntryPoint`.
*/
entryPointTemplate?: CompilationInfoPluginTemplateOptions;
}
interface CompilationInfoPluginTemplateOptions {
/**
* Handlebars template string.
*/
template: string;
/**
* Output filename. Allowed tokens:
* - Compilation: --
* - Entry point: [name]
*/
output: string;
}
Sample webpack configuration to print out all chunks as script
tags for ASP.NET Core Razor Pages:
{
plugins: [
new CompilationInfoPlugin({
entryPointTemplate: {
output: '../../Pages/Generated/_[name].cshtml',
template: `@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
{{#each chunks}}
{{#each files}}
<script src="~/assets/{{replace name '@' '@@'}}" asp-append-version="true"></script>
{{/each}}
{{/each}}
`
}
}),
]
};
interface Compilation {
entryPoints: EntryPoint[];
}
interface EntryPoint {
name: string;
chunks: Chunk[];
}
interface Chunk {
files: File[];
}
interface File {
name: string;
}
{
"entryPoints": [
{
"name": "main",
"chunks": [
{
"files": [
{
"name": "main.js"
}
]
}
]
}
]
}