{"id":22580,"library":"vite-plugin-archiver","title":"vite-plugin-archiver","description":"A Vite plugin that archives the build output into a ZIP or TAR file after a successful build. Current stable version 0.3.2, released sporadically with no fixed cadence. Only supports ESM imports. Key differentiator: integrates deeply with Vite's build lifecycle and uses archiver.js for archive creation, with options for output type, compression level, filename templates (using dayjs), and auto-open of archive directory. Requires Vite 6/7/8. Ships TypeScript types. Lightweight with no other runtime dependencies.","status":"active","version":"0.3.2","language":"javascript","source_language":"en","source_url":"https://github.com/hooray/vite-plugin-archiver","tags":["javascript","typescript"],"install":[{"cmd":"npm install vite-plugin-archiver","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-archiver","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-archiver","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Plugin designed to work as a Vite plugin, requires Vite 6/7/8","package":"vite","optional":false}],"imports":[{"note":"Module is ESM-only; CommonJS require() will fail. Default export is the plugin function.","wrong":"const ArchiverPlugin = require('vite-plugin-archiver')","symbol":"default","correct":"import ArchiverPlugin from 'vite-plugin-archiver'"},{"note":"TypeScript users should import the options type for type safety. The default export is still the plugin.","wrong":"","symbol":"default (with type)","correct":"import type { VitePluginArchiverOptions } from 'vite-plugin-archiver'"},{"note":"The plugin is a function that returns a Vite plugin object; no need to access a subproperty.","wrong":"export default defineConfig({\n  plugins: [ArchiverPlugin({ archiveType: 'zip' }).plugin] // No .plugin property\n})","symbol":"plugin usage in vite.config.ts","correct":"import { defineConfig } from 'vite';\nimport ArchiverPlugin from 'vite-plugin-archiver';\n\nexport default defineConfig({\n  plugins: [ArchiverPlugin({ archiveType: 'zip' })]\n})"}],"quickstart":{"code":"// install: npm i vite-plugin-archiver -D\n\n// vite.config.ts\nimport { defineConfig } from 'vite'\nimport ArchiverPlugin from 'vite-plugin-archiver'\n\nexport default defineConfig({\n  build: {\n    outDir: 'dist'\n  },\n  plugins: [\n    ArchiverPlugin({\n      archiveType: 'zip',          // 'zip' or 'tar'\n      archiveZipOptions: {\n        zlib: { level: 9 }        // compression level (0-9)\n      },\n      formatTemplate: 'YYYY-MM-DD-HH-mm-ss',  // date-based filename\n      open: false                  // auto-open archive directory?\n    })\n  ]\n})\n\n// After build, creates dist/2025-03-25-12-00-00.zip (or .tar)","lang":"typescript","description":"Quick setup of vite-plugin-archiver with ZIP output, custom name template, and compression options."},"warnings":[{"fix":"Upgrade Vite to ^6.0.0 || ^7.0.0 || ^8.0.0; or pin plugin to v0.2.x for Vite 5 support.","message":"Since v0.3.0, Vite 6+ is required; Vite 5 and below are no longer supported.","severity":"breaking","affected_versions":">=0.3.0"},{"fix":"Use import instead of require, and ensure your project is configured for ESM (e.g., \"type\": \"module\" in package.json).","message":"Since v0.2.0, the plugin is ESM-only. CommonJS require() will throw an error.","severity":"breaking","affected_versions":">=0.2.0"},{"fix":"Explicitly set build.outDir in Vite config, or ensure the output directory is generated by Vite.","message":"The default archive directory is Vite's build.outDir. If outDir is not set, it defaults to 'dist'. Make sure outDir exists or is created during build.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use dayjs-compatible format tokens: YYYY, MM, DD, HH, mm, ss, etc.","message":"The formatTemplate uses dayjs formatting tokens. If you include invalid tokens (e.g., 'YYYY' is valid, but 'YYY' is not), the archive filename will have unexpected characters.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Set open: false in CI environments, or use an environment variable to conditionally enable it.","message":"The 'open' option is intended to open the archive directory after build. This may not work in headless CI environments or on all operating systems.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Switch to import syntax or set \"type\": \"module\" in package.json. If using TypeScript, ensure esModuleInterop is enabled.","cause":"Using CommonJS require() to load the plugin in a CJS project.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module"},{"fix":"Use ArchiverPlugin directly as a function: plugins: [ArchiverPlugin({...})]","cause":"Default import assumed the plugin is an object with a 'plugin' property, but the module exports a function directly.","error":"TypeError: ArchiverPlugin is not a function"},{"fix":"Install a compatible Vite version: npm install vite@^6.0.0","cause":"Vite is not installed or version mismatched (plugin requires Vite 6/7/8).","error":"Error: Cannot find module 'vite'"},{"fix":"Use archiveType: 'tar' and optionally set archiveTarOptions.gzip: true.","cause":"Passing an unsupported archive type like 'tgz' (should be 'tar' for gzipped tar).","error":"Error: Invalid archive type: 'tgz'. Supported types are 'zip' and 'tar'."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}