1 | export { parseAst, parseAstAsync } from 'rollup/parseAst';
|
---|
2 | import { i as isInNodeModules, a as arraify } from './chunks/dep-mCdpKltl.js';
|
---|
3 | export { b as build, g as buildErrorMessage, k as createFilter, v as createLogger, c as createServer, d as defineConfig, h as fetchModule, f as formatPostcssSourceMap, x as isFileServingAllowed, l as loadConfigFromFile, y as loadEnv, j as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, e as preprocessCSS, p as preview, r as resolveConfig, z as resolveEnvPrefix, q as rollupVersion, w as searchForWorkspaceRoot, u as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-mCdpKltl.js';
|
---|
4 | export { VERSION as version } from './constants.js';
|
---|
5 | export { version as esbuildVersion } from 'esbuild';
|
---|
6 | import { existsSync, readFileSync } from 'node:fs';
|
---|
7 | import { ViteRuntime, ESModulesRunner } from 'vite/runtime';
|
---|
8 | import 'node:fs/promises';
|
---|
9 | import 'node:path';
|
---|
10 | import 'node:url';
|
---|
11 | import 'node:util';
|
---|
12 | import 'node:perf_hooks';
|
---|
13 | import 'node:module';
|
---|
14 | import 'tty';
|
---|
15 | import 'path';
|
---|
16 | import 'fs';
|
---|
17 | import 'node:events';
|
---|
18 | import 'node:stream';
|
---|
19 | import 'node:string_decoder';
|
---|
20 | import 'node:child_process';
|
---|
21 | import 'node:http';
|
---|
22 | import 'node:https';
|
---|
23 | import 'util';
|
---|
24 | import 'net';
|
---|
25 | import 'events';
|
---|
26 | import 'url';
|
---|
27 | import 'http';
|
---|
28 | import 'stream';
|
---|
29 | import 'os';
|
---|
30 | import 'child_process';
|
---|
31 | import 'node:os';
|
---|
32 | import 'node:crypto';
|
---|
33 | import 'node:dns';
|
---|
34 | import 'crypto';
|
---|
35 | import 'module';
|
---|
36 | import 'node:assert';
|
---|
37 | import 'node:v8';
|
---|
38 | import 'node:worker_threads';
|
---|
39 | import 'node:buffer';
|
---|
40 | import 'querystring';
|
---|
41 | import 'node:readline';
|
---|
42 | import 'zlib';
|
---|
43 | import 'buffer';
|
---|
44 | import 'https';
|
---|
45 | import 'tls';
|
---|
46 | import 'assert';
|
---|
47 | import 'node:zlib';
|
---|
48 |
|
---|
49 | const CSS_LANGS_RE = (
|
---|
50 | // eslint-disable-next-line regexp/no-unused-capturing-group
|
---|
51 | /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/
|
---|
52 | );
|
---|
53 | const isCSSRequest = (request) => CSS_LANGS_RE.test(request);
|
---|
54 | class SplitVendorChunkCache {
|
---|
55 | cache;
|
---|
56 | constructor() {
|
---|
57 | this.cache = /* @__PURE__ */ new Map();
|
---|
58 | }
|
---|
59 | reset() {
|
---|
60 | this.cache = /* @__PURE__ */ new Map();
|
---|
61 | }
|
---|
62 | }
|
---|
63 | function splitVendorChunk(options = {}) {
|
---|
64 | const cache = options.cache ?? new SplitVendorChunkCache();
|
---|
65 | return (id, { getModuleInfo }) => {
|
---|
66 | if (isInNodeModules(id) && !isCSSRequest(id) && staticImportedByEntry(id, getModuleInfo, cache.cache)) {
|
---|
67 | return "vendor";
|
---|
68 | }
|
---|
69 | };
|
---|
70 | }
|
---|
71 | function staticImportedByEntry(id, getModuleInfo, cache, importStack = []) {
|
---|
72 | if (cache.has(id)) {
|
---|
73 | return cache.get(id);
|
---|
74 | }
|
---|
75 | if (importStack.includes(id)) {
|
---|
76 | cache.set(id, false);
|
---|
77 | return false;
|
---|
78 | }
|
---|
79 | const mod = getModuleInfo(id);
|
---|
80 | if (!mod) {
|
---|
81 | cache.set(id, false);
|
---|
82 | return false;
|
---|
83 | }
|
---|
84 | if (mod.isEntry) {
|
---|
85 | cache.set(id, true);
|
---|
86 | return true;
|
---|
87 | }
|
---|
88 | const someImporterIs = mod.importers.some(
|
---|
89 | (importer) => staticImportedByEntry(
|
---|
90 | importer,
|
---|
91 | getModuleInfo,
|
---|
92 | cache,
|
---|
93 | importStack.concat(id)
|
---|
94 | )
|
---|
95 | );
|
---|
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 = arraify(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 | } else {
|
---|
126 | console.warn(
|
---|
127 | "(!) the `splitVendorChunk` plugin doesn't have any effect when using the object form of `build.rollupOptions.output.manualChunks`. Consider using the function form instead."
|
---|
128 | );
|
---|
129 | }
|
---|
130 | } else {
|
---|
131 | output.manualChunks = viteManualChunks;
|
---|
132 | }
|
---|
133 | }
|
---|
134 | }
|
---|
135 | } else {
|
---|
136 | return {
|
---|
137 | build: {
|
---|
138 | rollupOptions: {
|
---|
139 | output: {
|
---|
140 | manualChunks: createSplitVendorChunk({}, config)
|
---|
141 | }
|
---|
142 | }
|
---|
143 | }
|
---|
144 | };
|
---|
145 | }
|
---|
146 | },
|
---|
147 | buildStart() {
|
---|
148 | caches.forEach((cache) => cache.reset());
|
---|
149 | }
|
---|
150 | };
|
---|
151 | }
|
---|
152 |
|
---|
153 | class ServerHMRBroadcasterClient {
|
---|
154 | constructor(hmrChannel) {
|
---|
155 | this.hmrChannel = hmrChannel;
|
---|
156 | }
|
---|
157 | send(...args) {
|
---|
158 | let payload;
|
---|
159 | if (typeof args[0] === "string") {
|
---|
160 | payload = {
|
---|
161 | type: "custom",
|
---|
162 | event: args[0],
|
---|
163 | data: args[1]
|
---|
164 | };
|
---|
165 | } else {
|
---|
166 | payload = args[0];
|
---|
167 | }
|
---|
168 | if (payload.type !== "custom") {
|
---|
169 | throw new Error(
|
---|
170 | "Cannot send non-custom events from the client to the server."
|
---|
171 | );
|
---|
172 | }
|
---|
173 | this.hmrChannel.send(payload);
|
---|
174 | }
|
---|
175 | }
|
---|
176 | class ServerHMRConnector {
|
---|
177 | handlers = [];
|
---|
178 | hmrChannel;
|
---|
179 | hmrClient;
|
---|
180 | connected = false;
|
---|
181 | constructor(server) {
|
---|
182 | const hmrChannel = server.hot?.channels.find(
|
---|
183 | (c) => c.name === "ssr"
|
---|
184 | );
|
---|
185 | if (!hmrChannel) {
|
---|
186 | throw new Error(
|
---|
187 | "Your version of Vite doesn't support HMR during SSR. Please, use Vite 5.1 or higher."
|
---|
188 | );
|
---|
189 | }
|
---|
190 | this.hmrClient = new ServerHMRBroadcasterClient(hmrChannel);
|
---|
191 | hmrChannel.api.outsideEmitter.on("send", (payload) => {
|
---|
192 | this.handlers.forEach((listener) => listener(payload));
|
---|
193 | });
|
---|
194 | this.hmrChannel = hmrChannel;
|
---|
195 | }
|
---|
196 | isReady() {
|
---|
197 | return this.connected;
|
---|
198 | }
|
---|
199 | send(message) {
|
---|
200 | const payload = JSON.parse(message);
|
---|
201 | this.hmrChannel.api.innerEmitter.emit(
|
---|
202 | payload.event,
|
---|
203 | payload.data,
|
---|
204 | this.hmrClient
|
---|
205 | );
|
---|
206 | }
|
---|
207 | onUpdate(handler) {
|
---|
208 | this.handlers.push(handler);
|
---|
209 | handler({ type: "connected" });
|
---|
210 | this.connected = true;
|
---|
211 | }
|
---|
212 | }
|
---|
213 |
|
---|
214 | function createHMROptions(server, options) {
|
---|
215 | if (server.config.server.hmr === false || options.hmr === false) {
|
---|
216 | return false;
|
---|
217 | }
|
---|
218 | const connection = new ServerHMRConnector(server);
|
---|
219 | return {
|
---|
220 | connection,
|
---|
221 | logger: options.hmr?.logger
|
---|
222 | };
|
---|
223 | }
|
---|
224 | const prepareStackTrace = {
|
---|
225 | retrieveFile(id) {
|
---|
226 | if (existsSync(id)) {
|
---|
227 | return readFileSync(id, "utf-8");
|
---|
228 | }
|
---|
229 | }
|
---|
230 | };
|
---|
231 | function resolveSourceMapOptions(options) {
|
---|
232 | if (options.sourcemapInterceptor != null) {
|
---|
233 | if (options.sourcemapInterceptor === "prepareStackTrace") {
|
---|
234 | return prepareStackTrace;
|
---|
235 | }
|
---|
236 | if (typeof options.sourcemapInterceptor === "object") {
|
---|
237 | return { ...prepareStackTrace, ...options.sourcemapInterceptor };
|
---|
238 | }
|
---|
239 | return options.sourcemapInterceptor;
|
---|
240 | }
|
---|
241 | if (typeof process !== "undefined" && "setSourceMapsEnabled" in process) {
|
---|
242 | return "node";
|
---|
243 | }
|
---|
244 | return prepareStackTrace;
|
---|
245 | }
|
---|
246 | async function createViteRuntime(server, options = {}) {
|
---|
247 | const hmr = createHMROptions(server, options);
|
---|
248 | return new ViteRuntime(
|
---|
249 | {
|
---|
250 | ...options,
|
---|
251 | root: server.config.root,
|
---|
252 | fetchModule: server.ssrFetchModule,
|
---|
253 | hmr,
|
---|
254 | sourcemapInterceptor: resolveSourceMapOptions(options)
|
---|
255 | },
|
---|
256 | options.runner || new ESModulesRunner()
|
---|
257 | );
|
---|
258 | }
|
---|
259 |
|
---|
260 | export { ServerHMRConnector, createViteRuntime, isCSSRequest, splitVendorChunk, splitVendorChunkPlugin };
|
---|