@file-viewer/vite-plugin 2.3.2 → 2.4.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.
Files changed (2) hide show
  1. package/dist/index.js +87 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -786,6 +786,25 @@ function hasManualChunks(config) {
786
786
  }
787
787
  return Boolean(output?.manualChunks);
788
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
+ }
789
808
  function getManualChunksFunction(config) {
790
809
  const output = config.build?.rollupOptions?.output;
791
810
  if (Array.isArray(output)) {
@@ -832,6 +851,68 @@ function getStableInteropChunkName(id) {
832
851
  function createStableInteropManualChunks(manualChunks) {
833
852
  return (id, meta) => getStableInteropChunkName(id) || manualChunks(id, meta);
834
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
+ }
835
916
  function createOptimizeDepsExclude(config) {
836
917
  return unique([
837
918
  ...(config.optimizeDeps?.exclude || []),
@@ -1837,6 +1918,12 @@ export function fileViewerRenderers(options = {}) {
1837
1918
  ]
1838
1919
  }
1839
1920
  };
1921
+ if (resolveProjectViteMajor(projectRoot) >= 8) {
1922
+ return {
1923
+ ...nextConfig,
1924
+ ...createVite8ChunkConfig(userConfig, selection, autoPresetIds, options)
1925
+ };
1926
+ }
1840
1927
  if (manualChunksFunction && options.stabilizeInteropChunks !== false) {
1841
1928
  return {
1842
1929
  ...nextConfig,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@file-viewer/vite-plugin",
3
- "version": "2.3.2",
3
+ "version": "2.4.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.",