@file-viewer/vite-plugin 2.3.1 → 2.3.3
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 +133 -19
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -53,20 +53,26 @@ const rendererModules = [
|
|
|
53
53
|
id: 'presentation',
|
|
54
54
|
packageName: '@file-viewer/renderer-presentation',
|
|
55
55
|
exportName: 'presentationRenderer',
|
|
56
|
-
formats: [
|
|
57
|
-
'presentation',
|
|
58
|
-
'ppt',
|
|
59
|
-
'pptx',
|
|
60
|
-
'pptm',
|
|
61
|
-
'pot',
|
|
62
|
-
'potx',
|
|
63
|
-
'potm',
|
|
64
|
-
'ppsx',
|
|
65
|
-
'ppsm'
|
|
66
|
-
],
|
|
56
|
+
formats: ['presentation'],
|
|
67
57
|
rendererIds: ['office-presentation-binary', 'office-presentation'],
|
|
68
58
|
chunkName: 'file-viewer-presentation'
|
|
69
59
|
},
|
|
60
|
+
{
|
|
61
|
+
id: 'presentation-binary',
|
|
62
|
+
packageName: '@file-viewer/renderer-presentation/ppt',
|
|
63
|
+
exportName: 'pptRenderer',
|
|
64
|
+
formats: ['ppt', 'pot'],
|
|
65
|
+
rendererIds: ['office-presentation-binary'],
|
|
66
|
+
chunkName: 'file-viewer-presentation-ppt'
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
id: 'presentation-openxml',
|
|
70
|
+
packageName: '@file-viewer/renderer-presentation/pptx',
|
|
71
|
+
exportName: 'pptxRenderer',
|
|
72
|
+
formats: ['pptx', 'pptm', 'potx', 'potm', 'ppsx', 'ppsm'],
|
|
73
|
+
rendererIds: ['office-presentation'],
|
|
74
|
+
chunkName: 'file-viewer-presentation-pptx'
|
|
75
|
+
},
|
|
70
76
|
{
|
|
71
77
|
id: 'word',
|
|
72
78
|
packageName: '@file-viewer/renderer-word',
|
|
@@ -780,6 +786,25 @@ function hasManualChunks(config) {
|
|
|
780
786
|
}
|
|
781
787
|
return Boolean(output?.manualChunks);
|
|
782
788
|
}
|
|
789
|
+
function resolveProjectViteMajor(projectRoot) {
|
|
790
|
+
const requireFns = [
|
|
791
|
+
createRequire(resolve(projectRoot, 'package.json')),
|
|
792
|
+
pluginRequire
|
|
793
|
+
];
|
|
794
|
+
for (const requireFn of requireFns) {
|
|
795
|
+
try {
|
|
796
|
+
const packageJsonPath = requireFn.resolve('vite/package.json');
|
|
797
|
+
const version = String(JSON.parse(readFileSync(packageJsonPath, 'utf8')).version || '');
|
|
798
|
+
const major = Number.parseInt(version.split('.')[0] || '', 10);
|
|
799
|
+
if (Number.isInteger(major) && major > 0)
|
|
800
|
+
return major;
|
|
801
|
+
}
|
|
802
|
+
catch {
|
|
803
|
+
// Try the plugin's own Vite installation when the project does not expose one.
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
return 7;
|
|
807
|
+
}
|
|
783
808
|
function getManualChunksFunction(config) {
|
|
784
809
|
const output = config.build?.rollupOptions?.output;
|
|
785
810
|
if (Array.isArray(output)) {
|
|
@@ -826,6 +851,68 @@ function getStableInteropChunkName(id) {
|
|
|
826
851
|
function createStableInteropManualChunks(manualChunks) {
|
|
827
852
|
return (id, meta) => getStableInteropChunkName(id) || manualChunks(id, meta);
|
|
828
853
|
}
|
|
854
|
+
function createRolldownCodeSplittingGroups(selection, autoPresetIds, options) {
|
|
855
|
+
const groups = [];
|
|
856
|
+
if (options.stabilizeInteropChunks !== false) {
|
|
857
|
+
groups.push({
|
|
858
|
+
name: 'vendor-codemirror',
|
|
859
|
+
test: (id) => getStableInteropChunkName(id) === 'vendor-codemirror',
|
|
860
|
+
priority: -10
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
if ((options.chunkStrategy || 'renderer') !== 'none') {
|
|
864
|
+
const resolveChunkName = createManualChunks(selection, autoPresetIds);
|
|
865
|
+
groups.push({
|
|
866
|
+
name: (id) => resolveChunkName(id) || null,
|
|
867
|
+
priority: -20
|
|
868
|
+
});
|
|
869
|
+
}
|
|
870
|
+
return groups;
|
|
871
|
+
}
|
|
872
|
+
function mergeRolldownCodeSplittingOutput(output, pluginGroups) {
|
|
873
|
+
const current = output || {};
|
|
874
|
+
if (current.codeSplitting === false || !pluginGroups.length)
|
|
875
|
+
return current;
|
|
876
|
+
const codeSplitting = current.codeSplitting && typeof current.codeSplitting === 'object'
|
|
877
|
+
? current.codeSplitting
|
|
878
|
+
: {};
|
|
879
|
+
const existingGroups = Array.isArray(codeSplitting.groups) ? codeSplitting.groups : [];
|
|
880
|
+
const existingNames = new Set(existingGroups
|
|
881
|
+
.map(group => typeof group.name === 'string' ? group.name : null)
|
|
882
|
+
.filter((name) => Boolean(name)));
|
|
883
|
+
const groups = [
|
|
884
|
+
...existingGroups,
|
|
885
|
+
...pluginGroups.filter(group => typeof group.name !== 'string' || !existingNames.has(group.name))
|
|
886
|
+
];
|
|
887
|
+
return {
|
|
888
|
+
...current,
|
|
889
|
+
codeSplitting: {
|
|
890
|
+
...codeSplitting,
|
|
891
|
+
groups
|
|
892
|
+
}
|
|
893
|
+
};
|
|
894
|
+
}
|
|
895
|
+
function createVite8ChunkConfig(userConfig, selection, autoPresetIds, options) {
|
|
896
|
+
const build = userConfig.build;
|
|
897
|
+
const rolldownOptions = build?.rolldownOptions || {};
|
|
898
|
+
const groups = createRolldownCodeSplittingGroups(selection, autoPresetIds, options);
|
|
899
|
+
const currentOutput = rolldownOptions.output;
|
|
900
|
+
if (!groups.length ||
|
|
901
|
+
(!Array.isArray(currentOutput) && currentOutput?.codeSplitting === false)) {
|
|
902
|
+
return {};
|
|
903
|
+
}
|
|
904
|
+
const output = Array.isArray(currentOutput)
|
|
905
|
+
? currentOutput.map(item => mergeRolldownCodeSplittingOutput(item, groups))
|
|
906
|
+
: mergeRolldownCodeSplittingOutput(currentOutput, groups);
|
|
907
|
+
return {
|
|
908
|
+
build: {
|
|
909
|
+
rolldownOptions: {
|
|
910
|
+
...rolldownOptions,
|
|
911
|
+
output
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
};
|
|
915
|
+
}
|
|
829
916
|
function createOptimizeDepsExclude(config) {
|
|
830
917
|
return unique([
|
|
831
918
|
...(config.optimizeDeps?.exclude || []),
|
|
@@ -1070,8 +1157,37 @@ function resolvePackageEntry(packageName, anchorPackages = []) {
|
|
|
1070
1157
|
return null;
|
|
1071
1158
|
}
|
|
1072
1159
|
const packageRoot = dirname(packageJsonPath);
|
|
1160
|
+
const anchorPackageJson = anchorPackages
|
|
1161
|
+
.map((anchorPackage) => resolvePackageJson(anchorPackage))
|
|
1162
|
+
.find(Boolean);
|
|
1163
|
+
const requireFns = [
|
|
1164
|
+
projectRequire(),
|
|
1165
|
+
pluginRequire,
|
|
1166
|
+
...(anchorPackageJson ? [createRequire(anchorPackageJson)] : [])
|
|
1167
|
+
];
|
|
1073
1168
|
try {
|
|
1074
1169
|
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
|
|
1170
|
+
const exportSubpath = packageJson.name && packageName.startsWith(`${packageJson.name}/`)
|
|
1171
|
+
? `.${packageName.slice(packageJson.name.length)}`
|
|
1172
|
+
: null;
|
|
1173
|
+
if (exportSubpath) {
|
|
1174
|
+
const exportedEntry = readPackageExportEntry(packageJson.exports?.[exportSubpath]);
|
|
1175
|
+
if (exportedEntry) {
|
|
1176
|
+
const entry = resolve(packageRoot, exportedEntry);
|
|
1177
|
+
if (existsSync(entry) && statSync(entry).isFile()) {
|
|
1178
|
+
return entry;
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
for (const requireFn of requireFns) {
|
|
1182
|
+
try {
|
|
1183
|
+
return requireFn.resolve(packageName);
|
|
1184
|
+
}
|
|
1185
|
+
catch {
|
|
1186
|
+
// Continue probing alternate anchors.
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
return null;
|
|
1190
|
+
}
|
|
1075
1191
|
const candidates = unique([
|
|
1076
1192
|
packageJson.module,
|
|
1077
1193
|
packageJson.main,
|
|
@@ -1087,14 +1203,6 @@ function resolvePackageEntry(packageName, anchorPackages = []) {
|
|
|
1087
1203
|
catch {
|
|
1088
1204
|
// Fall back to Node resolution below.
|
|
1089
1205
|
}
|
|
1090
|
-
const anchorPackageJson = anchorPackages
|
|
1091
|
-
.map((anchorPackage) => resolvePackageJson(anchorPackage))
|
|
1092
|
-
.find(Boolean);
|
|
1093
|
-
const requireFns = [
|
|
1094
|
-
projectRequire(),
|
|
1095
|
-
pluginRequire,
|
|
1096
|
-
...(anchorPackageJson ? [createRequire(anchorPackageJson)] : [])
|
|
1097
|
-
];
|
|
1098
1206
|
for (const requireFn of requireFns) {
|
|
1099
1207
|
try {
|
|
1100
1208
|
return requireFn.resolve(packageName);
|
|
@@ -1810,6 +1918,12 @@ export function fileViewerRenderers(options = {}) {
|
|
|
1810
1918
|
]
|
|
1811
1919
|
}
|
|
1812
1920
|
};
|
|
1921
|
+
if (resolveProjectViteMajor(projectRoot) >= 8) {
|
|
1922
|
+
return {
|
|
1923
|
+
...nextConfig,
|
|
1924
|
+
...createVite8ChunkConfig(userConfig, selection, autoPresetIds, options)
|
|
1925
|
+
};
|
|
1926
|
+
}
|
|
1813
1927
|
if (manualChunksFunction && options.stabilizeInteropChunks !== false) {
|
|
1814
1928
|
return {
|
|
1815
1929
|
...nextConfig,
|
package/package.json
CHANGED