index.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. export { parseAst, parseAstAsync } from 'rollup/parseAst';
  2. import { a as arraify, i as isInNodeModules, D as DevEnvironment } from './chunks/dep-DBxKXgDP.js';
  3. export { B as BuildEnvironment, 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-DBxKXgDP.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 'picomatch';
  15. import 'path';
  16. import 'fs';
  17. import 'fdir';
  18. import 'node:child_process';
  19. import 'node:http';
  20. import 'node:https';
  21. import 'tty';
  22. import 'util';
  23. import 'net';
  24. import 'events';
  25. import 'url';
  26. import 'http';
  27. import 'stream';
  28. import 'os';
  29. import 'child_process';
  30. import 'node:os';
  31. import 'node:net';
  32. import 'node:dns';
  33. import 'vite/module-runner';
  34. import 'node:buffer';
  35. import 'module';
  36. import 'node:readline';
  37. import 'node:process';
  38. import 'node:events';
  39. import 'tinyglobby';
  40. import 'crypto';
  41. import 'node:assert';
  42. import 'node:v8';
  43. import 'node:worker_threads';
  44. import 'https';
  45. import 'tls';
  46. import 'zlib';
  47. import 'buffer';
  48. import 'assert';
  49. import 'node:querystring';
  50. import 'node:zlib';
  51. const CSS_LANGS_RE = (
  52. // eslint-disable-next-line regexp/no-unused-capturing-group
  53. /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/
  54. );
  55. const isCSSRequest = (request) => CSS_LANGS_RE.test(request);
  56. class SplitVendorChunkCache {
  57. cache;
  58. constructor() {
  59. this.cache = /* @__PURE__ */ new Map();
  60. }
  61. reset() {
  62. this.cache = /* @__PURE__ */ new Map();
  63. }
  64. }
  65. function splitVendorChunk(options = {}) {
  66. const cache = options.cache ?? new SplitVendorChunkCache();
  67. return (id, { getModuleInfo }) => {
  68. if (isInNodeModules(id) && !isCSSRequest(id) && staticImportedByEntry(id, getModuleInfo, cache.cache)) {
  69. return "vendor";
  70. }
  71. };
  72. }
  73. function staticImportedByEntry(id, getModuleInfo, cache, importStack = []) {
  74. if (cache.has(id)) {
  75. return cache.get(id);
  76. }
  77. if (importStack.includes(id)) {
  78. cache.set(id, false);
  79. return false;
  80. }
  81. const mod = getModuleInfo(id);
  82. if (!mod) {
  83. cache.set(id, false);
  84. return false;
  85. }
  86. if (mod.isEntry) {
  87. cache.set(id, true);
  88. return true;
  89. }
  90. const someImporterIs = mod.importers.some(
  91. (importer) => staticImportedByEntry(
  92. importer,
  93. getModuleInfo,
  94. cache,
  95. importStack.concat(id)
  96. )
  97. );
  98. cache.set(id, someImporterIs);
  99. return someImporterIs;
  100. }
  101. function splitVendorChunkPlugin() {
  102. const caches = [];
  103. function createSplitVendorChunk(output, config) {
  104. const cache = new SplitVendorChunkCache();
  105. caches.push(cache);
  106. const build = config.build ?? {};
  107. const format = output.format;
  108. if (!build.ssr && !build.lib && format !== "umd" && format !== "iife") {
  109. return splitVendorChunk({ cache });
  110. }
  111. }
  112. return {
  113. name: "vite:split-vendor-chunk",
  114. config(config) {
  115. let outputs = config.build?.rollupOptions?.output;
  116. if (outputs) {
  117. outputs = arraify(outputs);
  118. for (const output of outputs) {
  119. const viteManualChunks = createSplitVendorChunk(output, config);
  120. if (viteManualChunks) {
  121. if (output.manualChunks) {
  122. if (typeof output.manualChunks === "function") {
  123. const userManualChunks = output.manualChunks;
  124. output.manualChunks = (id, api) => {
  125. return userManualChunks(id, api) ?? viteManualChunks(id, api);
  126. };
  127. } else {
  128. console.warn(
  129. "(!) the `splitVendorChunk` plugin doesn't have any effect when using the object form of `build.rollupOptions.output.manualChunks`. Consider using the function form instead."
  130. );
  131. }
  132. } else {
  133. output.manualChunks = viteManualChunks;
  134. }
  135. }
  136. }
  137. } else {
  138. return {
  139. build: {
  140. rollupOptions: {
  141. output: {
  142. manualChunks: createSplitVendorChunk({}, config)
  143. }
  144. }
  145. }
  146. };
  147. }
  148. },
  149. buildStart() {
  150. caches.forEach((cache) => cache.reset());
  151. }
  152. };
  153. }
  154. function createFetchableDevEnvironment(name, config, context) {
  155. if (typeof Request === "undefined" || typeof Response === "undefined") {
  156. throw new TypeError(
  157. "FetchableDevEnvironment requires a global `Request` and `Response` object."
  158. );
  159. }
  160. if (!context.handleRequest) {
  161. throw new TypeError(
  162. "FetchableDevEnvironment requires a `handleRequest` method during initialisation."
  163. );
  164. }
  165. return new FetchableDevEnvironment(name, config, context);
  166. }
  167. function isFetchableDevEnvironment(environment) {
  168. return environment instanceof FetchableDevEnvironment;
  169. }
  170. class FetchableDevEnvironment extends DevEnvironment {
  171. _handleRequest;
  172. constructor(name, config, context) {
  173. super(name, config, context);
  174. this._handleRequest = context.handleRequest;
  175. }
  176. async dispatchFetch(request) {
  177. if (!(request instanceof Request)) {
  178. throw new TypeError(
  179. "FetchableDevEnvironment `dispatchFetch` must receive a `Request` object."
  180. );
  181. }
  182. const response = await this._handleRequest(request);
  183. if (!(response instanceof Response)) {
  184. throw new TypeError(
  185. "FetchableDevEnvironment `context.handleRequest` must return a `Response` object."
  186. );
  187. }
  188. return response;
  189. }
  190. }
  191. export { DevEnvironment, createFetchableDevEnvironment, isCSSRequest, isFetchableDevEnvironment, splitVendorChunk, splitVendorChunkPlugin };