index.js 5.5 KB

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