index.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var index = require('./chunks/dep-689425f3.js');
  4. require('fs');
  5. require('path');
  6. require('url');
  7. require('perf_hooks');
  8. require('tty');
  9. require('os');
  10. require('esbuild');
  11. require('events');
  12. require('assert');
  13. require('resolve');
  14. require('util');
  15. require('stream');
  16. require('net');
  17. require('http');
  18. require('child_process');
  19. require('module');
  20. require('crypto');
  21. require('buffer');
  22. require('querystring');
  23. require('zlib');
  24. require('https');
  25. require('tls');
  26. require('worker_threads');
  27. require('readline');
  28. // Use splitVendorChunkPlugin() to get the same manualChunks strategy as Vite 2.7
  29. // We don't recommend using this strategy as a general solution moving forward
  30. // splitVendorChunk is a simple index/vendor strategy that was used in Vite
  31. // until v2.8. It is exposed to let people continue to use it in case it was
  32. // working well for their setups.
  33. // The cache needs to be reset on buildStart for watch mode to work correctly
  34. // Don't use this manualChunks strategy for ssr, lib mode, and 'umd' or 'iife'
  35. class SplitVendorChunkCache {
  36. constructor() {
  37. this.cache = new Map();
  38. }
  39. reset() {
  40. this.cache = new Map();
  41. }
  42. }
  43. function splitVendorChunk(options = {}) {
  44. var _a;
  45. const cache = (_a = options.cache) !== null && _a !== void 0 ? _a : new SplitVendorChunkCache();
  46. return (id, { getModuleInfo }) => {
  47. if (id.includes('node_modules') &&
  48. !index.isCSSRequest(id) &&
  49. staticImportedByEntry(id, getModuleInfo, cache.cache)) {
  50. return 'vendor';
  51. }
  52. };
  53. }
  54. function staticImportedByEntry(id, getModuleInfo, cache, importStack = []) {
  55. if (cache.has(id)) {
  56. return cache.get(id);
  57. }
  58. if (importStack.includes(id)) {
  59. // circular deps!
  60. cache.set(id, false);
  61. return false;
  62. }
  63. const mod = getModuleInfo(id);
  64. if (!mod) {
  65. cache.set(id, false);
  66. return false;
  67. }
  68. if (mod.isEntry) {
  69. cache.set(id, true);
  70. return true;
  71. }
  72. const someImporterIs = mod.importers.some((importer) => staticImportedByEntry(importer, getModuleInfo, cache, importStack.concat(id)));
  73. cache.set(id, someImporterIs);
  74. return someImporterIs;
  75. }
  76. function splitVendorChunkPlugin() {
  77. const caches = [];
  78. function createSplitVendorChunk(output, config) {
  79. var _a;
  80. const cache = new SplitVendorChunkCache();
  81. caches.push(cache);
  82. const build = (_a = config.build) !== null && _a !== void 0 ? _a : {};
  83. const format = output === null || output === void 0 ? void 0 : output.format;
  84. if (!build.ssr && !build.lib && format !== 'umd' && format !== 'iife') {
  85. return splitVendorChunk({ cache });
  86. }
  87. }
  88. return {
  89. name: 'vite:split-vendor-chunk',
  90. config(config) {
  91. var _a, _b;
  92. let outputs = (_b = (_a = config === null || config === void 0 ? void 0 : config.build) === null || _a === void 0 ? void 0 : _a.rollupOptions) === null || _b === void 0 ? void 0 : _b.output;
  93. if (outputs) {
  94. outputs = Array.isArray(outputs) ? outputs : [outputs];
  95. for (const output of outputs) {
  96. const viteManualChunks = createSplitVendorChunk(output, config);
  97. if (viteManualChunks) {
  98. if (output.manualChunks) {
  99. if (typeof output.manualChunks === 'function') {
  100. const userManualChunks = output.manualChunks;
  101. output.manualChunks = (id, api) => {
  102. var _a;
  103. return (_a = userManualChunks(id, api)) !== null && _a !== void 0 ? _a : viteManualChunks(id, api);
  104. };
  105. }
  106. // else, leave the object form of manualChunks untouched, as
  107. // we can't safely replicate rollup handling.
  108. }
  109. else {
  110. output.manualChunks = viteManualChunks;
  111. }
  112. }
  113. }
  114. }
  115. else {
  116. return {
  117. build: {
  118. rollupOptions: {
  119. output: {
  120. manualChunks: createSplitVendorChunk({}, config)
  121. }
  122. }
  123. }
  124. };
  125. }
  126. },
  127. buildStart() {
  128. caches.forEach((cache) => cache.reset());
  129. }
  130. };
  131. }
  132. exports.build = index.build;
  133. exports.createLogger = index.createLogger;
  134. exports.createServer = index.createServer;
  135. exports.defineConfig = index.defineConfig;
  136. exports.formatPostcssSourceMap = index.formatPostcssSourceMap;
  137. exports.loadConfigFromFile = index.loadConfigFromFile;
  138. exports.loadEnv = index.loadEnv;
  139. exports.mergeConfig = index.mergeConfig;
  140. exports.normalizePath = index.normalizePath;
  141. exports.optimizeDeps = index.optimizeDeps;
  142. exports.preview = index.preview;
  143. exports.printHttpServerUrls = index.printHttpServerUrls;
  144. exports.resolveConfig = index.resolveConfig;
  145. exports.resolveEnvPrefix = index.resolveEnvPrefix;
  146. exports.resolvePackageData = index.resolvePackageData;
  147. exports.resolvePackageEntry = index.resolvePackageEntry;
  148. exports.searchForWorkspaceRoot = index.searchForWorkspaceRoot;
  149. exports.send = index.send;
  150. exports.sortUserPlugins = index.sortUserPlugins;
  151. exports.transformWithEsbuild = index.transformWithEsbuild;
  152. exports.splitVendorChunk = splitVendorChunk;
  153. exports.splitVendorChunkPlugin = splitVendorChunkPlugin;