vite 3.0.0-beta.9 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/client.mjs +23 -3
- package/dist/client/client.mjs.map +1 -1
- package/dist/node/chunks/{dep-58325dc2.js → dep-1513d487.js} +334 -239
- package/dist/node/chunks/{dep-235df460.js → dep-3f457808.js} +1 -1
- package/dist/node/chunks/{dep-21ac9d2b.js → dep-f07a4e2f.js} +1 -1
- package/dist/node/cli.js +5 -5
- package/dist/node/constants.js +1 -1
- package/dist/node/index.d.ts +24 -5
- package/dist/node/index.js +1 -1
- package/dist/node-cjs/publicUtils.cjs +1 -1
- package/package.json +6 -6
- package/src/client/client.ts +22 -3
- package/src/client/overlay.ts +4 -0
|
@@ -22,7 +22,7 @@ import { createHash as createHash$2 } from 'node:crypto';
|
|
|
22
22
|
import { promisify as promisify$4 } from 'node:util';
|
|
23
23
|
import { promises } from 'node:dns';
|
|
24
24
|
import resolve$5 from 'resolve';
|
|
25
|
-
import { CLIENT_ENTRY, DEFAULT_EXTENSIONS as DEFAULT_EXTENSIONS$1, OPTIMIZABLE_ENTRY_RE, VALID_ID_PREFIX, FS_PREFIX, wildcardHosts, CLIENT_PUBLIC_PATH, ENV_PUBLIC_PATH,
|
|
25
|
+
import { CLIENT_ENTRY, DEFAULT_EXTENSIONS as DEFAULT_EXTENSIONS$1, OPTIMIZABLE_ENTRY_RE, VALID_ID_PREFIX, FS_PREFIX, wildcardHosts, loopbackHosts, CLIENT_PUBLIC_PATH, ENV_PUBLIC_PATH, DEFAULT_MAIN_FIELDS, DEP_VERSION_RE, SPECIAL_QUERY_RE, KNOWN_ASSET_TYPES, JS_TYPES_RE, ESBUILD_MODULES_TARGET, CLIENT_DIR, NULL_BYTE_PLACEHOLDER, VERSION, VITE_PACKAGE_DIR, ENV_ENTRY, DEFAULT_ASSETS_RE, DEFAULT_CONFIG_FILES } from '../constants.js';
|
|
26
26
|
import require$$5 from 'crypto';
|
|
27
27
|
import require$$0$a from 'buffer';
|
|
28
28
|
import require$$0$8, { createRequire as createRequire$2 } from 'module';
|
|
@@ -12172,7 +12172,49 @@ async function resolveHostname(optionsHost) {
|
|
|
12172
12172
|
name = localhostAddr;
|
|
12173
12173
|
}
|
|
12174
12174
|
}
|
|
12175
|
-
return { host, name
|
|
12175
|
+
return { host, name };
|
|
12176
|
+
}
|
|
12177
|
+
async function resolveServerUrls(server, options, config) {
|
|
12178
|
+
const address = server.address();
|
|
12179
|
+
const isAddressInfo = (x) => x?.address;
|
|
12180
|
+
if (!isAddressInfo(address)) {
|
|
12181
|
+
return { local: [], network: [] };
|
|
12182
|
+
}
|
|
12183
|
+
const local = [];
|
|
12184
|
+
const network = [];
|
|
12185
|
+
const hostname = await resolveHostname(options.host);
|
|
12186
|
+
const protocol = options.https ? 'https' : 'http';
|
|
12187
|
+
const port = address.port;
|
|
12188
|
+
const base = config.base === './' || config.base === '' ? '/' : config.base;
|
|
12189
|
+
if (hostname.host && loopbackHosts.has(hostname.host)) {
|
|
12190
|
+
let hostnameName = hostname.name;
|
|
12191
|
+
if (hostnameName === '::1' ||
|
|
12192
|
+
hostnameName === '0000:0000:0000:0000:0000:0000:0000:0001') {
|
|
12193
|
+
hostnameName = `[${hostnameName}]`;
|
|
12194
|
+
}
|
|
12195
|
+
local.push(`${protocol}://${hostnameName}:${port}${base}`);
|
|
12196
|
+
}
|
|
12197
|
+
else {
|
|
12198
|
+
Object.values(os$3.networkInterfaces())
|
|
12199
|
+
.flatMap((nInterface) => nInterface ?? [])
|
|
12200
|
+
.filter((detail) => detail &&
|
|
12201
|
+
detail.address &&
|
|
12202
|
+
// Node < v18
|
|
12203
|
+
((typeof detail.family === 'string' && detail.family === 'IPv4') ||
|
|
12204
|
+
// Node >= v18
|
|
12205
|
+
(typeof detail.family === 'number' && detail.family === 4)))
|
|
12206
|
+
.forEach((detail) => {
|
|
12207
|
+
const host = detail.address.replace('127.0.0.1', hostname.name);
|
|
12208
|
+
const url = `${protocol}://${host}:${port}${base}`;
|
|
12209
|
+
if (detail.address.includes('127.0.0.1')) {
|
|
12210
|
+
local.push(url);
|
|
12211
|
+
}
|
|
12212
|
+
else {
|
|
12213
|
+
network.push(url);
|
|
12214
|
+
}
|
|
12215
|
+
});
|
|
12216
|
+
}
|
|
12217
|
+
return { local, network };
|
|
12176
12218
|
}
|
|
12177
12219
|
function arraify(target) {
|
|
12178
12220
|
return Array.isArray(target) ? target : [target];
|
|
@@ -12381,7 +12423,6 @@ function stripBomTag(content) {
|
|
|
12381
12423
|
}
|
|
12382
12424
|
return content;
|
|
12383
12425
|
}
|
|
12384
|
-
const isTS = (filename) => /\.[cm]?ts$/.test(filename);
|
|
12385
12426
|
const windowsDrivePathPrefixRE = /^[A-Za-z]:[/\\]/;
|
|
12386
12427
|
/**
|
|
12387
12428
|
* path.isAbsolute also returns true for drive relative paths on windows (e.g. /something)
|
|
@@ -12491,64 +12532,18 @@ function createLogger(level = 'info', options = {}) {
|
|
|
12491
12532
|
};
|
|
12492
12533
|
return logger;
|
|
12493
12534
|
}
|
|
12494
|
-
|
|
12495
|
-
const
|
|
12496
|
-
const
|
|
12497
|
-
|
|
12498
|
-
const hostname = await resolveHostname(options.host);
|
|
12499
|
-
const protocol = options.https ? 'https' : 'http';
|
|
12500
|
-
const base = config.base === './' || config.base === '' ? '/' : config.base;
|
|
12501
|
-
printServerUrls(hostname, protocol, address.port, base, config.logger.info);
|
|
12535
|
+
function printServerUrls(urls, optionsHost, info) {
|
|
12536
|
+
const colorUrl = (url) => picocolors.exports.cyan(url.replace(/:(\d+)\//, (_, port) => `:${picocolors.exports.bold(port)}/`));
|
|
12537
|
+
for (const url of urls.local) {
|
|
12538
|
+
info(` ${picocolors.exports.green('➜')} ${picocolors.exports.bold('Local')}: ${colorUrl(url)}`);
|
|
12502
12539
|
}
|
|
12503
|
-
|
|
12504
|
-
|
|
12505
|
-
const urls = [];
|
|
12506
|
-
const notes = [];
|
|
12507
|
-
if (hostname.host && loopbackHosts.has(hostname.host)) {
|
|
12508
|
-
let hostnameName = hostname.name;
|
|
12509
|
-
if (hostnameName === '::1' ||
|
|
12510
|
-
hostnameName === '0000:0000:0000:0000:0000:0000:0000:0001') {
|
|
12511
|
-
hostnameName = `[${hostnameName}]`;
|
|
12512
|
-
}
|
|
12513
|
-
urls.push({
|
|
12514
|
-
label: 'Local',
|
|
12515
|
-
url: picocolors.exports.cyan(`${protocol}://${hostnameName}:${picocolors.exports.bold(port)}${base}`)
|
|
12516
|
-
});
|
|
12517
|
-
if (hostname.implicit) {
|
|
12518
|
-
urls.push({
|
|
12519
|
-
label: 'Network',
|
|
12520
|
-
url: `use ${picocolors.exports.white(picocolors.exports.bold('--host'))} to expose`,
|
|
12521
|
-
disabled: true
|
|
12522
|
-
});
|
|
12523
|
-
}
|
|
12540
|
+
for (const url of urls.network) {
|
|
12541
|
+
info(` ${picocolors.exports.green('➜')} ${picocolors.exports.bold('Network')}: ${colorUrl(url)}`);
|
|
12524
12542
|
}
|
|
12525
|
-
|
|
12526
|
-
|
|
12527
|
-
|
|
12528
|
-
.filter((detail) => detail &&
|
|
12529
|
-
detail.address &&
|
|
12530
|
-
// Node < v18
|
|
12531
|
-
((typeof detail.family === 'string' && detail.family === 'IPv4') ||
|
|
12532
|
-
// Node >= v18
|
|
12533
|
-
(typeof detail.family === 'number' && detail.family === 4)))
|
|
12534
|
-
.forEach((detail) => {
|
|
12535
|
-
const host = detail.address.replace('127.0.0.1', hostname.name);
|
|
12536
|
-
const url = `${protocol}://${host}:${picocolors.exports.bold(port)}${base}`;
|
|
12537
|
-
const label = detail.address.includes('127.0.0.1') ? 'Local' : 'Network';
|
|
12538
|
-
urls.push({ label, url: picocolors.exports.cyan(url) });
|
|
12539
|
-
});
|
|
12543
|
+
if (urls.network.length === 0 && optionsHost === undefined) {
|
|
12544
|
+
const note = `use ${picocolors.exports.white(picocolors.exports.bold('--host'))} to expose`;
|
|
12545
|
+
info(picocolors.exports.dim(` ${picocolors.exports.green('➜')} ${picocolors.exports.bold('Network')}: ${note}`));
|
|
12540
12546
|
}
|
|
12541
|
-
const length = Math.max(...[...urls, ...notes].map(({ label }) => label.length));
|
|
12542
|
-
const print = (iconWithColor, label, messageWithColor, disabled) => {
|
|
12543
|
-
const message = ` ${iconWithColor} ${label ? picocolors.exports.bold(label) + ':' : ' '} ${' '.repeat(length - label.length)}${messageWithColor}`;
|
|
12544
|
-
info(disabled ? picocolors.exports.dim(message) : message);
|
|
12545
|
-
};
|
|
12546
|
-
urls.forEach(({ label, url: text, disabled }) => {
|
|
12547
|
-
print(picocolors.exports.green('➜'), label, text, disabled);
|
|
12548
|
-
});
|
|
12549
|
-
notes.forEach(({ label, message: text }) => {
|
|
12550
|
-
print(picocolors.exports.white('❖'), label, text);
|
|
12551
|
-
});
|
|
12552
12547
|
}
|
|
12553
12548
|
|
|
12554
12549
|
const writeColors = {
|
|
@@ -13343,7 +13338,11 @@ function esbuildPlugin(options = {}) {
|
|
|
13343
13338
|
minifyIdentifiers: false,
|
|
13344
13339
|
minifySyntax: false,
|
|
13345
13340
|
minifyWhitespace: false,
|
|
13346
|
-
treeShaking: false
|
|
13341
|
+
treeShaking: false,
|
|
13342
|
+
// keepNames is not needed when minify is disabled.
|
|
13343
|
+
// Also transforming multiple times with keepNames enabled breaks
|
|
13344
|
+
// tree-shaking. (#9164)
|
|
13345
|
+
keepNames: false
|
|
13347
13346
|
};
|
|
13348
13347
|
return {
|
|
13349
13348
|
name: 'vite:esbuild',
|
|
@@ -13438,10 +13437,19 @@ function resolveEsbuildTranspileOptions(config, format) {
|
|
|
13438
13437
|
// pure annotations and break tree-shaking
|
|
13439
13438
|
// https://github.com/vuejs/core/issues/2860#issuecomment-926882793
|
|
13440
13439
|
const isEsLibBuild = config.build.lib && format === 'es';
|
|
13440
|
+
const esbuildOptions = config.esbuild || {};
|
|
13441
13441
|
const options = {
|
|
13442
|
-
...
|
|
13442
|
+
...esbuildOptions,
|
|
13443
13443
|
target: target || undefined,
|
|
13444
|
-
format: rollupToEsbuildFormatMap[format]
|
|
13444
|
+
format: rollupToEsbuildFormatMap[format],
|
|
13445
|
+
// the final build should always support dynamic import and import.meta.
|
|
13446
|
+
// if they need to be polyfilled, plugin-legacy should be used.
|
|
13447
|
+
// plugin-legacy detects these two features when checking for modern code.
|
|
13448
|
+
supported: {
|
|
13449
|
+
'dynamic-import': true,
|
|
13450
|
+
'import-meta': true,
|
|
13451
|
+
...esbuildOptions.supported
|
|
13452
|
+
}
|
|
13445
13453
|
};
|
|
13446
13454
|
// If no minify, disable all minify options
|
|
13447
13455
|
if (!minify) {
|
|
@@ -13560,11 +13568,14 @@ function reloadOnTsconfigChange(changedFile) {
|
|
|
13560
13568
|
server.moduleGraph.invalidateAll();
|
|
13561
13569
|
// reset tsconfck so that recompile works with up2date configs
|
|
13562
13570
|
initTSConfck(server.config).finally(() => {
|
|
13563
|
-
//
|
|
13564
|
-
server
|
|
13565
|
-
|
|
13566
|
-
|
|
13567
|
-
|
|
13571
|
+
// server may not be available if vite config is updated at the same time
|
|
13572
|
+
if (server) {
|
|
13573
|
+
// force full reload
|
|
13574
|
+
server.ws.send({
|
|
13575
|
+
type: 'full-reload',
|
|
13576
|
+
path: '*'
|
|
13577
|
+
});
|
|
13578
|
+
}
|
|
13568
13579
|
});
|
|
13569
13580
|
}
|
|
13570
13581
|
}
|
|
@@ -33906,6 +33917,16 @@ function resolvePlugin(resolveOptions) {
|
|
|
33906
33917
|
return res;
|
|
33907
33918
|
}
|
|
33908
33919
|
}
|
|
33920
|
+
// drive relative fs paths (only windows)
|
|
33921
|
+
if (isWindows$4 && id.startsWith('/')) {
|
|
33922
|
+
const basedir = importer ? path$n.dirname(importer) : process.cwd();
|
|
33923
|
+
const fsPath = path$n.resolve(basedir, id);
|
|
33924
|
+
if ((res = tryFsResolve(fsPath, options))) {
|
|
33925
|
+
isDebug$4 &&
|
|
33926
|
+
debug$c(`[drive-relative] ${picocolors.exports.cyan(id)} -> ${picocolors.exports.dim(res)}`);
|
|
33927
|
+
return res;
|
|
33928
|
+
}
|
|
33929
|
+
}
|
|
33909
33930
|
// absolute fs paths
|
|
33910
33931
|
if (isNonDriveRelativeAbsolutePath(id) &&
|
|
33911
33932
|
(res = tryFsResolve(id, options))) {
|
|
@@ -36116,7 +36137,7 @@ function getDepsOptimizer(config, ssr) {
|
|
|
36116
36137
|
}
|
|
36117
36138
|
async function initDepsOptimizer(config, server) {
|
|
36118
36139
|
// Non Dev SSR Optimizer
|
|
36119
|
-
const ssr = !!config.build.ssr;
|
|
36140
|
+
const ssr = config.command === 'build' && !!config.build.ssr;
|
|
36120
36141
|
if (!getDepsOptimizer(config, ssr)) {
|
|
36121
36142
|
await createDepsOptimizer(config, server);
|
|
36122
36143
|
}
|
|
@@ -36147,7 +36168,7 @@ async function initDevSsrDepsOptimizer(config, server) {
|
|
|
36147
36168
|
async function createDepsOptimizer(config, server) {
|
|
36148
36169
|
const { logger } = config;
|
|
36149
36170
|
const isBuild = config.command === 'build';
|
|
36150
|
-
const ssr = !!config.build.ssr; // safe as Dev SSR don't use this optimizer
|
|
36171
|
+
const ssr = isBuild && !!config.build.ssr; // safe as Dev SSR don't use this optimizer
|
|
36151
36172
|
const sessionTimestamp = Date.now().toString();
|
|
36152
36173
|
const cachedMetadata = loadCachedDepOptimizationMetadata(config, ssr);
|
|
36153
36174
|
let handle;
|
|
@@ -36207,41 +36228,41 @@ async function createDepsOptimizer(config, server) {
|
|
|
36207
36228
|
}
|
|
36208
36229
|
if (!isBuild) {
|
|
36209
36230
|
// Important, the scanner is dev only
|
|
36210
|
-
|
|
36211
|
-
|
|
36212
|
-
|
|
36213
|
-
|
|
36214
|
-
|
|
36215
|
-
|
|
36216
|
-
|
|
36217
|
-
|
|
36218
|
-
|
|
36219
|
-
|
|
36220
|
-
|
|
36221
|
-
|
|
36222
|
-
|
|
36223
|
-
|
|
36224
|
-
|
|
36225
|
-
|
|
36226
|
-
|
|
36227
|
-
|
|
36228
|
-
|
|
36229
|
-
|
|
36230
|
-
|
|
36231
|
-
|
|
36232
|
-
|
|
36233
|
-
|
|
36234
|
-
|
|
36235
|
-
|
|
36236
|
-
|
|
36237
|
-
|
|
36238
|
-
|
|
36239
|
-
|
|
36240
|
-
|
|
36241
|
-
|
|
36242
|
-
|
|
36243
|
-
|
|
36244
|
-
|
|
36231
|
+
const scanPhaseProcessing = newDepOptimizationProcessing();
|
|
36232
|
+
depsOptimizer.scanProcessing = scanPhaseProcessing.promise;
|
|
36233
|
+
// Ensure server listen is called before the scanner
|
|
36234
|
+
setTimeout(async () => {
|
|
36235
|
+
try {
|
|
36236
|
+
debuggerViteDeps(picocolors.exports.green(`scanning for dependencies...`));
|
|
36237
|
+
const deps = await discoverProjectDependencies(config);
|
|
36238
|
+
debuggerViteDeps(picocolors.exports.green(Object.keys(deps).length > 0
|
|
36239
|
+
? `dependencies found by scanner: ${depsLogString(Object.keys(deps))}`
|
|
36240
|
+
: `no dependencies found by scanner`));
|
|
36241
|
+
// Add these dependencies to the discovered list, as these are currently
|
|
36242
|
+
// used by the preAliasPlugin to support aliased and optimized deps.
|
|
36243
|
+
// This is also used by the CJS externalization heuristics in legacy mode
|
|
36244
|
+
for (const id of Object.keys(deps)) {
|
|
36245
|
+
if (!metadata.discovered[id]) {
|
|
36246
|
+
addMissingDep(id, deps[id]);
|
|
36247
|
+
}
|
|
36248
|
+
}
|
|
36249
|
+
if (!isBuild) {
|
|
36250
|
+
const knownDeps = prepareKnownDeps();
|
|
36251
|
+
// For dev, we run the scanner and the first optimization
|
|
36252
|
+
// run on the background, but we wait until crawling has ended
|
|
36253
|
+
// to decide if we send this result to the browser or we need to
|
|
36254
|
+
// do another optimize step
|
|
36255
|
+
postScanOptimizationResult = runOptimizeDeps(config, knownDeps);
|
|
36256
|
+
}
|
|
36257
|
+
}
|
|
36258
|
+
catch (e) {
|
|
36259
|
+
logger.error(e.message);
|
|
36260
|
+
}
|
|
36261
|
+
finally {
|
|
36262
|
+
scanPhaseProcessing.resolve();
|
|
36263
|
+
depsOptimizer.scanProcessing = undefined;
|
|
36264
|
+
}
|
|
36265
|
+
}, 0);
|
|
36245
36266
|
}
|
|
36246
36267
|
}
|
|
36247
36268
|
async function startNextDiscoveredBatch() {
|
|
@@ -36658,11 +36679,12 @@ const isDebugEnabled = _debug('vite:deps').enabled;
|
|
|
36658
36679
|
const jsExtensionRE = /\.js$/i;
|
|
36659
36680
|
const jsMapExtensionRE = /\.js\.map$/i;
|
|
36660
36681
|
/**
|
|
36661
|
-
*
|
|
36682
|
+
* Scan and optimize dependencies within a project.
|
|
36683
|
+
* Used by Vite CLI when running `vite optimize`.
|
|
36662
36684
|
*/
|
|
36663
36685
|
async function optimizeDeps(config, force = config.optimizeDeps.force, asCommand = false) {
|
|
36664
36686
|
const log = asCommand ? config.logger.info : debug$a;
|
|
36665
|
-
const ssr = !!config.build.ssr;
|
|
36687
|
+
const ssr = config.command === 'build' && !!config.build.ssr;
|
|
36666
36688
|
const cachedMetadata = loadCachedDepOptimizationMetadata(config, ssr, force, asCommand);
|
|
36667
36689
|
if (cachedMetadata) {
|
|
36668
36690
|
return cachedMetadata;
|
|
@@ -36797,7 +36819,8 @@ function depsLogString(qualifiedIds) {
|
|
|
36797
36819
|
* Internally, Vite uses this function to prepare a optimizeDeps run. When Vite starts, we can get
|
|
36798
36820
|
* the metadata and start the server without waiting for the optimizeDeps processing to be completed
|
|
36799
36821
|
*/
|
|
36800
|
-
async function runOptimizeDeps(resolvedConfig, depsInfo, ssr =
|
|
36822
|
+
async function runOptimizeDeps(resolvedConfig, depsInfo, ssr = resolvedConfig.command === 'build' &&
|
|
36823
|
+
!!resolvedConfig.build.ssr) {
|
|
36801
36824
|
const isBuild = resolvedConfig.command === 'build';
|
|
36802
36825
|
const config = {
|
|
36803
36826
|
...resolvedConfig,
|
|
@@ -37023,7 +37046,7 @@ function newDepOptimizationProcessing() {
|
|
|
37023
37046
|
function depsFromOptimizedDepInfo(depsInfo) {
|
|
37024
37047
|
return Object.fromEntries(Object.entries(depsInfo).map((d) => [d[0], d[1].src]));
|
|
37025
37048
|
}
|
|
37026
|
-
function getOptimizedDepPath(id, config, ssr
|
|
37049
|
+
function getOptimizedDepPath(id, config, ssr) {
|
|
37027
37050
|
return normalizePath$3(path$n.resolve(getDepsCacheDir(config, ssr), flattenId(id) + '.js'));
|
|
37028
37051
|
}
|
|
37029
37052
|
function getDepsCacheSuffix(config, ssr) {
|
|
@@ -37963,13 +37986,17 @@ function createIsConfiguredAsSsrExternal(config) {
|
|
|
37963
37986
|
return (id) => {
|
|
37964
37987
|
const { ssr } = config;
|
|
37965
37988
|
if (ssr) {
|
|
37966
|
-
|
|
37989
|
+
const pkgName = getNpmPackageName(id);
|
|
37990
|
+
if (!pkgName) {
|
|
37991
|
+
return undefined;
|
|
37992
|
+
}
|
|
37993
|
+
if (ssr.external?.includes(pkgName)) {
|
|
37967
37994
|
return true;
|
|
37968
37995
|
}
|
|
37969
37996
|
if (typeof noExternal === 'boolean') {
|
|
37970
37997
|
return !noExternal;
|
|
37971
37998
|
}
|
|
37972
|
-
if (noExternalFilter && !noExternalFilter(
|
|
37999
|
+
if (noExternalFilter && !noExternalFilter(pkgName)) {
|
|
37973
38000
|
return false;
|
|
37974
38001
|
}
|
|
37975
38002
|
}
|
|
@@ -38783,11 +38810,11 @@ const ssrImportKey = `__vite_ssr_import__`;
|
|
|
38783
38810
|
const ssrDynamicImportKey = `__vite_ssr_dynamic_import__`;
|
|
38784
38811
|
const ssrExportAllKey = `__vite_ssr_exportAll__`;
|
|
38785
38812
|
const ssrImportMetaKey = `__vite_ssr_import_meta__`;
|
|
38786
|
-
async function ssrTransform(code, inMap, url, options) {
|
|
38813
|
+
async function ssrTransform(code, inMap, url, originalCode, options) {
|
|
38787
38814
|
if (options?.json?.stringify && isJSONRequest(url)) {
|
|
38788
38815
|
return ssrTransformJSON(code, inMap);
|
|
38789
38816
|
}
|
|
38790
|
-
return ssrTransformScript(code, inMap, url);
|
|
38817
|
+
return ssrTransformScript(code, inMap, url, originalCode);
|
|
38791
38818
|
}
|
|
38792
38819
|
async function ssrTransformJSON(code, inMap) {
|
|
38793
38820
|
return {
|
|
@@ -38797,7 +38824,7 @@ async function ssrTransformJSON(code, inMap) {
|
|
|
38797
38824
|
dynamicDeps: []
|
|
38798
38825
|
};
|
|
38799
38826
|
}
|
|
38800
|
-
async function ssrTransformScript(code, inMap, url) {
|
|
38827
|
+
async function ssrTransformScript(code, inMap, url, originalCode) {
|
|
38801
38828
|
const s = new MagicString(code);
|
|
38802
38829
|
let ast;
|
|
38803
38830
|
try {
|
|
@@ -38976,11 +39003,13 @@ async function ssrTransformScript(code, inMap, url) {
|
|
|
38976
39003
|
sourcesContent: inMap.sourcesContent
|
|
38977
39004
|
},
|
|
38978
39005
|
inMap
|
|
38979
|
-
]);
|
|
39006
|
+
], false);
|
|
38980
39007
|
}
|
|
38981
39008
|
else {
|
|
38982
39009
|
map.sources = [url];
|
|
38983
|
-
|
|
39010
|
+
// needs to use originalCode instead of code
|
|
39011
|
+
// because code might be already transformed even if map is null
|
|
39012
|
+
map.sourcesContent = [originalCode];
|
|
38984
39013
|
}
|
|
38985
39014
|
return {
|
|
38986
39015
|
code: s.toString(),
|
|
@@ -39472,32 +39501,36 @@ function serveStaticMiddleware(dir, server) {
|
|
|
39472
39501
|
isInternalRequest(req.url)) {
|
|
39473
39502
|
return next();
|
|
39474
39503
|
}
|
|
39475
|
-
const url =
|
|
39504
|
+
const url = new URL(req.url, 'http://example.com');
|
|
39505
|
+
const pathname = decodeURIComponent(url.pathname);
|
|
39476
39506
|
// apply aliases to static requests as well
|
|
39477
|
-
let
|
|
39507
|
+
let redirectedPathname;
|
|
39478
39508
|
for (const { find, replacement } of server.config.resolve.alias) {
|
|
39479
|
-
const matches = typeof find === 'string'
|
|
39509
|
+
const matches = typeof find === 'string'
|
|
39510
|
+
? pathname.startsWith(find)
|
|
39511
|
+
: find.test(pathname);
|
|
39480
39512
|
if (matches) {
|
|
39481
|
-
|
|
39513
|
+
redirectedPathname = pathname.replace(find, replacement);
|
|
39482
39514
|
break;
|
|
39483
39515
|
}
|
|
39484
39516
|
}
|
|
39485
|
-
if (
|
|
39517
|
+
if (redirectedPathname) {
|
|
39486
39518
|
// dir is pre-normalized to posix style
|
|
39487
|
-
if (
|
|
39488
|
-
|
|
39519
|
+
if (redirectedPathname.startsWith(dir)) {
|
|
39520
|
+
redirectedPathname = redirectedPathname.slice(dir.length);
|
|
39489
39521
|
}
|
|
39490
39522
|
}
|
|
39491
|
-
const
|
|
39492
|
-
let fileUrl = path$n.resolve(dir,
|
|
39493
|
-
if (
|
|
39523
|
+
const resolvedPathname = redirectedPathname || pathname;
|
|
39524
|
+
let fileUrl = path$n.resolve(dir, resolvedPathname.replace(/^\//, ''));
|
|
39525
|
+
if (resolvedPathname.endsWith('/') && !fileUrl.endsWith('/')) {
|
|
39494
39526
|
fileUrl = fileUrl + '/';
|
|
39495
39527
|
}
|
|
39496
39528
|
if (!ensureServingAccess(fileUrl, server, res, next)) {
|
|
39497
39529
|
return;
|
|
39498
39530
|
}
|
|
39499
|
-
if (
|
|
39500
|
-
|
|
39531
|
+
if (redirectedPathname) {
|
|
39532
|
+
url.pathname = encodeURIComponent(redirectedPathname);
|
|
39533
|
+
req.url = url.href.slice(url.origin.length);
|
|
39501
39534
|
}
|
|
39502
39535
|
serve(req, res, next);
|
|
39503
39536
|
};
|
|
@@ -39506,20 +39539,22 @@ function serveRawFsMiddleware(server) {
|
|
|
39506
39539
|
const serveFromRoot = sirv('/', sirvOptions(server.config.server.headers));
|
|
39507
39540
|
// Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...`
|
|
39508
39541
|
return function viteServeRawFsMiddleware(req, res, next) {
|
|
39509
|
-
|
|
39542
|
+
const url = new URL(req.url, 'http://example.com');
|
|
39510
39543
|
// In some cases (e.g. linked monorepos) files outside of root will
|
|
39511
39544
|
// reference assets that are also out of served root. In such cases
|
|
39512
39545
|
// the paths are rewritten to `/@fs/` prefixed paths and must be served by
|
|
39513
39546
|
// searching based from fs root.
|
|
39514
|
-
if (url.startsWith(FS_PREFIX)) {
|
|
39547
|
+
if (url.pathname.startsWith(FS_PREFIX)) {
|
|
39548
|
+
const pathname = decodeURIComponent(url.pathname);
|
|
39515
39549
|
// restrict files outside of `fs.allow`
|
|
39516
|
-
if (!ensureServingAccess(slash$1(path$n.resolve(fsPathFromId(
|
|
39550
|
+
if (!ensureServingAccess(slash$1(path$n.resolve(fsPathFromId(pathname))), server, res, next)) {
|
|
39517
39551
|
return;
|
|
39518
39552
|
}
|
|
39519
|
-
|
|
39553
|
+
let newPathname = pathname.slice(FS_PREFIX.length);
|
|
39520
39554
|
if (isWindows$4)
|
|
39521
|
-
|
|
39522
|
-
|
|
39555
|
+
newPathname = newPathname.replace(/^[A-Z]:/i, '');
|
|
39556
|
+
url.pathname = encodeURIComponent(newPathname);
|
|
39557
|
+
req.url = url.href.slice(url.origin.length);
|
|
39523
39558
|
serveFromRoot(req, res, next);
|
|
39524
39559
|
}
|
|
39525
39560
|
else {
|
|
@@ -39742,6 +39777,7 @@ async function loadAndTransform(id, url, server, options, timestamp) {
|
|
|
39742
39777
|
inMap: map,
|
|
39743
39778
|
ssr
|
|
39744
39779
|
});
|
|
39780
|
+
const originalCode = code;
|
|
39745
39781
|
if (transformResult == null ||
|
|
39746
39782
|
(isObject$2(transformResult) && transformResult.code == null)) {
|
|
39747
39783
|
// no transform applied, keep code as-is
|
|
@@ -39760,7 +39796,7 @@ async function loadAndTransform(id, url, server, options, timestamp) {
|
|
|
39760
39796
|
}
|
|
39761
39797
|
}
|
|
39762
39798
|
const result = ssr
|
|
39763
|
-
? await ssrTransform(code, map, url, {
|
|
39799
|
+
? await ssrTransform(code, map, url, originalCode, {
|
|
39764
39800
|
json: { stringify: !!server.config.json?.stringify }
|
|
39765
39801
|
})
|
|
39766
39802
|
: {
|
|
@@ -40106,7 +40142,7 @@ function importAnalysisPlugin(config) {
|
|
|
40106
40142
|
if (ssr) {
|
|
40107
40143
|
return [url, url];
|
|
40108
40144
|
}
|
|
40109
|
-
this.error(`Failed to resolve import "${url}" from "${path$n.relative(process.cwd(), importerFile)}". Does the file exist?`, pos);
|
|
40145
|
+
return this.error(`Failed to resolve import "${url}" from "${path$n.relative(process.cwd(), importerFile)}". Does the file exist?`, pos);
|
|
40110
40146
|
}
|
|
40111
40147
|
const isRelative = url.startsWith('.');
|
|
40112
40148
|
const isSelfImport = !isRelative && cleanUrl(url) === cleanUrl(importer);
|
|
@@ -40652,7 +40688,7 @@ function buildImportAnalysisPlugin(config) {
|
|
|
40652
40688
|
if (ssr) {
|
|
40653
40689
|
return [url, url];
|
|
40654
40690
|
}
|
|
40655
|
-
this.error(`Failed to resolve import "${url}" from "${path$n.relative(process.cwd(), importerFile)}". Does the file exist?`, pos);
|
|
40691
|
+
return this.error(`Failed to resolve import "${url}" from "${path$n.relative(process.cwd(), importerFile)}". Does the file exist?`, pos);
|
|
40656
40692
|
}
|
|
40657
40693
|
// normalize all imports into resolved URLs
|
|
40658
40694
|
// e.g. `import 'foo'` -> `import '/@fs/.../node_modules/foo/index.js'`
|
|
@@ -41027,7 +41063,7 @@ const assetAttrsConfig = {
|
|
|
41027
41063
|
const isAsyncScriptMap = new WeakMap();
|
|
41028
41064
|
async function traverseHtml(html, filePath, visitor) {
|
|
41029
41065
|
// lazy load compiler
|
|
41030
|
-
const { parse, transform } = await import('./dep-
|
|
41066
|
+
const { parse, transform } = await import('./dep-3f457808.js').then(function (n) { return n.c; });
|
|
41031
41067
|
// @vue/compiler-core doesn't like lowercase doctypes
|
|
41032
41068
|
html = html.replace(/<!doctype\s/i, '<!DOCTYPE ');
|
|
41033
41069
|
try {
|
|
@@ -42157,7 +42193,7 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
|
|
|
42157
42193
|
logger: config.logger
|
|
42158
42194
|
}));
|
|
42159
42195
|
if (isModule) {
|
|
42160
|
-
postcssPlugins.unshift((await import('./dep-
|
|
42196
|
+
postcssPlugins.unshift((await import('./dep-f07a4e2f.js').then(function (n) { return n.i; })).default({
|
|
42161
42197
|
...modulesOptions,
|
|
42162
42198
|
getJSON(cssFileName, _modules, outputFileName) {
|
|
42163
42199
|
modules = _modules;
|
|
@@ -43353,10 +43389,10 @@ async function doBuild(inlineConfig = {}) {
|
|
|
43353
43389
|
? `[name].${jsExt}`
|
|
43354
43390
|
: libOptions
|
|
43355
43391
|
? resolveLibFilename(libOptions, format, config.root, jsExt)
|
|
43356
|
-
: path$n.posix.join(options.assetsDir, `[name].[hash]
|
|
43392
|
+
: path$n.posix.join(options.assetsDir, `[name].[hash].${jsExt}`),
|
|
43357
43393
|
chunkFileNames: libOptions
|
|
43358
43394
|
? `[name].[hash].${jsExt}`
|
|
43359
|
-
: path$n.posix.join(options.assetsDir, `[name].[hash]
|
|
43395
|
+
: path$n.posix.join(options.assetsDir, `[name].[hash].${jsExt}`),
|
|
43360
43396
|
assetFileNames: libOptions
|
|
43361
43397
|
? `[name].[ext]`
|
|
43362
43398
|
: path$n.posix.join(options.assetsDir, `[name].[hash].[ext]`),
|
|
@@ -50247,7 +50283,8 @@ async function instantiateModule(url, server, context = { global }, urlStack = [
|
|
|
50247
50283
|
if (dep[0] !== '.' && dep[0] !== '/') {
|
|
50248
50284
|
return nodeImport(dep, mod.file, resolveOptions);
|
|
50249
50285
|
}
|
|
50250
|
-
|
|
50286
|
+
// convert to rollup URL because `pendingImports`, `moduleGraph.urlToModuleMap` requires that
|
|
50287
|
+
dep = unwrapId(dep).replace(NULL_BYTE_PLACEHOLDER, '\0');
|
|
50251
50288
|
if (!isCircular(dep) && !pendingImports.get(dep)?.some(isCircular)) {
|
|
50252
50289
|
pendingDeps.push(dep);
|
|
50253
50290
|
if (pendingDeps.length === 1) {
|
|
@@ -53491,11 +53528,11 @@ function initAsClient(websocket, address, protocols, options) {
|
|
|
53491
53528
|
? parsedUrl.hostname.slice(1, -1)
|
|
53492
53529
|
: parsedUrl.hostname;
|
|
53493
53530
|
opts.headers = {
|
|
53531
|
+
...opts.headers,
|
|
53494
53532
|
'Sec-WebSocket-Version': opts.protocolVersion,
|
|
53495
53533
|
'Sec-WebSocket-Key': key,
|
|
53496
53534
|
Connection: 'Upgrade',
|
|
53497
|
-
Upgrade: 'websocket'
|
|
53498
|
-
...opts.headers
|
|
53535
|
+
Upgrade: 'websocket'
|
|
53499
53536
|
};
|
|
53500
53537
|
opts.path = parsedUrl.pathname + parsedUrl.search;
|
|
53501
53538
|
opts.timeout = opts.handshakeTimeout;
|
|
@@ -53549,8 +53586,11 @@ function initAsClient(websocket, address, protocols, options) {
|
|
|
53549
53586
|
|
|
53550
53587
|
if (opts.followRedirects) {
|
|
53551
53588
|
if (websocket._redirects === 0) {
|
|
53589
|
+
websocket._originalUnixSocket = isUnixSocket;
|
|
53552
53590
|
websocket._originalSecure = isSecure;
|
|
53553
|
-
websocket.
|
|
53591
|
+
websocket._originalHostOrSocketPath = isUnixSocket
|
|
53592
|
+
? opts.socketPath
|
|
53593
|
+
: parsedUrl.host;
|
|
53554
53594
|
|
|
53555
53595
|
const headers = options && options.headers;
|
|
53556
53596
|
|
|
@@ -53566,7 +53606,13 @@ function initAsClient(websocket, address, protocols, options) {
|
|
|
53566
53606
|
}
|
|
53567
53607
|
}
|
|
53568
53608
|
} else if (websocket.listenerCount('redirect') === 0) {
|
|
53569
|
-
const isSameHost =
|
|
53609
|
+
const isSameHost = isUnixSocket
|
|
53610
|
+
? websocket._originalUnixSocket
|
|
53611
|
+
? opts.socketPath === websocket._originalHostOrSocketPath
|
|
53612
|
+
: false
|
|
53613
|
+
: websocket._originalUnixSocket
|
|
53614
|
+
? false
|
|
53615
|
+
: parsedUrl.host === websocket._originalHostOrSocketPath;
|
|
53570
53616
|
|
|
53571
53617
|
if (!isSameHost || (websocket._originalSecure && !isSecure)) {
|
|
53572
53618
|
//
|
|
@@ -56933,16 +56979,29 @@ function proxyMiddleware(httpServer, options, config) {
|
|
|
56933
56979
|
opts = { target: opts, changeOrigin: true };
|
|
56934
56980
|
}
|
|
56935
56981
|
const proxy = httpProxy.createProxyServer(opts);
|
|
56936
|
-
proxy.on('error', (err, req,
|
|
56937
|
-
|
|
56938
|
-
|
|
56939
|
-
|
|
56940
|
-
|
|
56941
|
-
|
|
56942
|
-
|
|
56943
|
-
|
|
56944
|
-
|
|
56945
|
-
|
|
56982
|
+
proxy.on('error', (err, req, originalRes) => {
|
|
56983
|
+
// When it is ws proxy, res is net.Socket
|
|
56984
|
+
const res = originalRes;
|
|
56985
|
+
if ('req' in res) {
|
|
56986
|
+
config.logger.error(`${picocolors.exports.red(`http proxy error:`)}\n${err.stack}`, {
|
|
56987
|
+
timestamp: true,
|
|
56988
|
+
error: err
|
|
56989
|
+
});
|
|
56990
|
+
if (!res.headersSent && !res.writableEnded) {
|
|
56991
|
+
res
|
|
56992
|
+
.writeHead(500, {
|
|
56993
|
+
'Content-Type': 'text/plain'
|
|
56994
|
+
})
|
|
56995
|
+
.end();
|
|
56996
|
+
}
|
|
56997
|
+
}
|
|
56998
|
+
else {
|
|
56999
|
+
config.logger.error(`${picocolors.exports.red(`ws proxy error:`)}\n${err.stack}`, {
|
|
57000
|
+
timestamp: true,
|
|
57001
|
+
error: err
|
|
57002
|
+
});
|
|
57003
|
+
res.end();
|
|
57004
|
+
}
|
|
56946
57005
|
});
|
|
56947
57006
|
if (opts.configure) {
|
|
56948
57007
|
opts.configure(proxy, opts);
|
|
@@ -57724,10 +57783,14 @@ class ModuleGraph {
|
|
|
57724
57783
|
url = removeImportQuery(removeTimestampQuery(url));
|
|
57725
57784
|
const resolved = await this.resolveId(url, !!ssr);
|
|
57726
57785
|
const resolvedId = resolved?.id || url;
|
|
57727
|
-
|
|
57728
|
-
|
|
57729
|
-
|
|
57730
|
-
|
|
57786
|
+
if (url !== resolvedId &&
|
|
57787
|
+
!url.includes('\0') &&
|
|
57788
|
+
!url.startsWith(`virtual:`)) {
|
|
57789
|
+
const ext = extname$1(cleanUrl(resolvedId));
|
|
57790
|
+
const { pathname, search, hash } = new URL(url, 'relative://');
|
|
57791
|
+
if (ext && !pathname.endsWith(ext)) {
|
|
57792
|
+
url = pathname + ext + search + hash;
|
|
57793
|
+
}
|
|
57731
57794
|
}
|
|
57732
57795
|
return [url, resolvedId, resolved?.meta];
|
|
57733
57796
|
}
|
|
@@ -58930,8 +58993,9 @@ async function createServer(inlineConfig = {}) {
|
|
|
58930
58993
|
pluginContainer: container,
|
|
58931
58994
|
ws,
|
|
58932
58995
|
moduleGraph,
|
|
58996
|
+
resolvedUrls: null,
|
|
58933
58997
|
ssrTransform(code, inMap, url) {
|
|
58934
|
-
return ssrTransform(code, inMap, url, {
|
|
58998
|
+
return ssrTransform(code, inMap, url, code, {
|
|
58935
58999
|
json: { stringify: server.config.json?.stringify }
|
|
58936
59000
|
});
|
|
58937
59001
|
},
|
|
@@ -58955,8 +59019,12 @@ async function createServer(inlineConfig = {}) {
|
|
|
58955
59019
|
ssrRewriteStacktrace(stack) {
|
|
58956
59020
|
return ssrRewriteStacktrace(stack, moduleGraph);
|
|
58957
59021
|
},
|
|
58958
|
-
listen(port, isRestart) {
|
|
58959
|
-
|
|
59022
|
+
async listen(port, isRestart) {
|
|
59023
|
+
await startServer(server, port, isRestart);
|
|
59024
|
+
if (httpServer) {
|
|
59025
|
+
server.resolvedUrls = await resolveServerUrls(httpServer, config.server, config);
|
|
59026
|
+
}
|
|
59027
|
+
return server;
|
|
58960
59028
|
},
|
|
58961
59029
|
async close() {
|
|
58962
59030
|
if (!middlewareMode) {
|
|
@@ -58971,14 +59039,18 @@ async function createServer(inlineConfig = {}) {
|
|
|
58971
59039
|
container.close(),
|
|
58972
59040
|
closeHttpServer()
|
|
58973
59041
|
]);
|
|
59042
|
+
server.resolvedUrls = null;
|
|
58974
59043
|
},
|
|
58975
|
-
|
|
58976
|
-
if (
|
|
58977
|
-
|
|
59044
|
+
printUrls() {
|
|
59045
|
+
if (server.resolvedUrls) {
|
|
59046
|
+
printServerUrls(server.resolvedUrls, serverConfig.host, config.logger.info);
|
|
58978
59047
|
}
|
|
58979
|
-
else {
|
|
59048
|
+
else if (middlewareMode) {
|
|
58980
59049
|
throw new Error('cannot print server URLs in middleware mode.');
|
|
58981
59050
|
}
|
|
59051
|
+
else {
|
|
59052
|
+
throw new Error('cannot print server URLs before server.listen is called.');
|
|
59053
|
+
}
|
|
58982
59054
|
},
|
|
58983
59055
|
async restart(forceOptimize) {
|
|
58984
59056
|
if (!server._restartPromise) {
|
|
@@ -59187,7 +59259,6 @@ async function startServer(server, inlinePort, isRestart = false) {
|
|
|
59187
59259
|
? path
|
|
59188
59260
|
: `${protocol}://${hostname.name}:${serverPort}${path}`, true, server.config.logger);
|
|
59189
59261
|
}
|
|
59190
|
-
return server;
|
|
59191
59262
|
}
|
|
59192
59263
|
function createServerCloseFn(server) {
|
|
59193
59264
|
if (!server) {
|
|
@@ -59494,6 +59565,7 @@ async function preview(inlineConfig = {}) {
|
|
|
59494
59565
|
host: hostname.host,
|
|
59495
59566
|
logger
|
|
59496
59567
|
});
|
|
59568
|
+
const resolvedUrls = await resolveServerUrls(httpServer, config.preview, config);
|
|
59497
59569
|
if (options.open) {
|
|
59498
59570
|
const path = typeof options.open === 'string' ? options.open : previewBase;
|
|
59499
59571
|
openBrowser(path.startsWith('http')
|
|
@@ -59503,8 +59575,9 @@ async function preview(inlineConfig = {}) {
|
|
|
59503
59575
|
return {
|
|
59504
59576
|
config,
|
|
59505
59577
|
httpServer,
|
|
59506
|
-
|
|
59507
|
-
|
|
59578
|
+
resolvedUrls,
|
|
59579
|
+
printUrls() {
|
|
59580
|
+
printServerUrls(resolvedUrls, options.host, logger.info);
|
|
59508
59581
|
}
|
|
59509
59582
|
};
|
|
59510
59583
|
}
|
|
@@ -59527,6 +59600,10 @@ function clientInjectionsPlugin(config) {
|
|
|
59527
59600
|
name: 'vite:client-inject',
|
|
59528
59601
|
async transform(code, id, options) {
|
|
59529
59602
|
if (id === normalizedClientEntry || id === normalizedEnvEntry) {
|
|
59603
|
+
const resolvedServerHostname = (await resolveHostname(config.server.host)).name;
|
|
59604
|
+
const resolvedServerPort = config.server.port;
|
|
59605
|
+
const devBase = config.base;
|
|
59606
|
+
const serverHost = `${resolvedServerHostname}:${resolvedServerPort}${devBase}`;
|
|
59530
59607
|
let hmrConfig = config.server.hmr;
|
|
59531
59608
|
hmrConfig = isObject$2(hmrConfig) ? hmrConfig : undefined;
|
|
59532
59609
|
const host = hmrConfig?.host || null;
|
|
@@ -59539,9 +59616,8 @@ function clientInjectionsPlugin(config) {
|
|
|
59539
59616
|
if (config.server.middlewareMode) {
|
|
59540
59617
|
port || (port = 24678);
|
|
59541
59618
|
}
|
|
59542
|
-
|
|
59543
|
-
|
|
59544
|
-
directTarget += `:${hmrConfig?.port || config.server.port}`;
|
|
59619
|
+
let directTarget = hmrConfig?.host || resolvedServerHostname;
|
|
59620
|
+
directTarget += `:${hmrConfig?.port || resolvedServerPort}`;
|
|
59545
59621
|
directTarget += devBase;
|
|
59546
59622
|
let hmrBase = devBase;
|
|
59547
59623
|
if (hmrConfig?.path) {
|
|
@@ -59551,6 +59627,7 @@ function clientInjectionsPlugin(config) {
|
|
|
59551
59627
|
.replace(`__MODE__`, JSON.stringify(config.mode))
|
|
59552
59628
|
.replace(`__BASE__`, JSON.stringify(devBase))
|
|
59553
59629
|
.replace(`__DEFINES__`, serializeDefine(config.define || {}))
|
|
59630
|
+
.replace(`__SERVER_HOST__`, JSON.stringify(serverHost))
|
|
59554
59631
|
.replace(`__HMR_PROTOCOL__`, JSON.stringify(protocol))
|
|
59555
59632
|
.replace(`__HMR_HOSTNAME__`, JSON.stringify(host))
|
|
59556
59633
|
.replace(`__HMR_PORT__`, JSON.stringify(port))
|
|
@@ -61942,7 +62019,7 @@ async function resolvePlugins(config, prePlugins, normalPlugins, postPlugins) {
|
|
|
61942
62019
|
wasmFallbackPlugin(),
|
|
61943
62020
|
definePlugin(config),
|
|
61944
62021
|
cssPostPlugin(config),
|
|
61945
|
-
config.build.ssr ? ssrRequireHookPlugin(config) : null,
|
|
62022
|
+
isBuild && config.build.ssr ? ssrRequireHookPlugin(config) : null,
|
|
61946
62023
|
isBuild && buildHtmlPlugin(config),
|
|
61947
62024
|
workerImportMetaUrlPlugin(config),
|
|
61948
62025
|
...buildPlugins.pre,
|
|
@@ -62244,7 +62321,6 @@ function defineConfig(config) {
|
|
|
62244
62321
|
return config;
|
|
62245
62322
|
}
|
|
62246
62323
|
async function resolveConfig(inlineConfig, command, defaultMode = 'development') {
|
|
62247
|
-
var _a;
|
|
62248
62324
|
let config = inlineConfig;
|
|
62249
62325
|
let configFileDependencies = [];
|
|
62250
62326
|
let mode = inlineConfig.mode || defaultMode;
|
|
@@ -62254,6 +62330,10 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development')
|
|
|
62254
62330
|
if (mode === 'production') {
|
|
62255
62331
|
process.env.NODE_ENV = 'production';
|
|
62256
62332
|
}
|
|
62333
|
+
// production env would not work in serve, fallback to development
|
|
62334
|
+
if (command === 'serve' && process.env.NODE_ENV === 'production') {
|
|
62335
|
+
process.env.NODE_ENV = 'development';
|
|
62336
|
+
}
|
|
62257
62337
|
const configEnv = {
|
|
62258
62338
|
mode,
|
|
62259
62339
|
command,
|
|
@@ -62308,6 +62388,14 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development')
|
|
|
62308
62388
|
}
|
|
62309
62389
|
}
|
|
62310
62390
|
}
|
|
62391
|
+
if (process.env.VITE_TEST_WITHOUT_PLUGIN_COMMONJS) {
|
|
62392
|
+
config = mergeConfig(config, {
|
|
62393
|
+
optimizeDeps: { disabled: false },
|
|
62394
|
+
ssr: { optimizeDeps: { disabled: false } }
|
|
62395
|
+
});
|
|
62396
|
+
config.build ?? (config.build = {});
|
|
62397
|
+
config.build.commonjsOptions = { include: [] };
|
|
62398
|
+
}
|
|
62311
62399
|
// resolve root
|
|
62312
62400
|
const resolvedRoot = normalizePath$3(config.root ? path$n.resolve(config.root) : process.cwd());
|
|
62313
62401
|
const clientAlias = [
|
|
@@ -62407,15 +62495,6 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development')
|
|
|
62407
62495
|
const ssr = resolveSSROptions(config.ssr, config.legacy?.buildSsrCjsExternalHeuristics, config.resolve?.preserveSymlinks);
|
|
62408
62496
|
const middlewareMode = config?.server?.middlewareMode;
|
|
62409
62497
|
const optimizeDeps = config.optimizeDeps || {};
|
|
62410
|
-
if (process.env.VITE_TEST_WITHOUT_PLUGIN_COMMONJS) {
|
|
62411
|
-
config.build ?? (config.build = {});
|
|
62412
|
-
config.build.commonjsOptions = { include: [] };
|
|
62413
|
-
config.optimizeDeps ?? (config.optimizeDeps = {});
|
|
62414
|
-
config.optimizeDeps.disabled = false;
|
|
62415
|
-
config.ssr ?? (config.ssr = {});
|
|
62416
|
-
(_a = config.ssr).optimizeDeps ?? (_a.optimizeDeps = {});
|
|
62417
|
-
config.ssr.optimizeDeps.disabled = false;
|
|
62418
|
-
}
|
|
62419
62498
|
const BASE_URL = resolvedBase;
|
|
62420
62499
|
const resolved = {
|
|
62421
62500
|
...config,
|
|
@@ -62574,7 +62653,6 @@ async function loadConfigFromFile(configEnv, configFile, configRoot = process.cw
|
|
|
62574
62653
|
const start = performance.now();
|
|
62575
62654
|
const getTime = () => `${(performance.now() - start).toFixed(2)}ms`;
|
|
62576
62655
|
let resolvedPath;
|
|
62577
|
-
let dependencies = [];
|
|
62578
62656
|
if (configFile) {
|
|
62579
62657
|
// explicit config path is always resolved from cwd
|
|
62580
62658
|
resolvedPath = path$n.resolve(configFile);
|
|
@@ -62610,41 +62688,9 @@ async function loadConfigFromFile(configEnv, configFile, configRoot = process.cw
|
|
|
62610
62688
|
catch (e) { }
|
|
62611
62689
|
}
|
|
62612
62690
|
try {
|
|
62613
|
-
|
|
62614
|
-
|
|
62615
|
-
|
|
62616
|
-
const bundled = await bundleConfigFile(resolvedPath, true);
|
|
62617
|
-
dependencies = bundled.dependencies;
|
|
62618
|
-
if (isTS(resolvedPath)) {
|
|
62619
|
-
// before we can register loaders without requiring users to run node
|
|
62620
|
-
// with --experimental-loader themselves, we have to do a hack here:
|
|
62621
|
-
// bundle the config file w/ ts transforms first, write it to disk,
|
|
62622
|
-
// load it with native Node ESM, then delete the file.
|
|
62623
|
-
fs$l.writeFileSync(resolvedPath + '.mjs', bundled.code);
|
|
62624
|
-
try {
|
|
62625
|
-
userConfig = (await dynamicImport(`${fileUrl}.mjs?t=${Date.now()}`))
|
|
62626
|
-
.default;
|
|
62627
|
-
}
|
|
62628
|
-
finally {
|
|
62629
|
-
fs$l.unlinkSync(resolvedPath + '.mjs');
|
|
62630
|
-
}
|
|
62631
|
-
debug(`TS + native esm config loaded in ${getTime()}`, fileUrl);
|
|
62632
|
-
}
|
|
62633
|
-
else {
|
|
62634
|
-
// using Function to avoid this from being compiled away by TS/Rollup
|
|
62635
|
-
// append a query so that we force reload fresh config in case of
|
|
62636
|
-
// server restart
|
|
62637
|
-
userConfig = (await dynamicImport(`${fileUrl}?t=${Date.now()}`)).default;
|
|
62638
|
-
debug(`native esm config loaded in ${getTime()}`, fileUrl);
|
|
62639
|
-
}
|
|
62640
|
-
}
|
|
62641
|
-
if (!userConfig) {
|
|
62642
|
-
// Bundle config file and transpile it to cjs using esbuild.
|
|
62643
|
-
const bundled = await bundleConfigFile(resolvedPath);
|
|
62644
|
-
dependencies = bundled.dependencies;
|
|
62645
|
-
userConfig = await loadConfigFromBundledFile(resolvedPath, bundled.code);
|
|
62646
|
-
debug(`bundled config file loaded in ${getTime()}`);
|
|
62647
|
-
}
|
|
62691
|
+
const bundled = await bundleConfigFile(resolvedPath, isESM);
|
|
62692
|
+
const userConfig = await loadConfigFromBundledFile(resolvedPath, bundled.code, isESM);
|
|
62693
|
+
debug(`bundled config file loaded in ${getTime()}`);
|
|
62648
62694
|
const config = await (typeof userConfig === 'function'
|
|
62649
62695
|
? userConfig(configEnv)
|
|
62650
62696
|
: userConfig);
|
|
@@ -62654,7 +62700,7 @@ async function loadConfigFromFile(configEnv, configFile, configRoot = process.cw
|
|
|
62654
62700
|
return {
|
|
62655
62701
|
path: normalizePath$3(resolvedPath),
|
|
62656
62702
|
config,
|
|
62657
|
-
dependencies
|
|
62703
|
+
dependencies: bundled.dependencies
|
|
62658
62704
|
};
|
|
62659
62705
|
}
|
|
62660
62706
|
catch (e) {
|
|
@@ -62662,7 +62708,9 @@ async function loadConfigFromFile(configEnv, configFile, configRoot = process.cw
|
|
|
62662
62708
|
throw e;
|
|
62663
62709
|
}
|
|
62664
62710
|
}
|
|
62665
|
-
async function bundleConfigFile(fileName, isESM
|
|
62711
|
+
async function bundleConfigFile(fileName, isESM) {
|
|
62712
|
+
const dirnameVarName = '__vite_injected_original_dirname';
|
|
62713
|
+
const filenameVarName = '__vite_injected_original_filename';
|
|
62666
62714
|
const importMetaUrlVarName = '__vite_injected_original_import_meta_url';
|
|
62667
62715
|
const result = await build$3({
|
|
62668
62716
|
absWorkingDir: process.cwd(),
|
|
@@ -62675,19 +62723,48 @@ async function bundleConfigFile(fileName, isESM = false) {
|
|
|
62675
62723
|
sourcemap: 'inline',
|
|
62676
62724
|
metafile: true,
|
|
62677
62725
|
define: {
|
|
62726
|
+
__dirname: dirnameVarName,
|
|
62727
|
+
__filename: filenameVarName,
|
|
62678
62728
|
'import.meta.url': importMetaUrlVarName
|
|
62679
62729
|
},
|
|
62680
62730
|
plugins: [
|
|
62681
62731
|
{
|
|
62682
62732
|
name: 'externalize-deps',
|
|
62683
62733
|
setup(build) {
|
|
62684
|
-
build.onResolve({ filter: /.*/ }, (
|
|
62685
|
-
|
|
62734
|
+
build.onResolve({ filter: /.*/ }, ({ path: id, importer }) => {
|
|
62735
|
+
// externalize bare imports
|
|
62686
62736
|
if (id[0] !== '.' && !path$n.isAbsolute(id)) {
|
|
62687
62737
|
return {
|
|
62688
62738
|
external: true
|
|
62689
62739
|
};
|
|
62690
62740
|
}
|
|
62741
|
+
// bundle the rest and make sure that the we can also access
|
|
62742
|
+
// it's third-party dependencies. externalize if not.
|
|
62743
|
+
// monorepo/
|
|
62744
|
+
// ├─ package.json
|
|
62745
|
+
// ├─ utils.js -----------> bundle (share same node_modules)
|
|
62746
|
+
// ├─ vite-project/
|
|
62747
|
+
// │ ├─ vite.config.js --> entry
|
|
62748
|
+
// │ ├─ package.json
|
|
62749
|
+
// ├─ foo-project/
|
|
62750
|
+
// │ ├─ utils.js --------> external (has own node_modules)
|
|
62751
|
+
// │ ├─ package.json
|
|
62752
|
+
const idFsPath = path$n.resolve(path$n.dirname(importer), id);
|
|
62753
|
+
const idPkgPath = lookupFile(idFsPath, [`package.json`], {
|
|
62754
|
+
pathOnly: true
|
|
62755
|
+
});
|
|
62756
|
+
if (idPkgPath) {
|
|
62757
|
+
const idPkgDir = path$n.dirname(idPkgPath);
|
|
62758
|
+
// if this file needs to go up one or more directory to reach the vite config,
|
|
62759
|
+
// that means it has it's own node_modules (e.g. foo-project)
|
|
62760
|
+
if (path$n.relative(idPkgDir, fileName).startsWith('..')) {
|
|
62761
|
+
return {
|
|
62762
|
+
// normalize actual import after bundled as a single vite config
|
|
62763
|
+
path: idFsPath,
|
|
62764
|
+
external: true
|
|
62765
|
+
};
|
|
62766
|
+
}
|
|
62767
|
+
}
|
|
62691
62768
|
});
|
|
62692
62769
|
}
|
|
62693
62770
|
},
|
|
@@ -62696,11 +62773,11 @@ async function bundleConfigFile(fileName, isESM = false) {
|
|
|
62696
62773
|
setup(build) {
|
|
62697
62774
|
build.onLoad({ filter: /\.[cm]?[jt]s$/ }, async (args) => {
|
|
62698
62775
|
const contents = await fs$l.promises.readFile(args.path, 'utf8');
|
|
62699
|
-
const injectValues = `const
|
|
62700
|
-
`const
|
|
62776
|
+
const injectValues = `const ${dirnameVarName} = ${JSON.stringify(path$n.dirname(args.path))};` +
|
|
62777
|
+
`const ${filenameVarName} = ${JSON.stringify(args.path)};` +
|
|
62701
62778
|
`const ${importMetaUrlVarName} = ${JSON.stringify(pathToFileURL(args.path).href)};`;
|
|
62702
62779
|
return {
|
|
62703
|
-
loader:
|
|
62780
|
+
loader: args.path.endsWith('ts') ? 'ts' : 'js',
|
|
62704
62781
|
contents: injectValues + contents
|
|
62705
62782
|
};
|
|
62706
62783
|
});
|
|
@@ -62715,22 +62792,40 @@ async function bundleConfigFile(fileName, isESM = false) {
|
|
|
62715
62792
|
};
|
|
62716
62793
|
}
|
|
62717
62794
|
const _require = createRequire$1(import.meta.url);
|
|
62718
|
-
async function loadConfigFromBundledFile(fileName, bundledCode) {
|
|
62719
|
-
|
|
62720
|
-
|
|
62721
|
-
|
|
62722
|
-
|
|
62723
|
-
|
|
62795
|
+
async function loadConfigFromBundledFile(fileName, bundledCode, isESM) {
|
|
62796
|
+
// for esm, before we can register loaders without requiring users to run node
|
|
62797
|
+
// with --experimental-loader themselves, we have to do a hack here:
|
|
62798
|
+
// write it to disk, load it with native Node ESM, then delete the file.
|
|
62799
|
+
if (isESM) {
|
|
62800
|
+
const fileUrl = pathToFileURL(fileName);
|
|
62801
|
+
fs$l.writeFileSync(fileName + '.mjs', bundledCode);
|
|
62802
|
+
try {
|
|
62803
|
+
return (await dynamicImport(`${fileUrl}.mjs?t=${Date.now()}`)).default;
|
|
62724
62804
|
}
|
|
62725
|
-
|
|
62726
|
-
|
|
62805
|
+
finally {
|
|
62806
|
+
fs$l.unlinkSync(fileName + '.mjs');
|
|
62727
62807
|
}
|
|
62728
|
-
}
|
|
62729
|
-
//
|
|
62730
|
-
|
|
62731
|
-
|
|
62732
|
-
|
|
62733
|
-
|
|
62808
|
+
}
|
|
62809
|
+
// for cjs, we can register a custom loader via `_require.extensions`
|
|
62810
|
+
else {
|
|
62811
|
+
const extension = path$n.extname(fileName);
|
|
62812
|
+
const realFileName = fs$l.realpathSync(fileName);
|
|
62813
|
+
const loaderExt = extension in _require.extensions ? extension : '.js';
|
|
62814
|
+
const defaultLoader = _require.extensions[loaderExt];
|
|
62815
|
+
_require.extensions[loaderExt] = (module, filename) => {
|
|
62816
|
+
if (filename === realFileName) {
|
|
62817
|
+
module._compile(bundledCode, filename);
|
|
62818
|
+
}
|
|
62819
|
+
else {
|
|
62820
|
+
defaultLoader(module, filename);
|
|
62821
|
+
}
|
|
62822
|
+
};
|
|
62823
|
+
// clear cache in case of server restart
|
|
62824
|
+
delete _require.cache[_require.resolve(fileName)];
|
|
62825
|
+
const raw = _require(fileName);
|
|
62826
|
+
_require.extensions[loaderExt] = defaultLoader;
|
|
62827
|
+
return raw.__esModule ? raw.default : raw;
|
|
62828
|
+
}
|
|
62734
62829
|
}
|
|
62735
62830
|
function getDepOptimizationConfig(config, ssr) {
|
|
62736
62831
|
return ssr ? config.ssr.optimizeDeps : config.optimizeDeps;
|