How vuefilespreview/vue-files-preview works
Project type and purpose
• This is an open‑source Vue 3 plugin/library (vue‑files‑preview) that provides a single component for previewing a wide variety of file formats (docx, xlsx, pdf, image, audio, video, code, markdown, epub, txt, etc.).
• It’s delivered as an npm package and can also be deployed via CDN.
File structure
• Top‑level folders:
• .github (CI/CD workflows, issue/pull templates)
• packages (core TypeScript source & subfolders)
• public and assets (static files and images)
• scripts & vite‑plugins (build/version scripts and custom Vite plugins)
• configuration (tsconfig, eslint, vite.config.ts)
• packages/index.ts exports the plugin;
packages/preview holds the “engine” (constants, interfaces, utils) and a supports subfolder containing one submodule per file type.
Extract architecture insights from the README
• The core plugin “VueFilesPreview” registers a single component that inspects the passed file, picks the right preview renderer, and displays it.
• Some previews use only native HTML (img, audio, video), others leverage third‑party libraries (vue‑office for docx/xlsx/pdf, codemirror for code, markdown‑it for markdown, epubjs for epub).
• CI/CD (GitHub Actions under .github/workflows) builds, runs tests, and publishes to NPM and CDN.
a. Developer / Consumer
→ uses npm or CDN to install VueFilesPreview
→ in their Vue 3 app calls app.use(VueFilesPreview) and embeds <VueFilesPreview> in templates
b. VueFilesPreview Plugin (packages/index.ts)
↳ registers the “VueFilesPreview” component globally
c. Preview Engine (packages/preview)
• preview.const.ts (file‑type mapping)
• preview.interface.ts (common props/events)
• utils/utils.ts (file reading & common helpers)
→ dispatches to the selected renderer
d. Preview Renderers (packages/preview/supports/*)
– audio‑preview (native <audio> + canvas)
– video‑preview (native <video>)
– pic‑preview (native <img>)
– code‑preview (CodeMirror)
– md‑preview (markdown‑it)
– pdf‑preview, docx‑preview, xlsx‑preview (vue‑office)
– epub‑preview (epubjs)
– txt‑preview (native text block)
e. External libraries & assets
• vue‑office, codemirror, markdown‑it, epubjs
f. Build & Release Pipeline
• Vite (vite.config.ts + vite‑plugins)
• Custom scripts (build‑version.ts, copy.plugin.ts)
• GitHub Actions (deploy.yml, release‑cdn.yml, contributors.yml)
• Outputs: ESM/CJS bundles, style.css, TypeScript declarations
• Publishes to npm registry & CDN
Architectural patterns & principles
• Single‑entry plugin exporting a unified API
• Strategy/Dispatcher pattern for selecting preview modules
• Modular design: one renderer per file type, easy to extend
• Separation of concerns: core engine vs. renderers vs. build pipeline
• CI/CD‑driven automated releases
• Entry and exit points: Developer import → plugin API → rendering → browser DOM