Delivery archives
pluginArchive() packages build output as ZIP or TAR archives when the build finishes. Here, combine it with Code formatting for delivery to generate files for delivery.
Table of Contents
- Add the archive plugin
- Input and archive contents
- Set the archive name
- Exclude unwanted files
- Change the source and format
Add the archive plugin
import { defineConfig, pluginSsg, pluginBeautify, pluginArchive } from "minista"
export default defineConfig({
plugins: [
pluginSsg(),
pluginBeautify({ src: ["**/*.html"] }),
pluginArchive(),
],
})Running npm run build creates dist/dist.zip containing the default output directory, dist/. No separate command is needed to create the archive.
Input and archive contents
dist/
├── index.html
├── about.html
├── assets/
│ └── ...
└── dist.zipdist/
├── index.html
├── about.html
└── assets/
└── ...Paths inside the archive include the input directory name: dist/index.html in this example. Configured archive destinations are excluded from compression, preventing the ZIP from including itself.
Extract the archive before delivery and confirm that the HTML, assets, and files copied from public are all included.
Set the archive name
Specify the name without an extension. The following configuration generates dist/downloads/site.zip.
pluginArchive({
archives: [{ outName: "downloads/site" }],
})archives is an array. Add multiple configurations to create multiple archives in one build. The supplied array replaces the default configuration.
Exclude unwanted files
Specify exclusions as globs based on paths from the project root.
pluginArchive({
archives: [
{
outName: "site",
ignore: ["dist/**/*.map", "dist/internal/**"],
},
],
})Old archives removed from the configuration and ZIP files placed separately are not automatically excluded. Add exclusions if you leave them in the output directory.
Change the source and format
If the input is omitted, the output directory resolved from build.outDir is used. For example, with build.outDir: "output", the default archive is output/dist.zip.
Use srcDir to compress another directory. You can also choose TAR format.
pluginArchive({
archives: [
{ srcDir: "dist", outName: "site" },
{ srcDir: "dist", outName: "site-tar", format: "tar", options: {} },
],
})The build stops if the input directory does not exist or the path is not a directory. See pluginArchive for settings and diagnostics.