@file-viewer/vite-plugin 3.2.2 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +5 -1
- package/README.md +60 -56
- package/README.zh-CN.md +198 -0
- package/dist/index.js +108 -32
- package/package.json +3 -2
package/README.en.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# @file-viewer/vite-plugin
|
|
2
2
|
|
|
3
|
+
[English](https://github.com/flyfish-dev/file-viewer/blob/main/packages/presets/vite-plugin/README.md) · [简体中文](https://github.com/flyfish-dev/file-viewer/blob/main/packages/presets/vite-plugin/README.zh-CN.md)
|
|
4
|
+
|
|
3
5
|
<!-- FILE_VIEWER_PACKAGE_HEADER -->
|
|
4
6
|
<p>
|
|
5
7
|
<a href="https://www.npmjs.com/package/@file-viewer/vite-plugin"><img src="https://img.shields.io/npm/v/@file-viewer%2Fvite-plugin?logo=npm" alt="npm version"></a>
|
|
@@ -9,7 +11,7 @@
|
|
|
9
11
|
</p>
|
|
10
12
|
|
|
11
13
|
<p>
|
|
12
|
-
<a href="https://github.com/flyfish-dev/file-viewer">GitHub</a> · <a href="https://doc.file-viewer.app/">Docs</a> · <a href="https://demo.file-viewer.app/">Live demo</a> · <a href="https://doc.file-viewer.app/guide/formats">Format matrix</a> · <a href="https://github.com/flyfish-dev/file-viewer/issues">Issues</a> · <a href="https://github.com/flyfish-dev/file-viewer/blob/main/packages/presets/vite-plugin/README.md">简体中文</a>
|
|
14
|
+
<a href="https://github.com/flyfish-dev/file-viewer">GitHub</a> · <a href="https://doc.file-viewer.app/">Docs</a> · <a href="https://demo.file-viewer.app/">Live demo</a> · <a href="https://doc.file-viewer.app/guide/formats">Format matrix</a> · <a href="https://github.com/flyfish-dev/file-viewer/issues">Issues</a> · <a href="https://github.com/flyfish-dev/file-viewer/blob/main/packages/presets/vite-plugin/README.zh-CN.md">简体中文</a>
|
|
13
15
|
</p>
|
|
14
16
|
|
|
15
17
|
<p>
|
|
@@ -118,6 +120,8 @@ When host apps split `node_modules` by package name, circular dependencies betwe
|
|
|
118
120
|
|
|
119
121
|
`copyAssets.baseDir` overrides automatic placement. It must be relative and cannot contain `..`; an empty string explicitly selects the root. The plugin now aligns the shared runtime asset base for standard packages, presets, and full packages; full packages also keep `setDefaultFullAssetBaseUrl()` synchronized. Only integrations that set `inject:false` and do not import the virtual module must call `setDefaultFileViewerAssetBaseUrl()` themselves (plus `setDefaultFullAssetBaseUrl()` for a full package). With Vite `base:'/app/'`, full-package dev URLs start with `/app/file-viewer/...`, while production files remain under `outDir/file-viewer/`.
|
|
120
122
|
|
|
123
|
+
Asset copying runs at dev-server startup/restart and after a production build, not on ordinary HMR. Files with identical contents are left untouched, and generated manifests omit the volatile `copiedAt` timestamp. Vite's own output cleanup and public-directory copying remain unchanged.
|
|
124
|
+
|
|
121
125
|
For strict registry control, disable injection and pass the virtual module explicitly:
|
|
122
126
|
|
|
123
127
|
```ts
|
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# @file-viewer/vite-plugin
|
|
2
2
|
|
|
3
|
+
[English](https://github.com/flyfish-dev/file-viewer/blob/main/packages/presets/vite-plugin/README.md) · [简体中文](https://github.com/flyfish-dev/file-viewer/blob/main/packages/presets/vite-plugin/README.zh-CN.md)
|
|
4
|
+
|
|
3
5
|
<!-- FILE_VIEWER_PACKAGE_HEADER -->
|
|
4
6
|
<p>
|
|
5
7
|
<a href="https://www.npmjs.com/package/@file-viewer/vite-plugin"><img src="https://img.shields.io/npm/v/@file-viewer%2Fvite-plugin?logo=npm" alt="npm version"></a>
|
|
@@ -9,20 +11,20 @@
|
|
|
9
11
|
</p>
|
|
10
12
|
|
|
11
13
|
<p>
|
|
12
|
-
<a href="https://github.com/flyfish-dev/file-viewer">GitHub</a> · <a href="https://doc.file-viewer.app/
|
|
14
|
+
<a href="https://github.com/flyfish-dev/file-viewer">GitHub</a> · <a href="https://doc.file-viewer.app/">Docs</a> · <a href="https://demo.file-viewer.app/">Live demo</a> · <a href="https://doc.file-viewer.app/guide/formats">Format matrix</a> · <a href="https://github.com/flyfish-dev/file-viewer/issues">Issues</a> · <a href="https://github.com/flyfish-dev/file-viewer/blob/main/packages/presets/vite-plugin/README.zh-CN.md">简体中文</a>
|
|
13
15
|
</p>
|
|
14
16
|
|
|
15
17
|
<p>
|
|
16
|
-
<a href="https://demo.file-viewer.app/"><img src="https://raw.githubusercontent.com/flyfish-dev/file-viewer/main/docs/public/_media/file-viewer-demo-v3-
|
|
18
|
+
<a href="https://demo.file-viewer.app/"><img src="https://raw.githubusercontent.com/flyfish-dev/file-viewer/main/docs/public/_media/file-viewer-demo-v3-en.webp" width="760" alt="File Viewer live demo: Word, Excel, PowerPoint, 3D model, CAD drawing and binary inspector"></a>
|
|
17
19
|
</p>
|
|
18
20
|
|
|
19
|
-
> ⭐
|
|
21
|
+
> ⭐ If File Viewer helps you, please [star the repo on GitHub](https://github.com/flyfish-dev/file-viewer).
|
|
20
22
|
|
|
21
|
-
Flyfish File Viewer
|
|
23
|
+
Vite plugin for Flyfish File Viewer on-demand renderer assembly. It can auto-discover installed `@file-viewer/preset-*` and `@file-viewer/*-full` packages, so Vue, React, Svelte, jQuery, and Vanilla JS components receive matching preview capability without application code passing `renderers` manually. It can also generate `virtual:file-viewer-renderers` from declared formats, import only matching renderer packages, and provide renderer-oriented chunk planning plus offline worker/WASM/font asset copying.
|
|
22
24
|
|
|
23
|
-
##
|
|
25
|
+
## Fastest Start
|
|
24
26
|
|
|
25
|
-
|
|
27
|
+
For complete format support, the fastest path is one full package and one Vite plugin registration. Full packages already include `preset-all`; do not install another preset. `copyAssets:true` matches the installed full package and publishes its Worker, WASM, font, and vendor files under `file-viewer/` at the deployment base (`/file-viewer/` for a root deployment) in both dev and build:
|
|
26
28
|
|
|
27
29
|
```bash
|
|
28
30
|
pnpm add @file-viewer/vue3-full
|
|
@@ -42,29 +44,29 @@ export default defineConfig({
|
|
|
42
44
|
})
|
|
43
45
|
```
|
|
44
46
|
|
|
45
|
-
|
|
47
|
+
Installing a full package without publishing these assets leaves PDF Worker, CAD/Typst/Archive WASM, and other formats without runtime files. That is partial support, not a complete setup.
|
|
46
48
|
|
|
47
|
-
|
|
49
|
+
For a smaller install, use a standard component with one preset and keep the same Vite config. The plugin auto-discovers installed presets, so application code does not hand-write renderer imports and the plugin does not need `preset:'office'`:
|
|
48
50
|
|
|
49
51
|
```bash
|
|
50
52
|
pnpm add @file-viewer/vue3 @file-viewer/preset-office
|
|
51
53
|
pnpm add -D @file-viewer/vite-plugin
|
|
52
54
|
```
|
|
53
55
|
|
|
54
|
-
|
|
56
|
+
Components keep `autoRenderers:true` by default, so `@file-viewer/vue3`, `@file-viewer/react`, `@file-viewer/web`, `@file-viewer/svelte`, `@file-viewer/jquery`, `@file-viewer/vue2.7`, and `@file-viewer/vue2.6` automatically consume the injected preset / renderer registry.
|
|
55
57
|
|
|
56
|
-
|
|
58
|
+
Available presets:
|
|
57
59
|
|
|
58
|
-
- `@file-viewer/preset-lite`:
|
|
59
|
-
- `@file-viewer/preset-office`: PDF
|
|
60
|
-
- `@file-viewer/preset-engineering`: CAD
|
|
61
|
-
- `@file-viewer/preset-all`:
|
|
60
|
+
- `@file-viewer/preset-lite`: text, Markdown, code, image, audio, and video.
|
|
61
|
+
- `@file-viewer/preset-office`: PDF, Word, Excel, PowerPoint, OFD, RTF, and OpenDocument.
|
|
62
|
+
- `@file-viewer/preset-engineering`: CAD, 3D, drawing, XMind, Geo, Typst, Archive, Data, and EDA.
|
|
63
|
+
- `@file-viewer/preset-all`: the complete official demo format matrix.
|
|
62
64
|
|
|
63
|
-
|
|
65
|
+
Install individual renderer packages only for strict cuts, such as `@file-viewer/renderer-pdf`, `@file-viewer/renderer-word`, `@file-viewer/renderer-ofd`, `@file-viewer/renderer-presentation`, `@file-viewer/renderer-cad`, `@file-viewer/renderer-drawing`, `@file-viewer/renderer-3d`, `@file-viewer/renderer-data`, `@file-viewer/renderer-eda`, `@file-viewer/renderer-typst`, `@file-viewer/renderer-archive`, or `@file-viewer/renderer-text`, then use `formats` to generate exact imports.
|
|
64
66
|
|
|
65
67
|
## vite.config.ts
|
|
66
68
|
|
|
67
|
-
|
|
69
|
+
Prefer full/preset auto assembly for normal products. With only `copyAssets:true`, the plugin auto-discovers installed `@file-viewer/*-full` or `@file-viewer/preset-*` packages:
|
|
68
70
|
|
|
69
71
|
```ts
|
|
70
72
|
fileViewerRenderers({
|
|
@@ -72,7 +74,7 @@ fileViewerRenderers({
|
|
|
72
74
|
})
|
|
73
75
|
```
|
|
74
76
|
|
|
75
|
-
|
|
77
|
+
Use customization options only when you need source scanning, single-format cuts, or manual registry control:
|
|
76
78
|
|
|
77
79
|
```ts
|
|
78
80
|
import { defineConfig } from 'vite'
|
|
@@ -90,35 +92,37 @@ export default defineConfig({
|
|
|
90
92
|
})
|
|
91
93
|
```
|
|
92
94
|
|
|
93
|
-
`inject`
|
|
95
|
+
`inject` is enabled by default. The plugin injects `virtual:file-viewer-renderers` into Vite HTML entrypoints, preset imports register themselves in core, and framework components consume them through `autoRenderers`.
|
|
94
96
|
|
|
95
97
|
```ts
|
|
96
98
|
const options = {
|
|
97
|
-
//
|
|
99
|
+
// Defaults to true; set false when a product needs total manual control.
|
|
98
100
|
autoRenderers: true
|
|
99
101
|
}
|
|
100
102
|
```
|
|
101
103
|
|
|
102
|
-
###
|
|
104
|
+
### Customization Options
|
|
103
105
|
|
|
104
|
-
|
|
|
106
|
+
| Option | Description |
|
|
105
107
|
| --- | --- |
|
|
106
|
-
| `copyAssets` | `true`
|
|
107
|
-
| `preset` | `'auto' | 'lite' | 'office' | 'engineering' | 'all'
|
|
108
|
-
| `autoPresets` | `true`
|
|
109
|
-
| `formats` |
|
|
110
|
-
| `renderers` |
|
|
111
|
-
| `scan` | `true`
|
|
112
|
-
| `inject` |
|
|
113
|
-
| `chunkStrategy` | `'renderer' | 'none'
|
|
114
|
-
| `stabilizeInteropChunks` |
|
|
115
|
-
| `missingRenderer` | `'error' | 'warn' | 'ignore'
|
|
108
|
+
| `copyAssets` | `true` or `{ publicDir, outDir, mode, baseDir }`; copies matching Worker, WASM, font, and vendor assets. Installed full packages default to `<deployment-base>/file-viewer/`, which is required for complete full support; standard packages/presets keep the existing root behavior |
|
|
109
|
+
| `preset` | `'auto' | 'lite' | 'office' | 'engineering' | 'all'`; with no explicit formats, installed presets are discovered automatically |
|
|
110
|
+
| `autoPresets` | `true` or a preset list; useful with `scan:true` when installed presets should stay active |
|
|
111
|
+
| `formats` | File extensions or format tokens, for example `['pdf', 'docx', 'dwg']` |
|
|
112
|
+
| `renderers` | Renderer ids, for example `['pdf', 'word', 'cad']` |
|
|
113
|
+
| `scan` | `true` or `{ roots, extensions, maxFileSize }`; scans source hints and merges formats |
|
|
114
|
+
| `inject` | Defaults to `true`; set `false` to import `virtual:file-viewer-renderers` manually |
|
|
115
|
+
| `chunkStrategy` | `'renderer' | 'none'`; controls renderer-level chunk grouping |
|
|
116
|
+
| `stabilizeInteropChunks` | Defaults to `true`; keeps Pako / shared CommonJS helpers and CodeMirror / Lezer / Sandpack in stable groups for default and host-defined chunk splitting |
|
|
117
|
+
| `missingRenderer` | `'error' | 'warn' | 'ignore'`; controls notices for planned renderer mappings |
|
|
118
|
+
|
|
119
|
+
When host apps split `node_modules` by package name, circular dependencies between `@codemirror/*`, `@lezer/*`, and Sandpack can show up in production as `codemirror-view.* Cannot access ... before initialization`. The plugin stabilizes default chunk splitting and wraps existing `manualChunks` functions. Pako and shared CommonJS helpers use `vendor-commonjs` to prevent compressed-format initialization cycles; CodeMirror / Lezer / Sandpack use `vendor-codemirror`. Other custom groups remain intact, and Vite 8 receives equivalent Rolldown groups. Set `stabilizeInteropChunks:false` only when the host build needs total control.
|
|
116
120
|
|
|
117
|
-
|
|
121
|
+
`copyAssets.baseDir` overrides automatic placement. It must be relative and cannot contain `..`; an empty string explicitly selects the root. The plugin now aligns the shared runtime asset base for standard packages, presets, and full packages; full packages also keep `setDefaultFullAssetBaseUrl()` synchronized. Only integrations that set `inject:false` and do not import the virtual module must call `setDefaultFileViewerAssetBaseUrl()` themselves (plus `setDefaultFullAssetBaseUrl()` for a full package). With Vite `base:'/app/'`, full-package dev URLs start with `/app/file-viewer/...`, while production files remain under `outDir/file-viewer/`.
|
|
118
122
|
|
|
119
|
-
|
|
123
|
+
Asset copying runs at dev-server startup/restart and after a production build, not on ordinary HMR. Files with identical contents are left untouched, and generated manifests omit the volatile `copiedAt` timestamp. Vite's own output cleanup and public-directory copying remain unchanged.
|
|
120
124
|
|
|
121
|
-
|
|
125
|
+
For strict registry control, disable injection and pass the virtual module explicitly:
|
|
122
126
|
|
|
123
127
|
```ts
|
|
124
128
|
fileViewerRenderers({
|
|
@@ -137,7 +141,7 @@ const options = {
|
|
|
137
141
|
}
|
|
138
142
|
```
|
|
139
143
|
|
|
140
|
-
|
|
144
|
+
You can also use `preset: 'auto'` to discover installed preset packages. When `preset-all` is installed, it wins to avoid importing narrower presets twice. Note: when `scan:true` is enabled, use `preset:'auto'` or `autoPresets:true` explicitly; otherwise the plugin treats source hints as the explicit renderer selection and skips zero-config preset discovery.
|
|
141
145
|
|
|
142
146
|
```ts
|
|
143
147
|
fileViewerRenderers({
|
|
@@ -149,7 +153,7 @@ fileViewerRenderers({
|
|
|
149
153
|
})
|
|
150
154
|
```
|
|
151
155
|
|
|
152
|
-
`scan: true`
|
|
156
|
+
`scan: true` inspects common source folders for lightweight hints and merges them with `formats`:
|
|
153
157
|
|
|
154
158
|
```ts
|
|
155
159
|
export const fileViewerFormats = ['pdf', 'docx', 'xlsx']
|
|
@@ -159,36 +163,36 @@ export const fileViewerFormats = ['pdf', 'docx', 'xlsx']
|
|
|
159
163
|
<input accept=".pdf,.docx" data-file-viewer-formats="dwg,xmind" />
|
|
160
164
|
```
|
|
161
165
|
|
|
162
|
-
|
|
166
|
+
This is useful when upload accept lists, sample matrices, or attachment allow-lists already live in source code: dev and production builds can generate the renderer assembly module without a second hand-written import list.
|
|
163
167
|
|
|
164
|
-
##
|
|
168
|
+
## Missing Renderer Guidance
|
|
165
169
|
|
|
166
|
-
|
|
170
|
+
When a file extension is in the supported matrix but the current project has not assembled its renderer, core now shows an install-oriented “renderer assembly required” state with the recommended preset / renderer package. For example, `.pdf` points to `@file-viewer/preset-office` or `@file-viewer/renderer-pdf`. Only truly unknown extensions show an unsupported-format state.
|
|
167
171
|
|
|
168
|
-
##
|
|
172
|
+
## Nested Vite Projects
|
|
169
173
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
+
From 3.0.3, a nested metadata-only project can use a resolvable Full dependency
|
|
175
|
+
declared in an ancestor `package.json`. A nearer light component or preset keeps
|
|
176
|
+
its own root asset layout. Explicit `copyAssets.baseDir` still takes precedence;
|
|
177
|
+
`publicDir` and `build.outDir` stay relative to the Vite root, not the dependency owner.
|
|
174
178
|
|
|
175
|
-
##
|
|
179
|
+
## Current Boundary
|
|
176
180
|
|
|
177
|
-
|
|
181
|
+
The plugin currently generates imports for extracted renderer packages: Word, Spreadsheet, PDF, OFD, Presentation, CAD, Draw.io/Excalidraw/Mermaid/PlantUML, 3D, Data, EDA, Typst, archives, email, EPUB, code/Markdown/Patch/Git Bundle, image, media, XMind, and Geo. Declare them explicitly with `formats`, or let `scan: true` discover source hints automatically; core-supported extensions such as `.zipx`, `.cbz`, `.tiff`, `.mjs`, `.gv`, `.patch`, `.bundle`, `.mermaid`, `.puml`, and `.mpeg` also resolve to their renderer packages. With `copyAssets:true`, the plugin detects installed capability packages. Full packages copy matching assets into dev `publicDir/file-viewer/` and production `outDir/file-viewer/`; standard packages/presets keep the existing root placement, including the Typst compiler / renderer WASM files and default fonts. `preset: 'auto' | 'lite' | 'office' | 'engineering' | 'all'` imports matching `@file-viewer/preset-*` packages; when `formats` are also present, the plugin adds extra renderers outside the preset.
|
|
178
182
|
|
|
179
|
-
##
|
|
183
|
+
## Documentation
|
|
180
184
|
|
|
181
|
-
-
|
|
182
|
-
-
|
|
185
|
+
- On-demand renderer architecture: <https://doc.file-viewer.app/guide/on-demand-renderers>
|
|
186
|
+
- Supported formats: <https://doc.file-viewer.app/guide/formats>
|
|
183
187
|
|
|
184
|
-
##
|
|
188
|
+
## Formats and related packages
|
|
185
189
|
|
|
186
|
-
File Viewer
|
|
190
|
+
File Viewer previews 275+ file extensions in the browser, covering Office, PDF/OFD, CAD, 3D, archives, email, images, media and code, without server-side conversion. See the [format matrix](https://doc.file-viewer.app/guide/formats) for the full list.
|
|
187
191
|
|
|
188
|
-
-
|
|
189
|
-
-
|
|
190
|
-
-
|
|
192
|
+
- Components: `@file-viewer/web`, `@file-viewer/vue3`, `@file-viewer/vue2.7`, `@file-viewer/vue2.6`, `@file-viewer/react`, `@file-viewer/react-legacy`, `@file-viewer/svelte`, `@file-viewer/jquery`, plus their `-full` packages
|
|
193
|
+
- Presets: `@file-viewer/preset-lite`, `@file-viewer/preset-office`, `@file-viewer/preset-engineering`, `@file-viewer/preset-all`
|
|
194
|
+
- Build: `@file-viewer/vite-plugin`, `file-viewer-copy-assets`
|
|
191
195
|
|
|
192
|
-
##
|
|
196
|
+
## License
|
|
193
197
|
|
|
194
|
-
|
|
198
|
+
This package is Apache-2.0. See [LICENSE](https://github.com/flyfish-dev/file-viewer/blob/main/LICENSE).
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# @file-viewer/vite-plugin
|
|
2
|
+
|
|
3
|
+
[English](https://github.com/flyfish-dev/file-viewer/blob/main/packages/presets/vite-plugin/README.md) · [简体中文](https://github.com/flyfish-dev/file-viewer/blob/main/packages/presets/vite-plugin/README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
<!-- FILE_VIEWER_PACKAGE_HEADER -->
|
|
6
|
+
<p>
|
|
7
|
+
<a href="https://www.npmjs.com/package/@file-viewer/vite-plugin"><img src="https://img.shields.io/npm/v/@file-viewer%2Fvite-plugin?logo=npm" alt="npm version"></a>
|
|
8
|
+
<a href="https://www.npmjs.com/package/@file-viewer/vite-plugin"><img src="https://img.shields.io/npm/dm/@file-viewer%2Fvite-plugin?logo=npm" alt="npm downloads"></a>
|
|
9
|
+
<a href="https://github.com/flyfish-dev/file-viewer/stargazers"><img src="https://img.shields.io/github/stars/flyfish-dev/file-viewer?style=flat&logo=github" alt="GitHub stars"></a>
|
|
10
|
+
<a href="https://github.com/flyfish-dev/file-viewer/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-Apache--2.0-blue" alt="License: Apache-2.0"></a>
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
<p>
|
|
14
|
+
<a href="https://github.com/flyfish-dev/file-viewer">GitHub</a> · <a href="https://doc.file-viewer.app/zh/">文档</a> · <a href="https://demo.file-viewer.app/">在线 Demo</a> · <a href="https://doc.file-viewer.app/guide/formats">格式矩阵</a> · <a href="https://github.com/flyfish-dev/file-viewer/issues">问题反馈</a> · <a href="https://github.com/flyfish-dev/file-viewer/blob/main/packages/presets/vite-plugin/README.md">English</a>
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
<p>
|
|
18
|
+
<a href="https://demo.file-viewer.app/"><img src="https://raw.githubusercontent.com/flyfish-dev/file-viewer/main/docs/public/_media/file-viewer-demo-v3-zh.webp" width="760" alt="File Viewer 在线演示:Word、Excel、PPT、3D 模型、CAD 图纸与二进制检查器"></a>
|
|
19
|
+
</p>
|
|
20
|
+
|
|
21
|
+
> ⭐ 如果 File Viewer 对你有帮助,欢迎到 [GitHub](https://github.com/flyfish-dev/file-viewer) 点个 Star。
|
|
22
|
+
|
|
23
|
+
Flyfish File Viewer 的 Vite 按需 renderer 自动装配插件。它可以自动发现已安装的 `@file-viewer/preset-*` 和 `@file-viewer/*-full` 包,让 Vue、React、Svelte、jQuery 和 Vanilla JS 组件无需手动传 `renderers` 就获得对应预览能力;也可以根据业务声明的文件格式生成 `virtual:file-viewer-renderers`,只 import 命中的 renderer 包,并提供 chunk 分组和离线 worker/WASM/字体资源复制能力。
|
|
24
|
+
|
|
25
|
+
## 最快开始
|
|
26
|
+
|
|
27
|
+
需要完整格式支持时,最快路径是“full 包 + 注册一次 Vite 插件”。full 已内置 `preset-all`,不要再安装 preset;`copyAssets:true` 会在开发和构建时自动匹配 full 包,并把 Worker、WASM、字体和 vendor 文件发布到部署基址下的 `file-viewer/`(根部署即 `/file-viewer/`):
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pnpm add @file-viewer/vue3-full
|
|
31
|
+
pnpm add -D @file-viewer/vite-plugin
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { defineConfig } from 'vite'
|
|
36
|
+
import { fileViewerRenderers } from '@file-viewer/vite-plugin'
|
|
37
|
+
|
|
38
|
+
export default defineConfig({
|
|
39
|
+
plugins: [
|
|
40
|
+
fileViewerRenderers({
|
|
41
|
+
copyAssets: true
|
|
42
|
+
})
|
|
43
|
+
]
|
|
44
|
+
})
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
只安装 full 包而不启用资源复制,PDF Worker、CAD/Typst/Archive WASM 等格式会缺少运行文件,只能获得部分格式支持。
|
|
48
|
+
|
|
49
|
+
需要更小体积时,改用“标准组件包 + 一个 preset”,Vite 配置保持不变。插件会自动发现已安装的 preset,无需手写 renderer import,也无需显式写 `preset:'office'`:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pnpm add @file-viewer/vue3 @file-viewer/preset-office
|
|
53
|
+
pnpm add -D @file-viewer/vite-plugin
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
组件默认 `autoRenderers:true`,会读取 Vite 插件注入的 preset / renderer registry。常规业务代码只要使用 `@file-viewer/vue3`、`@file-viewer/react`、`@file-viewer/web`、`@file-viewer/svelte`、`@file-viewer/jquery`、`@file-viewer/vue2.7` 或 `@file-viewer/vue2.6` 即可获得对应能力。
|
|
57
|
+
|
|
58
|
+
可选 preset:
|
|
59
|
+
|
|
60
|
+
- `@file-viewer/preset-lite`: 文本、Markdown、代码、图片、音频、视频。
|
|
61
|
+
- `@file-viewer/preset-office`: PDF、Word、Excel、PowerPoint、OFD、RTF、OpenDocument。
|
|
62
|
+
- `@file-viewer/preset-engineering`: CAD、3D、绘图、XMind、Geo、Typst、Archive、Data、EDA。
|
|
63
|
+
- `@file-viewer/preset-all`: 官方 demo 完整格式矩阵。
|
|
64
|
+
|
|
65
|
+
如果只需要极少数格式,也可以安装对应 renderer 包,例如 `@file-viewer/renderer-pdf`、`@file-viewer/renderer-word`、`@file-viewer/renderer-ofd`、`@file-viewer/renderer-presentation`、`@file-viewer/renderer-cad`、`@file-viewer/renderer-drawing`、`@file-viewer/renderer-3d`、`@file-viewer/renderer-data`、`@file-viewer/renderer-eda`、`@file-viewer/renderer-typst`、`@file-viewer/renderer-archive`、`@file-viewer/renderer-text`,再通过 `formats` 做精确裁剪。
|
|
66
|
+
|
|
67
|
+
## vite.config.ts
|
|
68
|
+
|
|
69
|
+
推荐默认使用 full/preset 自动装配。只传 `copyAssets:true` 时,插件会自动发现已安装的 `@file-viewer/*-full` 或 `@file-viewer/preset-*`,无需写 `preset:'all'`:
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
fileViewerRenderers({
|
|
73
|
+
copyAssets: true
|
|
74
|
+
})
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
只有在需要源码扫描、单格式裁剪、或手动 registry 管理时,再使用自定义能力:
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
import { defineConfig } from 'vite'
|
|
81
|
+
import { fileViewerRenderers } from '@file-viewer/vite-plugin'
|
|
82
|
+
|
|
83
|
+
export default defineConfig({
|
|
84
|
+
plugins: [
|
|
85
|
+
fileViewerRenderers({
|
|
86
|
+
formats: ['pdf', 'dwg', 'typst', 'zip', 'xmind'],
|
|
87
|
+
scan: true,
|
|
88
|
+
copyAssets: true,
|
|
89
|
+
chunkStrategy: 'renderer'
|
|
90
|
+
})
|
|
91
|
+
]
|
|
92
|
+
})
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
`inject` 默认开启,插件会把 `virtual:file-viewer-renderers` 注入 Vite HTML 入口,preset 导入后会自动注册到 core。常规业务只需要安装组件包和对应 preset,组件会通过 `autoRenderers` 默认读取这些能力。
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
const options = {
|
|
99
|
+
// 默认 true;需要完全手动控制时设为 false。
|
|
100
|
+
autoRenderers: true
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### 可定制能力
|
|
105
|
+
|
|
106
|
+
| 选项 | 说明 |
|
|
107
|
+
| --- | --- |
|
|
108
|
+
| `copyAssets` | `true` 或 `{ publicDir, outDir, mode, baseDir }`;复制匹配的 Worker、WASM、字体和 vendor 资源。检测到 full 时默认发布到 `<部署基址>/file-viewer/`,这是 full 完整格式支持的必需项;标准包/preset 保持原有根目录行为 |
|
|
109
|
+
| `preset` | `'auto' | 'lite' | 'office' | 'engineering' | 'all'`;默认无显式格式时自动发现已安装 preset |
|
|
110
|
+
| `autoPresets` | `true` 或 preset 列表;常用于 `scan:true` 时继续自动激活已安装 preset |
|
|
111
|
+
| `formats` | 文件扩展名或格式 token,例如 `['pdf', 'docx', 'dwg']` |
|
|
112
|
+
| `renderers` | renderer id,例如 `['pdf', 'word', 'cad']` |
|
|
113
|
+
| `scan` | `true` 或 `{ roots, extensions, maxFileSize }`,扫描源码 hint 并合并格式 |
|
|
114
|
+
| `inject` | 默认 `true`;设为 `false` 后手动导入 `virtual:file-viewer-renderers` |
|
|
115
|
+
| `chunkStrategy` | `'renderer' | 'none'`,控制是否注入 renderer 级 chunk 分组 |
|
|
116
|
+
| `stabilizeInteropChunks` | 默认 `true`;为默认分组和宿主 `manualChunks` 稳定 Pako / CommonJS 辅助模块及 CodeMirror / Lezer / Sandpack 的分组 |
|
|
117
|
+
| `missingRenderer` | `'error' | 'warn' | 'ignore'`,控制尚未提取的 renderer 映射提示方式 |
|
|
118
|
+
|
|
119
|
+
如果宿主项目按包名拆分 `node_modules`,`@codemirror/*`、`@lezer/*` 和 Sandpack 之间的循环依赖可能在生产构建中表现为 `codemirror-view.* Cannot access ... before initialization`。插件同时稳定默认分组和已有的 `manualChunks` 函数:Pako 与共享 CommonJS 辅助模块归入 `vendor-commonjs`,避免压缩格式的初始化循环;CodeMirror / Lezer / Sandpack 归入 `vendor-codemirror`。Vite 8 使用对应的 Rolldown 分组,其它自定义分组保持不变;确实需要完全接管时可设置 `stabilizeInteropChunks:false`。
|
|
120
|
+
|
|
121
|
+
`copyAssets.baseDir` 可以覆盖自动目录:必须是相对路径,不能包含 `..`;传空字符串表示显式复制到根目录。插件会为标准包、preset 和 full 包同步统一运行时资源根;full 包仍同时同步 `setDefaultFullAssetBaseUrl()`。只有设置 `inject:false` 且不手动导入虚拟模块时,业务才需要调用 `setDefaultFileViewerAssetBaseUrl()`(full 包同时调用 `setDefaultFullAssetBaseUrl()`)。Vite 配置了 `base:'/app/'` 时,full 包开发 URL 为 `/app/file-viewer/...`,构建文件仍位于 `outDir/file-viewer/`。
|
|
122
|
+
|
|
123
|
+
资源复制在开发服务器启动/重启及生产构建结束时执行,不随普通 HMR 执行。内容相同的文件不会被重复写入,生成的清单不再包含易变的 `copiedAt` 时间戳。Vite 自身清空构建目录、复制 public 目录的行为保持不变。
|
|
124
|
+
|
|
125
|
+
如果你需要严格控制 registry,可以关闭注入并手动传入:
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
fileViewerRenderers({
|
|
129
|
+
formats: ['pdf'],
|
|
130
|
+
inject: false,
|
|
131
|
+
copyAssets: true
|
|
132
|
+
})
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
import { configuredFileViewerRenderers } from 'virtual:file-viewer-renderers'
|
|
137
|
+
|
|
138
|
+
const options = {
|
|
139
|
+
rendererMode: 'replace',
|
|
140
|
+
renderers: configuredFileViewerRenderers
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
也可以使用 `preset: 'auto'` 发现项目中已安装的 preset 包;当 `preset-all` 存在时会优先使用它,避免重复导入其它 preset。注意:如果同时开启 `scan:true`,请显式使用 `preset:'auto'` 或 `autoPresets:true`,否则插件会以源码 hint 为准,不再做“无配置 preset 自动发现”。
|
|
145
|
+
|
|
146
|
+
```ts
|
|
147
|
+
fileViewerRenderers({
|
|
148
|
+
preset: 'auto',
|
|
149
|
+
scan: true,
|
|
150
|
+
formats: ['pdf'],
|
|
151
|
+
copyAssets: true,
|
|
152
|
+
chunkStrategy: 'renderer'
|
|
153
|
+
})
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
`scan: true` 会扫描常见源码目录里的轻量 hint,并把它们合并到 `formats`:
|
|
157
|
+
|
|
158
|
+
```ts
|
|
159
|
+
export const fileViewerFormats = ['pdf', 'docx', 'xlsx']
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
```html
|
|
163
|
+
<input accept=".pdf,.docx" data-file-viewer-formats="dwg,xmind" />
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
这适合业务把上传入口、示例矩阵或附件白名单维护在源码中时使用:开发和构建阶段插件会自动生成 renderer 装配模块,少写一份手工 import 清单。
|
|
167
|
+
|
|
168
|
+
## 缺失 renderer 提示
|
|
169
|
+
|
|
170
|
+
如果用户打开的是支持矩阵内的格式,但项目没有安装或装配对应 renderer,core 会显示“需要装配预览能力”,并提示推荐安装的 preset / renderer 包,例如 `.pdf` 会引导安装 `@file-viewer/preset-office` 或 `@file-viewer/renderer-pdf`。只有真正不在支持矩阵中的扩展名才显示“不支持在线预览”。
|
|
171
|
+
|
|
172
|
+
## 嵌套 Vite 项目
|
|
173
|
+
|
|
174
|
+
从 3.0.3 起,子目录只有项目元数据或 Vite 插件声明时,会沿祖先 `package.json`
|
|
175
|
+
查找实际可解析的 Full 依赖。子项目明确声明轻量组件或 preset 时保留其根目录资产布局,
|
|
176
|
+
不会继承父项目的 Full 布局。`copyAssets.baseDir` 仍具有最高优先级;`publicDir`
|
|
177
|
+
和 `build.outDir` 均相对于 Vite root,不相对于依赖所在目录。
|
|
178
|
+
|
|
179
|
+
## 当前边界
|
|
180
|
+
|
|
181
|
+
当前插件会为已经拆出的 renderer 包生成导入:Word、Spreadsheet、PDF、OFD、Presentation、CAD、Draw.io/Excalidraw/Mermaid/PlantUML、3D、Data、EDA、Typst、压缩包、邮件、EPUB、代码/Markdown/Patch/Git Bundle、图片、媒体、XMind 和 Geo。可以通过 `formats` 显式声明,也可以通过 `scan: true` 从源码 hint 自动发现;`.zipx`、`.cbz`、`.tiff`、`.mjs`、`.gv`、`.patch`、`.bundle`、`.mermaid`、`.puml`、`.mpeg` 等 core 支持的扩展也会映射到对应 renderer。开启 `copyAssets:true` 时会识别已安装能力;full 包把匹配资源复制到开发 `publicDir/file-viewer/` 与构建 `outDir/file-viewer/`,标准包/preset 维持根目录行为,包括 Typst compiler / renderer WASM 与默认字体目录。`preset: 'auto' | 'lite' | 'office' | 'engineering' | 'all'` 会导入对应 `@file-viewer/preset-*` 包;如果同时声明 `formats`,插件会在 preset 之外补充额外 renderer。
|
|
182
|
+
|
|
183
|
+
## 文档
|
|
184
|
+
|
|
185
|
+
- 按需渲染架构: <https://doc.file-viewer.app/guide/on-demand-renderers>
|
|
186
|
+
- 支持格式: <https://doc.file-viewer.app/guide/formats>
|
|
187
|
+
|
|
188
|
+
## 格式与相关包
|
|
189
|
+
|
|
190
|
+
File Viewer 在浏览器内预览 275+ 种扩展名,覆盖 Office、PDF/OFD、CAD、3D、压缩包、邮件、图片、音视频和代码,无需服务端转码;完整清单见 [格式矩阵](https://doc.file-viewer.app/guide/formats)。
|
|
191
|
+
|
|
192
|
+
- 组件:`@file-viewer/web`、`@file-viewer/vue3`、`@file-viewer/vue2.7`、`@file-viewer/vue2.6`、`@file-viewer/react`、`@file-viewer/react-legacy`、`@file-viewer/svelte`、`@file-viewer/jquery`,以及对应的 `-full` 包
|
|
193
|
+
- 能力组合:`@file-viewer/preset-lite`、`@file-viewer/preset-office`、`@file-viewer/preset-engineering`、`@file-viewer/preset-all`
|
|
194
|
+
- 构建:`@file-viewer/vite-plugin`、`file-viewer-copy-assets`
|
|
195
|
+
|
|
196
|
+
## 许可证
|
|
197
|
+
|
|
198
|
+
本包采用 Apache-2.0。详见 [LICENSE](https://github.com/flyfish-dev/file-viewer/blob/main/LICENSE)。
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
2
|
-
import { copyFile,
|
|
2
|
+
import { copyFile, lstat, mkdir, readFile, readdir, realpath, rm, stat, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { createRequire } from 'node:module';
|
|
4
4
|
import { dirname, extname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
5
5
|
const virtualModuleId = 'virtual:file-viewer-renderers';
|
|
@@ -1440,6 +1440,42 @@ function createFileViewerResolveAliases(anchorPackages) {
|
|
|
1440
1440
|
.filter((alias) => Boolean(alias)));
|
|
1441
1441
|
return aliases;
|
|
1442
1442
|
}
|
|
1443
|
+
async function assetPathInfo(path) {
|
|
1444
|
+
try {
|
|
1445
|
+
return await lstat(path);
|
|
1446
|
+
}
|
|
1447
|
+
catch (error) {
|
|
1448
|
+
if (error.code === 'ENOENT')
|
|
1449
|
+
return null;
|
|
1450
|
+
throw error;
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
async function ensureAssetCopyDirectory(path, replace) {
|
|
1454
|
+
const info = await assetPathInfo(path);
|
|
1455
|
+
if (info?.isDirectory() && !info.isSymbolicLink())
|
|
1456
|
+
return;
|
|
1457
|
+
if (info) {
|
|
1458
|
+
if (!replace)
|
|
1459
|
+
throw new Error(`[file-viewer:vite-plugin] Unsafe asset directory ${path}.`);
|
|
1460
|
+
await rm(path, { recursive: info.isDirectory(), force: true });
|
|
1461
|
+
}
|
|
1462
|
+
await mkdir(path, { recursive: true });
|
|
1463
|
+
}
|
|
1464
|
+
async function writeAssetJsonIfChanged(path, value) {
|
|
1465
|
+
const manifest = { ...value };
|
|
1466
|
+
delete manifest.copiedAt;
|
|
1467
|
+
const content = `${JSON.stringify(manifest, null, 2)}\n`;
|
|
1468
|
+
const info = await assetPathInfo(path);
|
|
1469
|
+
if (info) {
|
|
1470
|
+
if (!info.isFile() || info.isSymbolicLink()) {
|
|
1471
|
+
throw new Error(`[file-viewer:vite-plugin] Unsafe asset manifest ${path}.`);
|
|
1472
|
+
}
|
|
1473
|
+
if (await readFile(path, 'utf8') === content)
|
|
1474
|
+
return;
|
|
1475
|
+
}
|
|
1476
|
+
await mkdir(dirname(path), { recursive: true });
|
|
1477
|
+
await writeFile(path, content);
|
|
1478
|
+
}
|
|
1443
1479
|
async function copyFileIfPresent(from, to) {
|
|
1444
1480
|
if (!from || !existsSync(from)) {
|
|
1445
1481
|
return false;
|
|
@@ -1448,21 +1484,66 @@ async function copyFileIfPresent(from, to) {
|
|
|
1448
1484
|
if (!info.isFile()) {
|
|
1449
1485
|
return false;
|
|
1450
1486
|
}
|
|
1487
|
+
const destination = await assetPathInfo(to);
|
|
1488
|
+
if (destination) {
|
|
1489
|
+
if (!destination.isFile() || destination.isSymbolicLink()) {
|
|
1490
|
+
throw new Error(`[file-viewer:vite-plugin] Unsafe asset file ${to}.`);
|
|
1491
|
+
}
|
|
1492
|
+
if (info.size === destination.size) {
|
|
1493
|
+
const [sourceBytes, destinationBytes] = await Promise.all([readFile(from), readFile(to)]);
|
|
1494
|
+
if (sourceBytes.equals(destinationBytes))
|
|
1495
|
+
return true;
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1451
1498
|
await mkdir(dirname(to), { recursive: true });
|
|
1452
1499
|
await copyFile(from, to);
|
|
1453
1500
|
return true;
|
|
1454
1501
|
}
|
|
1455
|
-
async function copyDirectoryIfPresent(from, to) {
|
|
1502
|
+
async function copyDirectoryIfPresent(from, to, options = {}) {
|
|
1456
1503
|
if (!from || !existsSync(from)) {
|
|
1457
1504
|
return false;
|
|
1458
1505
|
}
|
|
1459
|
-
const info = await
|
|
1506
|
+
const info = await lstat(from);
|
|
1507
|
+
if (info.isSymbolicLink()) {
|
|
1508
|
+
throw new Error(`[file-viewer:vite-plugin] Asset source is a symbolic link: ${from}.`);
|
|
1509
|
+
}
|
|
1460
1510
|
if (!info.isDirectory()) {
|
|
1461
1511
|
return false;
|
|
1462
1512
|
}
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1513
|
+
if (isPathWithin(from, to) || isPathWithin(to, from)) {
|
|
1514
|
+
throw new Error(`[file-viewer:vite-plugin] Asset source and destination overlap: ${from}, ${to}.`);
|
|
1515
|
+
}
|
|
1516
|
+
const entries = await readdir(from, { withFileTypes: true });
|
|
1517
|
+
if (entries.some(entry => entry.isSymbolicLink())) {
|
|
1518
|
+
throw new Error(`[file-viewer:vite-plugin] Asset source contains a symbolic link: ${from}.`);
|
|
1519
|
+
}
|
|
1520
|
+
await ensureAssetCopyDirectory(to, !options.merge);
|
|
1521
|
+
const excluded = new Set(options.exclude || []);
|
|
1522
|
+
if (!options.merge) {
|
|
1523
|
+
const names = new Set([...entries.map(entry => entry.name), ...excluded]);
|
|
1524
|
+
for (const entry of await readdir(to)) {
|
|
1525
|
+
if (!names.has(entry))
|
|
1526
|
+
await rm(join(to, entry), { recursive: true, force: true });
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
for (const entry of entries) {
|
|
1530
|
+
if (excluded.has(entry.name))
|
|
1531
|
+
continue;
|
|
1532
|
+
const source = join(from, entry.name), destination = join(to, entry.name);
|
|
1533
|
+
if (entry.isDirectory()) {
|
|
1534
|
+
await copyDirectoryIfPresent(source, destination, { merge: options.merge });
|
|
1535
|
+
}
|
|
1536
|
+
else if (entry.isFile()) {
|
|
1537
|
+
const destinationInfo = await assetPathInfo(destination);
|
|
1538
|
+
if (!options.merge && destinationInfo && (!destinationInfo.isFile() || destinationInfo.isSymbolicLink())) {
|
|
1539
|
+
await rm(destination, { recursive: destinationInfo.isDirectory(), force: true });
|
|
1540
|
+
}
|
|
1541
|
+
await copyFileIfPresent(source, destination);
|
|
1542
|
+
}
|
|
1543
|
+
else {
|
|
1544
|
+
throw new Error(`[file-viewer:vite-plugin] Asset source is not a regular file: ${source}.`);
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1466
1547
|
return true;
|
|
1467
1548
|
}
|
|
1468
1549
|
async function copyVersionedCadRuntimeDirectoryIfPresent(from, to, runtimeVersion) {
|
|
@@ -1472,12 +1553,12 @@ async function copyVersionedCadRuntimeDirectoryIfPresent(from, to, runtimeVersio
|
|
|
1472
1553
|
if (!runtimeVersion || !/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/.test(runtimeVersion)) {
|
|
1473
1554
|
throw new Error(`[file-viewer:vite-plugin] Cannot publish CAD runtime assets with invalid version ${JSON.stringify(runtimeVersion)}.`);
|
|
1474
1555
|
}
|
|
1475
|
-
const copied = await copyDirectoryIfPresent(from, to);
|
|
1556
|
+
const copied = await copyDirectoryIfPresent(from, to, { exclude: [runtimeVersion] });
|
|
1476
1557
|
if (!copied) {
|
|
1477
1558
|
return false;
|
|
1478
1559
|
}
|
|
1479
1560
|
const versionedTarget = join(to, runtimeVersion);
|
|
1480
|
-
return copyDirectoryIfPresent(from, versionedTarget);
|
|
1561
|
+
return copyDirectoryIfPresent(from, versionedTarget, { exclude: ['LICENSE', 'NOTICE'] });
|
|
1481
1562
|
}
|
|
1482
1563
|
async function copyPdfCjkFontAssets(from, to) {
|
|
1483
1564
|
if (!from) {
|
|
@@ -1489,11 +1570,15 @@ async function copyPdfCjkFontAssets(from, to) {
|
|
|
1489
1570
|
if (![files, stylesheet, license].every(existsSync) || !statSync(files).isDirectory()) {
|
|
1490
1571
|
return false;
|
|
1491
1572
|
}
|
|
1492
|
-
await
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1573
|
+
await ensureAssetCopyDirectory(to, true);
|
|
1574
|
+
const retained = new Set(['files', 'noto-sans-sc.css', 'OFL-1.1.txt']);
|
|
1575
|
+
for (const name of await readdir(to)) {
|
|
1576
|
+
if (!retained.has(name))
|
|
1577
|
+
await rm(join(to, name), { recursive: true, force: true });
|
|
1578
|
+
}
|
|
1579
|
+
await copyDirectoryIfPresent(files, join(to, 'files'));
|
|
1580
|
+
await copyFileIfPresent(stylesheet, join(to, 'noto-sans-sc.css'));
|
|
1581
|
+
await copyFileIfPresent(license, join(to, 'OFL-1.1.txt'));
|
|
1497
1582
|
return true;
|
|
1498
1583
|
}
|
|
1499
1584
|
function hasPdfCjkFontAssets(root, stylesheet, license) {
|
|
@@ -1749,13 +1834,7 @@ async function copyKnownRendererAssets(targetRoot, rendererIds) {
|
|
|
1749
1834
|
await push('indesign-idml-design', 'indesign-idml-license', join(targetRoot, 'vendor/design/LICENSE.introspect-wasm-MPL-2.0.txt'), () => copyFileIfPresent(designRendererRoot ? join(designRendererRoot, 'LICENSES/MPL-2.0.txt') : null, join(targetRoot, 'vendor/design/LICENSE.introspect-wasm-MPL-2.0.txt')));
|
|
1750
1835
|
await push('data-asset', 'data-sql-wasm', join(targetRoot, 'wasm/data/sql-wasm.wasm'), () => copyFileIfPresent(sqlJsRoot ? join(sqlJsRoot, 'dist/sql-wasm.wasm') : null, join(targetRoot, 'wasm/data/sql-wasm.wasm')));
|
|
1751
1836
|
await mkdir(targetRoot, { recursive: true });
|
|
1752
|
-
await
|
|
1753
|
-
schemaVersion: 1,
|
|
1754
|
-
generatedBy: '@file-viewer/vite-plugin',
|
|
1755
|
-
rendererIds,
|
|
1756
|
-
copiedAt: new Date().toISOString(),
|
|
1757
|
-
assets: results
|
|
1758
|
-
}, null, 2)}\n`);
|
|
1837
|
+
await writeAssetJsonIfChanged(join(targetRoot, 'flyfish-viewer-assets.json'), { schemaVersion: 1, generatedBy: '@file-viewer/vite-plugin', rendererIds, assets: results });
|
|
1759
1838
|
return results;
|
|
1760
1839
|
}
|
|
1761
1840
|
const independentlyOwnedAssetRendererIds = new Map([
|
|
@@ -1899,17 +1978,17 @@ async function copyInstalledCapabilityAssetPacks(targetRoot, rendererIds, instal
|
|
|
1899
1978
|
const manifests = [...rendererOwners]
|
|
1900
1979
|
.sort(([left], [right]) => left.localeCompare(right))
|
|
1901
1980
|
.map(([, value]) => value.manifest);
|
|
1902
|
-
await
|
|
1981
|
+
await writeAssetJsonIfChanged(join(targetRoot, 'flyfish-viewer-assets.json'), {
|
|
1903
1982
|
schemaVersion: 1,
|
|
1904
1983
|
generatedBy: '@file-viewer/vite-plugin',
|
|
1905
1984
|
rendererAssetManifests: manifests
|
|
1906
|
-
}
|
|
1907
|
-
await
|
|
1985
|
+
});
|
|
1986
|
+
await writeAssetJsonIfChanged(join(targetRoot, 'flyfish-viewer-manifest.json'), {
|
|
1908
1987
|
schemaVersion: 1,
|
|
1909
1988
|
kind: 'file-viewer-capability-assets',
|
|
1910
1989
|
owners: sources.map(source => ({ packageName: source.packageName, packageVersion: source.packageVersion }))
|
|
1911
1990
|
.sort((left, right) => left.packageName.localeCompare(right.packageName))
|
|
1912
|
-
}
|
|
1991
|
+
});
|
|
1913
1992
|
return { results, rendererIds: [...rendererOwners.keys()].sort() };
|
|
1914
1993
|
}
|
|
1915
1994
|
function matchesBundledAssetKind(kind, info) {
|
|
@@ -2040,7 +2119,10 @@ async function copyBundledFullRendererAssets(targetRoot, rendererIds, installedF
|
|
|
2040
2119
|
}
|
|
2041
2120
|
}
|
|
2042
2121
|
await mkdir(targetRoot, { recursive: true });
|
|
2043
|
-
await
|
|
2122
|
+
await copyDirectoryIfPresent(source.payloadRoot, targetRoot, {
|
|
2123
|
+
merge: true,
|
|
2124
|
+
exclude: ['flyfish-viewer-assets.json']
|
|
2125
|
+
});
|
|
2044
2126
|
const results = [];
|
|
2045
2127
|
for (const asset of manifest.rendererAssetManifests.flatMap((rendererManifest) => rendererManifest.assets)) {
|
|
2046
2128
|
if (asset.target !== 'public' || !asset.defaultPath) {
|
|
@@ -2079,13 +2161,7 @@ async function copyBundledFullRendererAssets(targetRoot, rendererIds, installedF
|
|
|
2079
2161
|
sourceVersion: owner?.packageVersion || source.sourceVersion
|
|
2080
2162
|
});
|
|
2081
2163
|
}
|
|
2082
|
-
await
|
|
2083
|
-
...manifest,
|
|
2084
|
-
generatedBy: '@file-viewer/vite-plugin',
|
|
2085
|
-
copiedAt: new Date().toISOString(),
|
|
2086
|
-
rendererIds,
|
|
2087
|
-
assets: results
|
|
2088
|
-
}, null, 2)}\n`);
|
|
2164
|
+
await writeAssetJsonIfChanged(join(targetRoot, 'flyfish-viewer-assets.json'), { ...manifest, generatedBy: '@file-viewer/vite-plugin', rendererIds, assets: results });
|
|
2089
2165
|
return results;
|
|
2090
2166
|
}
|
|
2091
2167
|
async function copyRendererAssets(target, rendererIds) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@file-viewer/vite-plugin",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Vite plugin for File Viewer on-demand renderer assembly, chunk planning, and offline asset deployment.",
|
|
@@ -52,7 +52,8 @@
|
|
|
52
52
|
"dist/index.js",
|
|
53
53
|
"LICENSE",
|
|
54
54
|
"README.en.md",
|
|
55
|
-
"README.md"
|
|
55
|
+
"README.md",
|
|
56
|
+
"README.zh-CN.md"
|
|
56
57
|
],
|
|
57
58
|
"peerDependencies": {
|
|
58
59
|
"vite": ">=5 <9"
|