pluginBeautify
A plugin that formats HTML, CSS, and JS at build time.
See the guide for setup and examples. This page covers settings and constraints.
Table of Contents
Options
pluginBeautify({
src: ["**/*.{html,css,js}"],
htmlOptions: {
indent_size: 2,
max_preserve_newlines: 0,
indent_inner_html: true,
extra_liners: [],
inline: ["span", "strong", "b", "small", "del", "s", "code", "br", "wbr"],
},
cssOptions: {
indent_size: 2,
space_around_combinator: true,
},
jsOptions: {
indent_size: 2,
},
})src
- Type:
string[] - Default:
["**/*.{html,css,js}"]
Specify files to format as globs relative to the output directory. For example, ["**/*.html"] targets HTML in the directory set by build.outDir. Files generated by the build are selected using picomatch.
htmlOptions
- Type:
HTMLBeautifyOptions
js-beautify settings for HTML formatting.
cssOptions
- Type:
CSSBeautifyOptions
js-beautify settings for CSS formatting.
jsOptions
- Type:
JSBeautifyOptions
js-beautify settings for JavaScript formatting.
Output constraints
Set build.rolldownOptions.output.minify: false when formatting JavaScript. With build.minify: false alone, Rolldown's later dce-only processing overwrites formatting. JS entryFileNames and chunkFileNames can use [hash].
When formatting CSS, set assetFileNames to a string without [hash], such as "assets/[name][extname]". CSS is formatted after names are finalized, so hashed names or function-based naming stop the build with MINISTA_BEAUTIFY_CSS_HASH_UNSUPPORTED.
js-beautify does not generate source maps, so combining formatting with source maps for the target JS or CSS stops the build with MINISTA_BEAUTIFY_SOURCEMAP_UNSUPPORTED. This includes external CSS maps and inline map references. Exclude such files with a setting such as src: ["**/*.html"] if you need source maps. Excluded JS, CSS, and maps are unchanged.
Combining formatting with subsequent JS minification produces MINISTA_BEAUTIFY_MINIFY_UNSUPPORTED. These constraints are validated when matching output exists. Transformations by later custom plugins are not covered.
Formatting makes delivered files readable. Spaces and line breaks increase uncompressed sizes, so if transfer size is a priority, limit targets to HTML or remove this plugin and use Vite's minification.
Preload migration
removeImagePreload moved to pluginSsg and defaults to true. The old option has been removed from Beautify’s public types, so TypeScript reports an error when it is specified. Untyped callers, such as JavaScript code, also fail at build time with MINISTA_BEAUTIFY_OPTION_MOVED. Move the same value to pluginSsg and remove it from Beautify. See pluginSsg for details.