@file-viewer/vite-plugin 2.1.14 → 2.1.16
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/dist/index.js +186 -6
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -384,6 +384,28 @@ const presetModules = {
|
|
|
384
384
|
chunkName: 'file-viewer-preset-engineering'
|
|
385
385
|
}
|
|
386
386
|
};
|
|
387
|
+
// Vite dep optimization rewrites import.meta.url into node_modules/.vite/deps
|
|
388
|
+
// and can trigger full-preset dev-server re-optimization reloads. Keep File
|
|
389
|
+
// Viewer packages out of dep optimization while still optimizing their
|
|
390
|
+
// CommonJS/UMD helper dependencies below.
|
|
391
|
+
const fileViewerOptimizationExcludedPackages = [
|
|
392
|
+
'@file-viewer/core',
|
|
393
|
+
'@file-viewer/pptx',
|
|
394
|
+
...rendererModules.map((descriptor) => descriptor.packageName),
|
|
395
|
+
...Object.values(presetModules).map((preset) => preset.packageName),
|
|
396
|
+
'@file-viewer/react-full',
|
|
397
|
+
'@file-viewer/react-legacy-full',
|
|
398
|
+
'@file-viewer/vue3-full',
|
|
399
|
+
'@file-viewer/vue2.7-full',
|
|
400
|
+
'@file-viewer/vue2.6-full',
|
|
401
|
+
'@file-viewer/web-full',
|
|
402
|
+
'@file-viewer/jquery-full',
|
|
403
|
+
'@file-viewer/svelte-full'
|
|
404
|
+
];
|
|
405
|
+
const cjsInteropPackages = [
|
|
406
|
+
'@file-viewer/docx',
|
|
407
|
+
'jszip'
|
|
408
|
+
];
|
|
387
409
|
const defaultScanRoots = ['src', 'app', 'pages', 'components'];
|
|
388
410
|
const defaultScanExtensions = [
|
|
389
411
|
'js',
|
|
@@ -669,6 +691,19 @@ function hasManualChunks(config) {
|
|
|
669
691
|
}
|
|
670
692
|
return Boolean(output?.manualChunks);
|
|
671
693
|
}
|
|
694
|
+
function createOptimizeDepsExclude(config) {
|
|
695
|
+
return unique([
|
|
696
|
+
...(config.optimizeDeps?.exclude || []),
|
|
697
|
+
...fileViewerOptimizationExcludedPackages
|
|
698
|
+
]);
|
|
699
|
+
}
|
|
700
|
+
function createOptimizeDepsInclude(config, exclude, anchorPackages) {
|
|
701
|
+
const excluded = new Set(exclude);
|
|
702
|
+
return unique([
|
|
703
|
+
...(config.optimizeDeps?.include || []),
|
|
704
|
+
...cjsInteropPackages.filter((packageName) => !excluded.has(packageName) && Boolean(resolvePackageJson(packageName, anchorPackages)))
|
|
705
|
+
]);
|
|
706
|
+
}
|
|
672
707
|
function createManualChunks(selection, autoPresetIds = []) {
|
|
673
708
|
const packageToChunk = new Map();
|
|
674
709
|
const presetIds = unique([
|
|
@@ -761,10 +796,14 @@ function collectWorkspacePackageJsons(root) {
|
|
|
761
796
|
return packageJsons;
|
|
762
797
|
}
|
|
763
798
|
function resolveWorkspacePackageJson(packageName) {
|
|
764
|
-
|
|
765
|
-
|
|
799
|
+
const root = process.cwd();
|
|
800
|
+
if (!workspacePackageJsonCache || workspacePackageJsonCache.root !== root) {
|
|
801
|
+
workspacePackageJsonCache = {
|
|
802
|
+
root,
|
|
803
|
+
packages: collectWorkspacePackageJsons(root)
|
|
804
|
+
};
|
|
766
805
|
}
|
|
767
|
-
return workspacePackageJsonCache.get(packageName) || null;
|
|
806
|
+
return workspacePackageJsonCache.packages.get(packageName) || null;
|
|
768
807
|
}
|
|
769
808
|
function resolvePackageJson(packageName, anchorPackages = []) {
|
|
770
809
|
const requireFns = [projectRequire(), pluginRequire];
|
|
@@ -778,7 +817,8 @@ function resolvePackageJson(packageName, anchorPackages = []) {
|
|
|
778
817
|
discoveredAnchor = false;
|
|
779
818
|
for (const anchorPackage of effectiveAnchorPackages) {
|
|
780
819
|
for (const requireFn of [...requireFns]) {
|
|
781
|
-
const anchorPackageJson = tryResolvePackageJson(anchorPackage, requireFn)
|
|
820
|
+
const anchorPackageJson = tryResolvePackageJson(anchorPackage, requireFn) ||
|
|
821
|
+
resolveWorkspacePackageJson(anchorPackage);
|
|
782
822
|
if (anchorPackageJson && !anchorPackageJsons.has(anchorPackageJson)) {
|
|
783
823
|
anchorPackageJsons.add(anchorPackageJson);
|
|
784
824
|
requireFns.push(createRequire(anchorPackageJson));
|
|
@@ -828,10 +868,122 @@ function collectSelectedPackages(selection, autoPresetIds = []) {
|
|
|
828
868
|
...selection.descriptors.map((descriptor) => descriptor.packageName)
|
|
829
869
|
]);
|
|
830
870
|
}
|
|
871
|
+
function collectDependencyAnchorPackages(selection, autoPresetIds = []) {
|
|
872
|
+
const presetIds = unique([
|
|
873
|
+
...(selection.preset ? [selection.preset] : []),
|
|
874
|
+
...autoPresetIds
|
|
875
|
+
]);
|
|
876
|
+
return unique([
|
|
877
|
+
...collectSelectedPackages(selection, autoPresetIds),
|
|
878
|
+
...presetIds.flatMap((presetId) => presetModules[presetId].rendererIds
|
|
879
|
+
.map((rendererId) => descriptorsById.get(rendererId)?.packageName)
|
|
880
|
+
.filter((packageName) => Boolean(packageName))),
|
|
881
|
+
...selection.descriptors.map((descriptor) => descriptor.packageName)
|
|
882
|
+
]);
|
|
883
|
+
}
|
|
831
884
|
function resolvePackageRoot(packageName, anchorPackages = []) {
|
|
832
885
|
const packageJson = resolvePackageJson(packageName, anchorPackages);
|
|
833
886
|
return packageJson ? dirname(packageJson) : null;
|
|
834
887
|
}
|
|
888
|
+
function resolvePackageEntry(packageName, anchorPackages = []) {
|
|
889
|
+
const packageJsonPath = resolvePackageJson(packageName, anchorPackages);
|
|
890
|
+
if (!packageJsonPath) {
|
|
891
|
+
return null;
|
|
892
|
+
}
|
|
893
|
+
const packageRoot = dirname(packageJsonPath);
|
|
894
|
+
try {
|
|
895
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
|
|
896
|
+
const candidates = unique([
|
|
897
|
+
packageJson.module,
|
|
898
|
+
packageJson.main,
|
|
899
|
+
'index.js'
|
|
900
|
+
].filter((value) => Boolean(value)));
|
|
901
|
+
for (const candidate of candidates) {
|
|
902
|
+
const entry = resolve(packageRoot, candidate);
|
|
903
|
+
if (existsSync(entry) && statSync(entry).isFile()) {
|
|
904
|
+
return entry;
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
catch {
|
|
909
|
+
// Fall back to Node resolution below.
|
|
910
|
+
}
|
|
911
|
+
const anchorPackageJson = anchorPackages
|
|
912
|
+
.map((anchorPackage) => resolvePackageJson(anchorPackage))
|
|
913
|
+
.find(Boolean);
|
|
914
|
+
const requireFns = [
|
|
915
|
+
projectRequire(),
|
|
916
|
+
pluginRequire,
|
|
917
|
+
...(anchorPackageJson ? [createRequire(anchorPackageJson)] : [])
|
|
918
|
+
];
|
|
919
|
+
for (const requireFn of requireFns) {
|
|
920
|
+
try {
|
|
921
|
+
return requireFn.resolve(packageName);
|
|
922
|
+
}
|
|
923
|
+
catch {
|
|
924
|
+
// Continue probing alternate anchors.
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
return null;
|
|
928
|
+
}
|
|
929
|
+
function readPackageExportEntry(value) {
|
|
930
|
+
if (typeof value === 'string') {
|
|
931
|
+
return value;
|
|
932
|
+
}
|
|
933
|
+
if (!value || typeof value !== 'object') {
|
|
934
|
+
return null;
|
|
935
|
+
}
|
|
936
|
+
const record = value;
|
|
937
|
+
return readPackageExportEntry(record.import) ||
|
|
938
|
+
readPackageExportEntry(record.default) ||
|
|
939
|
+
readPackageExportEntry(record.require);
|
|
940
|
+
}
|
|
941
|
+
function resolvePackageExportEntry(packageName, exportPath, anchorPackages = []) {
|
|
942
|
+
const packageJsonPath = resolvePackageJson(packageName, anchorPackages);
|
|
943
|
+
if (!packageJsonPath) {
|
|
944
|
+
return null;
|
|
945
|
+
}
|
|
946
|
+
try {
|
|
947
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
|
|
948
|
+
const exportEntry = readPackageExportEntry(packageJson.exports?.[exportPath]);
|
|
949
|
+
if (!exportEntry) {
|
|
950
|
+
return null;
|
|
951
|
+
}
|
|
952
|
+
const entry = resolve(dirname(packageJsonPath), exportEntry);
|
|
953
|
+
return existsSync(entry) && statSync(entry).isFile() ? entry : null;
|
|
954
|
+
}
|
|
955
|
+
catch {
|
|
956
|
+
return null;
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
function normalizeViteAlias(alias) {
|
|
960
|
+
if (!alias) {
|
|
961
|
+
return [];
|
|
962
|
+
}
|
|
963
|
+
if (Array.isArray(alias)) {
|
|
964
|
+
return [...alias];
|
|
965
|
+
}
|
|
966
|
+
return Object.entries(alias).map(([find, replacement]) => ({ find, replacement }));
|
|
967
|
+
}
|
|
968
|
+
function createFileViewerResolveAliases(anchorPackages) {
|
|
969
|
+
const packageNames = unique([
|
|
970
|
+
'@file-viewer/core',
|
|
971
|
+
...anchorPackages,
|
|
972
|
+
...cjsInteropPackages
|
|
973
|
+
]);
|
|
974
|
+
const aliases = [];
|
|
975
|
+
const coreAssetsEntry = resolvePackageExportEntry('@file-viewer/core', './assets', anchorPackages);
|
|
976
|
+
if (coreAssetsEntry) {
|
|
977
|
+
aliases.push({ find: '@file-viewer/core/assets', replacement: coreAssetsEntry });
|
|
978
|
+
}
|
|
979
|
+
aliases.push(...packageNames
|
|
980
|
+
.map((packageName) => {
|
|
981
|
+
const entry = resolvePackageEntry(packageName, anchorPackages);
|
|
982
|
+
return entry ? { find: packageName, replacement: entry } : null;
|
|
983
|
+
})
|
|
984
|
+
.filter((alias) => Boolean(alias)));
|
|
985
|
+
return aliases;
|
|
986
|
+
}
|
|
835
987
|
async function copyFileIfPresent(from, to) {
|
|
836
988
|
if (!from || !existsSync(from)) {
|
|
837
989
|
return false;
|
|
@@ -878,6 +1030,11 @@ async function copyKnownRendererAssets(targetRoot, rendererIds) {
|
|
|
878
1030
|
await push('pdf', 'pdf-cmaps', join(targetRoot, 'vendor/pdf/cmaps'), () => copyDirectoryIfPresent(pdfRoot ? join(pdfRoot, 'cmaps') : null, join(targetRoot, 'vendor/pdf/cmaps')));
|
|
879
1031
|
await push('pdf', 'pdf-wasm', join(targetRoot, 'vendor/pdf/wasm'), () => copyDirectoryIfPresent(pdfRoot ? join(pdfRoot, 'wasm') : null, join(targetRoot, 'vendor/pdf/wasm')));
|
|
880
1032
|
await push('pdf', 'pdf-standard-fonts', join(targetRoot, 'vendor/pdf/standard_fonts'), () => copyDirectoryIfPresent(pdfRoot ? join(pdfRoot, 'standard_fonts') : null, join(targetRoot, 'vendor/pdf/standard_fonts')));
|
|
1033
|
+
const pptxRoot = resolvePackageRoot('@file-viewer/pptx', ['@file-viewer/renderer-presentation']);
|
|
1034
|
+
await push('office-presentation', 'pptx-worker', join(targetRoot, 'vendor/pptx/pptx.worker.js'), () => copyFileIfPresent(pptxRoot ? join(pptxRoot, 'dist/worker/pptx.worker.js') : null, join(targetRoot, 'vendor/pptx/pptx.worker.js')));
|
|
1035
|
+
const docxRoot = resolvePackageRoot('@file-viewer/docx', ['@file-viewer/renderer-word']);
|
|
1036
|
+
await push('office-word-openxml', 'docx-worker', join(targetRoot, 'vendor/docx/docx.worker.js'), () => copyFileIfPresent(docxRoot ? join(docxRoot, 'dist/docx-preview.worker.js') : null, join(targetRoot, 'vendor/docx/docx.worker.js')));
|
|
1037
|
+
await push('office-word-openxml', 'docx-worker-jszip', join(targetRoot, 'vendor/docx/jszip.min.js'), () => copyFileIfPresent(docxRoot ? join(docxRoot, 'dist/jszip.min.js') : null, join(targetRoot, 'vendor/docx/jszip.min.js')));
|
|
881
1038
|
const cadRoot = resolvePackageRoot('@flyfish-dev/cad-viewer', ['@file-viewer/renderer-cad']);
|
|
882
1039
|
await push('cad', 'cad-wasm-directory', join(targetRoot, 'wasm/cad'), () => copyDirectoryIfPresent(cadRoot ? join(cadRoot, 'dist/wasm') : null, join(targetRoot, 'wasm/cad')));
|
|
883
1040
|
const typstCompilerRoot = resolvePackageRoot('@myriaddreamin/typst-ts-web-compiler', [
|
|
@@ -925,7 +1082,14 @@ function collectAssetRendererIds(selection, autoPresetIds = []) {
|
|
|
925
1082
|
]);
|
|
926
1083
|
}
|
|
927
1084
|
function reportAssetCopy(results, targetRoot, mode) {
|
|
928
|
-
const failedRequired = results.filter((result) => !result.copied && [
|
|
1085
|
+
const failedRequired = results.filter((result) => !result.copied && [
|
|
1086
|
+
'pdf',
|
|
1087
|
+
'office-word-openxml',
|
|
1088
|
+
'office-presentation',
|
|
1089
|
+
'archive',
|
|
1090
|
+
'cad',
|
|
1091
|
+
'typst'
|
|
1092
|
+
].includes(result.rendererId));
|
|
929
1093
|
if (!results.length) {
|
|
930
1094
|
return;
|
|
931
1095
|
}
|
|
@@ -977,10 +1141,26 @@ export function fileViewerRenderers(options = {}) {
|
|
|
977
1141
|
config(userConfig) {
|
|
978
1142
|
const projectRoot = resolve(process.cwd(), userConfig.root || '.');
|
|
979
1143
|
refreshSelection(projectRoot);
|
|
1144
|
+
const selectedPackages = collectSelectedPackages(selection, autoPresetIds);
|
|
1145
|
+
const dependencyAnchorPackages = collectDependencyAnchorPackages(selection, autoPresetIds);
|
|
1146
|
+
const optimizeDepsExclude = createOptimizeDepsExclude(userConfig);
|
|
1147
|
+
const nextConfig = {
|
|
1148
|
+
optimizeDeps: {
|
|
1149
|
+
exclude: optimizeDepsExclude,
|
|
1150
|
+
include: createOptimizeDepsInclude(userConfig, optimizeDepsExclude, dependencyAnchorPackages)
|
|
1151
|
+
},
|
|
1152
|
+
resolve: {
|
|
1153
|
+
alias: [
|
|
1154
|
+
...normalizeViteAlias(userConfig.resolve?.alias),
|
|
1155
|
+
...createFileViewerResolveAliases(dependencyAnchorPackages)
|
|
1156
|
+
]
|
|
1157
|
+
}
|
|
1158
|
+
};
|
|
980
1159
|
if ((options.chunkStrategy || 'renderer') === 'none' || hasManualChunks(userConfig)) {
|
|
981
|
-
return
|
|
1160
|
+
return nextConfig;
|
|
982
1161
|
}
|
|
983
1162
|
return {
|
|
1163
|
+
...nextConfig,
|
|
984
1164
|
build: {
|
|
985
1165
|
rollupOptions: {
|
|
986
1166
|
output: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@file-viewer/vite-plugin",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.16",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Vite plugin for Flyfish File Viewer on-demand renderer assembly, chunk planning, and offline asset deployment.",
|
|
@@ -24,12 +24,12 @@
|
|
|
24
24
|
},
|
|
25
25
|
"repository": {
|
|
26
26
|
"type": "git",
|
|
27
|
-
"url": "git+https://github.com/flyfish-dev/file-viewer
|
|
27
|
+
"url": "git+https://github.com/flyfish-dev/file-viewer.git",
|
|
28
28
|
"directory": "packages/presets/vite-plugin"
|
|
29
29
|
},
|
|
30
30
|
"homepage": "https://doc.file-viewer.app/guide/on-demand-renderers",
|
|
31
31
|
"bugs": {
|
|
32
|
-
"url": "https://github.com/flyfish-dev/file-viewer
|
|
32
|
+
"url": "https://github.com/flyfish-dev/file-viewer/issues"
|
|
33
33
|
},
|
|
34
34
|
"funding": {
|
|
35
35
|
"type": "individual",
|