UNPKG

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