You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
5.2 KiB

  1. export { parseAst, parseAstAsync } from 'rollup/parseAst';
  2. import { a as arraify, i as isInNodeModules } from './chunks/dep-Bid9ssRr.js';
  3. export { B as BuildEnvironment, D as DevEnvironment, f as build, m as buildErrorMessage, g as createBuilder, F as createFilter, h as createIdResolver, I as createLogger, n as createRunnableDevEnvironment, c as createServer, y as createServerHotChannel, w as createServerModuleRunner, x as createServerModuleRunnerTransport, d as defineConfig, v as fetchModule, j as formatPostcssSourceMap, L as isFileLoadingAllowed, K as isFileServingAllowed, q as isRunnableDevEnvironment, l as loadConfigFromFile, M as loadEnv, E as mergeAlias, C as mergeConfig, z as moduleRunnerTransform, A as normalizePath, o as optimizeDeps, p as perEnvironmentPlugin, b as perEnvironmentState, k as preprocessCSS, e as preview, r as resolveConfig, N as resolveEnvPrefix, G as rollupVersion, u as runnerImport, J as searchForWorkspaceRoot, H as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-Bid9ssRr.js';
  4. export { defaultAllowedOrigins, DEFAULT_CLIENT_CONDITIONS as defaultClientConditions, DEFAULT_CLIENT_MAIN_FIELDS as defaultClientMainFields, DEFAULT_SERVER_CONDITIONS as defaultServerConditions, DEFAULT_SERVER_MAIN_FIELDS as defaultServerMainFields, VERSION as version } from './constants.js';
  5. export { version as esbuildVersion } from 'esbuild';
  6. import 'node:fs';
  7. import 'node:path';
  8. import 'node:fs/promises';
  9. import 'node:url';
  10. import 'node:util';
  11. import 'node:perf_hooks';
  12. import 'node:module';
  13. import 'node:crypto';
  14. import 'path';
  15. import 'fs';
  16. import 'node:child_process';
  17. import 'node:http';
  18. import 'node:https';
  19. import 'tty';
  20. import 'util';
  21. import 'net';
  22. import 'events';
  23. import 'url';
  24. import 'http';
  25. import 'stream';
  26. import 'os';
  27. import 'child_process';
  28. import 'node:os';
  29. import 'node:net';
  30. import 'node:dns';
  31. import 'vite/module-runner';
  32. import 'node:buffer';
  33. import 'module';
  34. import 'node:readline';
  35. import 'node:process';
  36. import 'node:events';
  37. import 'crypto';
  38. import 'node:assert';
  39. import 'node:v8';
  40. import 'node:worker_threads';
  41. import 'https';
  42. import 'tls';
  43. import 'zlib';
  44. import 'buffer';
  45. import 'assert';
  46. import 'node:querystring';
  47. import 'node:zlib';
  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. );
  52. const isCSSRequest = (request) => CSS_LANGS_RE.test(request);
  53. class SplitVendorChunkCache {
  54. cache;
  55. constructor() {
  56. this.cache = /* @__PURE__ */ new Map();
  57. }
  58. reset() {
  59. this.cache = /* @__PURE__ */ new Map();
  60. }
  61. }
  62. function splitVendorChunk(options = {}) {
  63. const cache = options.cache ?? new SplitVendorChunkCache();
  64. return (id, { getModuleInfo }) => {
  65. if (isInNodeModules(id) && !isCSSRequest(id) && staticImportedByEntry(id, getModuleInfo, cache.cache)) {
  66. return "vendor";
  67. }
  68. };
  69. }
  70. function staticImportedByEntry(id, getModuleInfo, cache, importStack = []) {
  71. if (cache.has(id)) {
  72. return cache.get(id);
  73. }
  74. if (importStack.includes(id)) {
  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(
  88. (importer) => staticImportedByEntry(
  89. importer,
  90. getModuleInfo,
  91. cache,
  92. importStack.concat(id)
  93. )
  94. );
  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 = arraify(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. } else {
  125. console.warn(
  126. "(!) the `splitVendorChunk` plugin doesn't have any effect when using the object form of `build.rollupOptions.output.manualChunks`. Consider using the function form instead."
  127. );
  128. }
  129. } else {
  130. output.manualChunks = viteManualChunks;
  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 };