index.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. export { b as build, q as createFilter, v as createLogger, c as createServer, e as defineConfig, f as formatPostcssSourceMap, i as getDepOptimizationConfig, j as isDepsOptimizerEnabled, l as loadConfigFromFile, x as loadEnv, k as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, a as preprocessCSS, p as preview, h as resolveBaseUrl, g as resolveConfig, y as resolveEnvPrefix, d as resolvePackageData, r as resolvePackageEntry, w as searchForWorkspaceRoot, u as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-f11f7337.js';
  2. export { VERSION as version } from './constants.js';
  3. export { version as esbuildVersion } from 'esbuild';
  4. export { VERSION as rollupVersion } from 'rollup';
  5. import 'node:fs';
  6. import 'node:path';
  7. import 'node:url';
  8. import 'node:perf_hooks';
  9. import 'node:module';
  10. import 'tty';
  11. import 'path';
  12. import 'fs';
  13. import 'events';
  14. import 'assert';
  15. import 'util';
  16. import 'net';
  17. import 'url';
  18. import 'http';
  19. import 'stream';
  20. import 'os';
  21. import 'child_process';
  22. import 'node:os';
  23. import 'node:crypto';
  24. import 'node:util';
  25. import 'node:dns';
  26. import 'resolve';
  27. import 'crypto';
  28. import 'node:buffer';
  29. import 'module';
  30. import 'worker_threads';
  31. import 'zlib';
  32. import 'https';
  33. import 'tls';
  34. import 'node:http';
  35. import 'node:https';
  36. import 'querystring';
  37. import 'node:readline';
  38. import 'node:child_process';
  39. import 'node:zlib';
  40. // This file will be built for both ESM and CJS. Avoid relying on other modules as possible.
  41. const cssLangs = `\\.(css|less|sass|scss|styl|stylus|pcss|postcss)($|\\?)`;
  42. const cssLangRE = new RegExp(cssLangs);
  43. const isCSSRequest = (request) => cssLangRE.test(request);
  44. // Use splitVendorChunkPlugin() to get the same manualChunks strategy as Vite 2.7
  45. // We don't recommend using this strategy as a general solution moving forward
  46. // splitVendorChunk is a simple index/vendor strategy that was used in Vite
  47. // until v2.8. It is exposed to let people continue to use it in case it was
  48. // working well for their setups.
  49. // The cache needs to be reset on buildStart for watch mode to work correctly
  50. // Don't use this manualChunks strategy for ssr, lib mode, and 'umd' or 'iife'
  51. class SplitVendorChunkCache {
  52. constructor() {
  53. this.cache = new Map();
  54. }
  55. reset() {
  56. this.cache = new Map();
  57. }
  58. }
  59. function splitVendorChunk(options = {}) {
  60. const cache = options.cache ?? new SplitVendorChunkCache();
  61. return (id, { getModuleInfo }) => {
  62. if (id.includes('node_modules') &&
  63. !isCSSRequest(id) &&
  64. staticImportedByEntry(id, getModuleInfo, cache.cache)) {
  65. return 'vendor';
  66. }
  67. };
  68. }
  69. function staticImportedByEntry(id, getModuleInfo, cache, importStack = []) {
  70. if (cache.has(id)) {
  71. return cache.get(id);
  72. }
  73. if (importStack.includes(id)) {
  74. // circular deps!
  75. cache.set(id, false);
  76. return false;
  77. }
  78. const mod = getModuleInfo(id);
  79. if (!mod) {
  80. cache.set(id, false);
  81. return false;
  82. }
  83. if (mod.isEntry) {
  84. cache.set(id, true);
  85. return true;
  86. }
  87. const someImporterIs = mod.importers.some((importer) => staticImportedByEntry(importer, getModuleInfo, cache, importStack.concat(id)));
  88. cache.set(id, someImporterIs);
  89. return someImporterIs;
  90. }
  91. function splitVendorChunkPlugin() {
  92. const caches = [];
  93. function createSplitVendorChunk(output, config) {
  94. const cache = new SplitVendorChunkCache();
  95. caches.push(cache);
  96. const build = config.build ?? {};
  97. const format = output?.format;
  98. if (!build.ssr && !build.lib && format !== 'umd' && format !== 'iife') {
  99. return splitVendorChunk({ cache });
  100. }
  101. }
  102. return {
  103. name: 'vite:split-vendor-chunk',
  104. config(config) {
  105. let outputs = config?.build?.rollupOptions?.output;
  106. if (outputs) {
  107. outputs = Array.isArray(outputs) ? outputs : [outputs];
  108. for (const output of outputs) {
  109. const viteManualChunks = createSplitVendorChunk(output, config);
  110. if (viteManualChunks) {
  111. if (output.manualChunks) {
  112. if (typeof output.manualChunks === 'function') {
  113. const userManualChunks = output.manualChunks;
  114. output.manualChunks = (id, api) => {
  115. return userManualChunks(id, api) ?? viteManualChunks(id, api);
  116. };
  117. }
  118. // else, leave the object form of manualChunks untouched, as
  119. // we can't safely replicate rollup handling.
  120. }
  121. else {
  122. output.manualChunks = viteManualChunks;
  123. }
  124. }
  125. }
  126. }
  127. else {
  128. return {
  129. build: {
  130. rollupOptions: {
  131. output: {
  132. manualChunks: createSplitVendorChunk({}, config)
  133. }
  134. }
  135. }
  136. };
  137. }
  138. },
  139. buildStart() {
  140. caches.forEach((cache) => cache.reset());
  141. }
  142. };
  143. }
  144. export { splitVendorChunk, splitVendorChunkPlugin };