ce10161ea329667d7ac8ee8abed52a3d9b58e9cafc3252868bc79a00d3fb99069ca1d685063b7b27ee75daf19fd39dc211476b49097040e89f8439e56612bf 6.0 KB

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