vite 3.2.3 → 4.0.0-alpha.1

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.
@@ -222,7 +222,7 @@ function alias$1(options = {}) {
222
222
  replace: (node: BaseNode) => void;
223
223
  }} WalkerContext */
224
224
 
225
- class WalkerBase$1 {
225
+ let WalkerBase$1 = class WalkerBase {
226
226
  constructor() {
227
227
  /** @type {boolean} */
228
228
  this.should_skip = false;
@@ -273,7 +273,7 @@ class WalkerBase$1 {
273
273
  }
274
274
  }
275
275
  }
276
- }
276
+ };
277
277
 
278
278
  // @ts-check
279
279
 
@@ -288,7 +288,7 @@ class WalkerBase$1 {
288
288
  * index: number
289
289
  * ) => void} SyncHandler */
290
290
 
291
- class SyncWalker$1 extends WalkerBase$1 {
291
+ let SyncWalker$1 = class SyncWalker extends WalkerBase$1 {
292
292
  /**
293
293
  *
294
294
  * @param {SyncHandler} enter
@@ -391,7 +391,7 @@ class SyncWalker$1 extends WalkerBase$1 {
391
391
 
392
392
  return node;
393
393
  }
394
- }
394
+ };
395
395
 
396
396
  // @ts-check
397
397
 
@@ -2521,7 +2521,7 @@ const blockDeclarations = {
2521
2521
  const: true,
2522
2522
  let: true
2523
2523
  };
2524
- class Scope$1 {
2524
+ let Scope$1 = class Scope {
2525
2525
  constructor(options = {}) {
2526
2526
  this.parent = options.parent;
2527
2527
  this.isBlockScope = !!options.block;
@@ -2549,7 +2549,7 @@ class Scope$1 {
2549
2549
  contains(name) {
2550
2550
  return this.declarations[name] || (this.parent ? this.parent.contains(name) : false);
2551
2551
  }
2552
- }
2552
+ };
2553
2553
  const attachScopes = function attachScopes(ast, propertyName = 'scope') {
2554
2554
  let scope = new Scope$1();
2555
2555
  walk$3(ast, {
@@ -3533,7 +3533,7 @@ minimatch$1.match = (list, pattern, options = {}) => {
3533
3533
  const globUnescape = s => s.replace(/\\(.)/g, '$1');
3534
3534
  const regExpEscape = s => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
3535
3535
 
3536
- class Minimatch$1 {
3536
+ let Minimatch$1 = class Minimatch {
3537
3537
  constructor (pattern, options) {
3538
3538
  assertValidPattern(pattern);
3539
3539
 
@@ -4265,7 +4265,7 @@ class Minimatch$1 {
4265
4265
  static defaults (def) {
4266
4266
  return minimatch$1.defaults(def).Minimatch
4267
4267
  }
4268
- }
4268
+ };
4269
4269
 
4270
4270
  minimatch$1.Minimatch = Minimatch$1;
4271
4271
 
@@ -6216,7 +6216,7 @@ function getBtoa () {
6216
6216
 
6217
6217
  const btoa$1 = /*#__PURE__*/ getBtoa();
6218
6218
 
6219
- class SourceMap$1 {
6219
+ let SourceMap$1 = class SourceMap {
6220
6220
  constructor(properties) {
6221
6221
  this.version = 3;
6222
6222
  this.file = properties.file;
@@ -6233,7 +6233,7 @@ class SourceMap$1 {
6233
6233
  toUrl() {
6234
6234
  return 'data:application/json;charset=utf-8;base64,' + btoa$1(this.toString());
6235
6235
  }
6236
- }
6236
+ };
6237
6237
 
6238
6238
  function guessIndent(code) {
6239
6239
  const lines = code.split('\n');
@@ -12232,7 +12232,7 @@ async function resolveServerUrls(server, options, config) {
12232
12232
  const hostname = await resolveHostname(options.host);
12233
12233
  const protocol = options.https ? 'https' : 'http';
12234
12234
  const port = address.port;
12235
- const base = config.base === './' || config.base === '' ? '/' : config.base;
12235
+ const base = config.rawBase === './' || config.rawBase === '' ? '/' : config.rawBase;
12236
12236
  if (hostname.host && loopbackHosts.has(hostname.host)) {
12237
12237
  let hostnameName = hostname.name;
12238
12238
  if (hostnameName === '::1' ||
@@ -12299,12 +12299,15 @@ function getHash(text) {
12299
12299
  return createHash$2('sha256').update(text).digest('hex').substring(0, 8);
12300
12300
  }
12301
12301
  const requireResolveFromRootWithFallback = (root, id) => {
12302
+ const paths = _require$4.resolve.paths?.(id) || [];
12302
12303
  // Search in the root directory first, and fallback to the default require paths.
12303
- const fallbackPaths = _require$4.resolve.paths?.(id) || [];
12304
- const path = _require$4.resolve(id, {
12305
- paths: [root, ...fallbackPaths]
12306
- });
12307
- return path;
12304
+ paths.unshift(root);
12305
+ // Use `resolve` package to check existence first, so if the package is not found,
12306
+ // it won't be cached by nodejs, since there isn't a way to invalidate them:
12307
+ // https://github.com/nodejs/node/issues/44663
12308
+ resolve$5.sync(id, { basedir: root, paths });
12309
+ // Use `require.resolve` again as the `resolve` package doesn't support the `exports` field
12310
+ return _require$4.resolve(id, { paths });
12308
12311
  };
12309
12312
  // Based on node-graceful-fs
12310
12313
  // The ISC License
@@ -12484,6 +12487,37 @@ const isNonDriveRelativeAbsolutePath = (p) => {
12484
12487
  return p.startsWith('/');
12485
12488
  return windowsDrivePathPrefixRE.test(p);
12486
12489
  };
12490
+ /**
12491
+ * Determine if a file is being requested with the correct case, to ensure
12492
+ * consistent behaviour between dev and prod and across operating systems.
12493
+ */
12494
+ function shouldServe(url, assetsDir) {
12495
+ // viteTestUrl is set to something like http://localhost:4173/ and then many tests make calls
12496
+ // like `await page.goto(viteTestUrl + '/example')` giving us URLs beginning with a double slash
12497
+ const pathname = decodeURI(new URL$3(url.startsWith('//') ? url.substring(1) : url, 'http://example.com')
12498
+ .pathname);
12499
+ const file = path$o.join(assetsDir, pathname);
12500
+ if (!fs$l.existsSync(file) ||
12501
+ (isCaseInsensitiveFS && // can skip case check on Linux
12502
+ !fs$l.statSync(file).isDirectory() &&
12503
+ !hasCorrectCase(file, assetsDir))) {
12504
+ return false;
12505
+ }
12506
+ return true;
12507
+ }
12508
+ /**
12509
+ * Note that we can't use realpath here, because we don't want to follow
12510
+ * symlinks.
12511
+ */
12512
+ function hasCorrectCase(file, assets) {
12513
+ if (file === assets)
12514
+ return true;
12515
+ const parent = path$o.dirname(file);
12516
+ if (fs$l.readdirSync(parent).includes(path$o.basename(file))) {
12517
+ return hasCorrectCase(parent, assets);
12518
+ }
12519
+ return false;
12520
+ }
12487
12521
  function joinUrlSegments(a, b) {
12488
12522
  if (!a || !b) {
12489
12523
  return a || b || '';
@@ -12496,6 +12530,24 @@ function joinUrlSegments(a, b) {
12496
12530
  }
12497
12531
  return a + b;
12498
12532
  }
12533
+ function stripBase(path, base) {
12534
+ if (path === base) {
12535
+ return '/';
12536
+ }
12537
+ const devBase = base.endsWith('/') ? base : base + '/';
12538
+ return path.replace(RegExp('^' + devBase), '/');
12539
+ }
12540
+ function arrayEqual(a, b) {
12541
+ if (a === b)
12542
+ return true;
12543
+ if (a.length !== b.length)
12544
+ return false;
12545
+ for (let i = 0; i < a.length; i++) {
12546
+ if (a[i] !== b[i])
12547
+ return false;
12548
+ }
12549
+ return true;
12550
+ }
12499
12551
 
12500
12552
  /* eslint no-console: 0 */
12501
12553
  const LogLevels = {
@@ -13401,6 +13453,7 @@ function esbuildPlugin(options = {}) {
13401
13453
  // and for build as the final optimization is in `buildEsbuildPlugin`
13402
13454
  const transformOptions = {
13403
13455
  target: 'esnext',
13456
+ charset: 'utf8',
13404
13457
  ...options,
13405
13458
  minify: false,
13406
13459
  minifyIdentifiers: false,
@@ -13507,6 +13560,7 @@ function resolveEsbuildTranspileOptions(config, format) {
13507
13560
  const isEsLibBuild = config.build.lib && format === 'es';
13508
13561
  const esbuildOptions = config.esbuild || {};
13509
13562
  const options = {
13563
+ charset: 'utf8',
13510
13564
  ...esbuildOptions,
13511
13565
  target: target || undefined,
13512
13566
  format: rollupToEsbuildFormatMap[format],
@@ -13851,7 +13905,7 @@ var fs$h = {};
13851
13905
 
13852
13906
  Object.defineProperty(fs$h, "__esModule", { value: true });
13853
13907
  fs$h.createDirentFromStats = void 0;
13854
- class DirentFromStats$1 {
13908
+ let DirentFromStats$1 = class DirentFromStats {
13855
13909
  constructor(name, stats) {
13856
13910
  this.name = name;
13857
13911
  this.isBlockDevice = stats.isBlockDevice.bind(stats);
@@ -13862,7 +13916,7 @@ class DirentFromStats$1 {
13862
13916
  this.isSocket = stats.isSocket.bind(stats);
13863
13917
  this.isSymbolicLink = stats.isSymbolicLink.bind(stats);
13864
13918
  }
13865
- }
13919
+ };
13866
13920
  function createDirentFromStats$1(name, stats) {
13867
13921
  return new DirentFromStats$1(name, stats);
13868
13922
  }
@@ -16573,7 +16627,7 @@ var fs$f = {};
16573
16627
 
16574
16628
  Object.defineProperty(settings$3, "__esModule", { value: true });
16575
16629
  const fs$e = fs$f;
16576
- class Settings$2 {
16630
+ let Settings$2 = class Settings {
16577
16631
  constructor(_options = {}) {
16578
16632
  this._options = _options;
16579
16633
  this.followSymbolicLink = this._getValue(this._options.followSymbolicLink, true);
@@ -16584,7 +16638,7 @@ class Settings$2 {
16584
16638
  _getValue(option, value) {
16585
16639
  return option !== null && option !== void 0 ? option : value;
16586
16640
  }
16587
- }
16641
+ };
16588
16642
  settings$3.default = Settings$2;
16589
16643
 
16590
16644
  Object.defineProperty(out$1, "__esModule", { value: true });
@@ -16928,7 +16982,7 @@ Object.defineProperty(settings$2, "__esModule", { value: true });
16928
16982
  const path$d = require$$0$4;
16929
16983
  const fsStat$3 = out$1;
16930
16984
  const fs$a = fs$b;
16931
- class Settings$1 {
16985
+ let Settings$1 = class Settings {
16932
16986
  constructor(_options = {}) {
16933
16987
  this._options = _options;
16934
16988
  this.followSymbolicLinks = this._getValue(this._options.followSymbolicLinks, false);
@@ -16945,7 +16999,7 @@ class Settings$1 {
16945
16999
  _getValue(option, value) {
16946
17000
  return option !== null && option !== void 0 ? option : value;
16947
17001
  }
16948
- }
17002
+ };
16949
17003
  settings$2.default = Settings$1;
16950
17004
 
16951
17005
  Object.defineProperty(out$2, "__esModule", { value: true });
@@ -17327,13 +17381,13 @@ var reader$1 = {};
17327
17381
 
17328
17382
  Object.defineProperty(reader$1, "__esModule", { value: true });
17329
17383
  const common$6 = common$7;
17330
- class Reader$1 {
17384
+ let Reader$1 = class Reader {
17331
17385
  constructor(_root, _settings) {
17332
17386
  this._root = _root;
17333
17387
  this._settings = _settings;
17334
17388
  this._root = common$6.replacePathSegmentSeparator(_root, _settings.pathSegmentSeparator);
17335
17389
  }
17336
- }
17390
+ };
17337
17391
  reader$1.default = Reader$1;
17338
17392
 
17339
17393
  Object.defineProperty(async$4, "__esModule", { value: true });
@@ -24826,7 +24880,7 @@ function fixFlowSeqItems(fc) {
24826
24880
  * }
24827
24881
  * ```
24828
24882
  */
24829
- class Parser$1 {
24883
+ let Parser$1 = class Parser {
24830
24884
  /**
24831
24885
  * @param onNewLine - If defined, called separately with the start position of
24832
24886
  * each new line (in `parse()`, including the start of input).
@@ -25654,7 +25708,7 @@ class Parser$1 {
25654
25708
  yield* this.pop();
25655
25709
  }
25656
25710
  }
25657
- }
25711
+ };
25658
25712
 
25659
25713
  function parseOptions(options) {
25660
25714
  const prettyErrors = options.prettyErrors !== false;
@@ -25784,7 +25838,7 @@ var YAML = {
25784
25838
 
25785
25839
  var browser$1 = {
25786
25840
  __proto__: null,
25787
- 'default': YAML,
25841
+ default: YAML,
25788
25842
  Composer: Composer,
25789
25843
  Document: Document,
25790
25844
  Schema: Schema,
@@ -32431,7 +32485,7 @@ function fileToDevUrl(id, config) {
32431
32485
  else {
32432
32486
  // outside of project root, use absolute fs path
32433
32487
  // (this is special handled by the serve static middleware
32434
- rtn = path$o.posix.join(FS_PREFIX + id);
32488
+ rtn = path$o.posix.join(FS_PREFIX, id);
32435
32489
  }
32436
32490
  const base = joinUrlSegments(config.server?.origin ?? '', config.base);
32437
32491
  return joinUrlSegments(base, rtn.replace(/^\//, ''));
@@ -32614,8 +32668,7 @@ async function fileToBuiltUrl(id, config, pluginContext, skipPublicCheck = false
32614
32668
  name,
32615
32669
  fileName: map.get(contentHash),
32616
32670
  type: 'asset',
32617
- source: content,
32618
- isAsset: true
32671
+ source: content
32619
32672
  });
32620
32673
  }
32621
32674
  url = `__VITE_ASSET__${contentHash}__${postfix ? `$_${postfix}__` : ``}`; // TODO_BASE
@@ -34288,7 +34341,7 @@ const externalTypes = [
34288
34341
  'tsx',
34289
34342
  ...KNOWN_ASSET_TYPES
34290
34343
  ];
34291
- function esbuildDepPlugin(qualified, exportsData, external, config, ssr) {
34344
+ function esbuildDepPlugin(qualified, external, config, ssr) {
34292
34345
  const { extensions } = getDepOptimizationConfig(config, ssr);
34293
34346
  // remove optimizable extensions from `externalTypes` list
34294
34347
  const allExternalTypes = extensions
@@ -36319,7 +36372,10 @@ function servePublicMiddleware(dir, headers) {
36319
36372
  if (isImportRequest(req.url) || isInternalRequest(req.url)) {
36320
36373
  return next();
36321
36374
  }
36322
- serve(req, res, next);
36375
+ if (shouldServe(req.url, dir)) {
36376
+ return serve(req, res, next);
36377
+ }
36378
+ next();
36323
36379
  };
36324
36380
  }
36325
36381
  function serveStaticMiddleware(dir, server) {
@@ -36448,6 +36504,8 @@ function renderRestrictedErrorHTML(msg) {
36448
36504
  `;
36449
36505
  }
36450
36506
 
36507
+ const ERR_LOAD_URL = 'ERR_LOAD_URL';
36508
+ const ERR_LOAD_PUBLIC_URL = 'ERR_LOAD_PUBLIC_URL';
36451
36509
  const debugLoad = createDebugger('vite:load');
36452
36510
  const debugTransform = createDebugger('vite:transform');
36453
36511
  const debugCache$1 = createDebugger('vite:cache');
@@ -36593,15 +36651,15 @@ async function loadAndTransform(id, url, server, options, timestamp) {
36593
36651
  }
36594
36652
  }
36595
36653
  if (code == null) {
36596
- if (checkPublicFile(url, config)) {
36597
- throw new Error(`Failed to load url ${url} (resolved id: ${id}). ` +
36598
- `This file is in /public and will be copied as-is during build without ` +
36654
+ const isPublicFile = checkPublicFile(url, config);
36655
+ const msg = isPublicFile
36656
+ ? `This file is in /public and will be copied as-is during build without ` +
36599
36657
  `going through the plugin transforms, and therefore should not be ` +
36600
- `imported from source code. It can only be referenced via HTML tags.`);
36601
- }
36602
- else {
36603
- return null;
36604
- }
36658
+ `imported from source code. It can only be referenced via HTML tags.`
36659
+ : `Does the file exist?`;
36660
+ const err = new Error(`Failed to load url ${url} (resolved id: ${id}). ${msg}`);
36661
+ err.code = isPublicFile ? ERR_LOAD_PUBLIC_URL : ERR_LOAD_URL;
36662
+ throw err;
36605
36663
  }
36606
36664
  // ensure module in graph after successful load
36607
36665
  const mod = await moduleGraph.ensureEntryFromUrl(url, ssr);
@@ -36803,9 +36861,7 @@ function importAnalysisPlugin(config) {
36803
36861
  : null;
36804
36862
  const toAbsoluteUrl = (url) => path$o.posix.resolve(path$o.posix.dirname(importerModule.url), url);
36805
36863
  const normalizeUrl = async (url, pos) => {
36806
- if (base !== '/' && url.startsWith(base)) {
36807
- url = url.replace(base, '/');
36808
- }
36864
+ url = stripBase(url, base);
36809
36865
  let importerFile = importer;
36810
36866
  const optimizeDeps = getDepOptimizationConfig(config, ssr);
36811
36867
  if (moduleListContains(optimizeDeps?.exclude, url)) {
@@ -36846,7 +36902,7 @@ function importAnalysisPlugin(config) {
36846
36902
  fs$l.existsSync(cleanUrl(resolved.id))) {
36847
36903
  // an optimized deps may not yet exists in the filesystem, or
36848
36904
  // a regular file exists but is out of root: rewrite to absolute /@fs/ paths
36849
- url = path$o.posix.join(FS_PREFIX + resolved.id);
36905
+ url = path$o.posix.join(FS_PREFIX, resolved.id);
36850
36906
  }
36851
36907
  else {
36852
36908
  url = resolved.id;
@@ -36893,8 +36949,8 @@ function importAnalysisPlugin(config) {
36893
36949
  e.pos = pos;
36894
36950
  throw e;
36895
36951
  }
36896
- // prepend base (dev base is guaranteed to have ending slash)
36897
- url = base + url.replace(/^\//, '');
36952
+ // prepend base
36953
+ url = joinUrlSegments(base, url);
36898
36954
  }
36899
36955
  return [url, resolved.id];
36900
36956
  };
@@ -37011,7 +37067,7 @@ function importAnalysisPlugin(config) {
37011
37067
  }
37012
37068
  // record for HMR import chain analysis
37013
37069
  // make sure to unwrap and normalize away base
37014
- const hmrUrl = unwrapId(url.replace(base, '/'));
37070
+ const hmrUrl = unwrapId(stripBase(url, base));
37015
37071
  importedUrls.add(hmrUrl);
37016
37072
  if (enablePartialAccept && importedBindings) {
37017
37073
  extractImportedBindings(resolvedId, source, imports[index], importedBindings);
@@ -37124,7 +37180,7 @@ function importAnalysisPlugin(config) {
37124
37180
  // These requests will also be registered in transformRequest to be awaited
37125
37181
  // by the deps optimizer
37126
37182
  if (config.server.preTransformRequests && staticImportedUrls.size) {
37127
- staticImportedUrls.forEach(({ url, id }) => {
37183
+ staticImportedUrls.forEach(({ url }) => {
37128
37184
  url = removeImportQuery(url);
37129
37185
  transformRequest(url, server, { ssr }).catch((e) => {
37130
37186
  if (e?.code === ERR_OUTDATED_OPTIMIZED_DEP) {
@@ -39596,7 +39652,7 @@ async function resolvePlugins(config, prePlugins, normalPlugins, postPlugins) {
39596
39652
  const isBuild = config.command === 'build';
39597
39653
  const isWatch = isBuild && !!config.build.watch;
39598
39654
  const buildPlugins = isBuild
39599
- ? (await Promise.resolve().then(function () { return build$1; })).resolveBuildPlugins(config)
39655
+ ? await (await Promise.resolve().then(function () { return build$1; })).resolveBuildPlugins(config)
39600
39656
  : { pre: [], post: [] };
39601
39657
  const { modulePreload } = config.build;
39602
39658
  return [
@@ -39915,6 +39971,7 @@ async function createPluginContainer(config, moduleGraph, watcher) {
39915
39971
  skip.add(this._activePlugin);
39916
39972
  }
39917
39973
  let out = await container.resolveId(id, importer, {
39974
+ assertions: options?.assertions,
39918
39975
  custom: options?.custom,
39919
39976
  isEntry: !!options?.isEntry,
39920
39977
  skip,
@@ -40150,6 +40207,7 @@ async function createPluginContainer(config, moduleGraph, watcher) {
40150
40207
  ? plugin.resolveId.handler
40151
40208
  : plugin.resolveId;
40152
40209
  const result = await handler.call(ctx, rawId, importer, {
40210
+ assertions: options?.assertions ?? {},
40153
40211
  custom: options?.custom,
40154
40212
  isEntry: !!options?.isEntry,
40155
40213
  ssr,
@@ -41451,7 +41509,6 @@ async function runOptimizeDeps(resolvedConfig, depsInfo, ssr = resolvedConfig.co
41451
41509
  // path.
41452
41510
  const flatIdDeps = {};
41453
41511
  const idToExports = {};
41454
- const flatIdToExports = {};
41455
41512
  const optimizeDeps = getDepOptimizationConfig(config, ssr);
41456
41513
  const { plugins: pluginsFromConfig = [], ...esbuildOptions } = optimizeDeps?.esbuildOptions ?? {};
41457
41514
  for (const id in depsInfo) {
@@ -41469,7 +41526,6 @@ async function runOptimizeDeps(resolvedConfig, depsInfo, ssr = resolvedConfig.co
41469
41526
  const flatId = flattenId(id);
41470
41527
  flatIdDeps[flatId] = src;
41471
41528
  idToExports[id] = exportsData;
41472
- flatIdToExports[flatId] = exportsData;
41473
41529
  }
41474
41530
  // esbuild automatically replaces process.env.NODE_ENV for platform 'browser'
41475
41531
  // In lib mode, we need to keep process.env.NODE_ENV untouched, so to at build
@@ -41501,7 +41557,7 @@ async function runOptimizeDeps(resolvedConfig, depsInfo, ssr = resolvedConfig.co
41501
41557
  if (external.length) {
41502
41558
  plugins.push(esbuildCjsExternalPlugin(external));
41503
41559
  }
41504
- plugins.push(esbuildDepPlugin(flatIdDeps, flatIdToExports, external, config, ssr));
41560
+ plugins.push(esbuildDepPlugin(flatIdDeps, external, config, ssr));
41505
41561
  const start = performance.now();
41506
41562
  const result = await build$3({
41507
41563
  absWorkingDir: process.cwd(),
@@ -41528,6 +41584,7 @@ async function runOptimizeDeps(resolvedConfig, depsInfo, ssr = resolvedConfig.co
41528
41584
  ignoreAnnotations: !isBuild,
41529
41585
  metafile: true,
41530
41586
  plugins,
41587
+ charset: 'utf8',
41531
41588
  ...esbuildOptions,
41532
41589
  supported: {
41533
41590
  'dynamic-import': true,
@@ -42535,7 +42592,7 @@ function traverseNodes(node, visitor) {
42535
42592
  }
42536
42593
  async function traverseHtml(html, filePath, visitor) {
42537
42594
  // lazy load compiler
42538
- const { parse } = await import('./dep-19c40c50.js');
42595
+ const { parse } = await import('./dep-adb60dd8.js');
42539
42596
  const ast = parse(html, {
42540
42597
  sourceCodeLocationInfo: true,
42541
42598
  onParseError: (e) => {
@@ -43329,7 +43386,7 @@ function cssPlugin(config) {
43329
43386
  for (const file of deps) {
43330
43387
  depModules.add(isCSSRequest(file)
43331
43388
  ? moduleGraph.createFileOnlyEntry(file)
43332
- : await moduleGraph.ensureEntryFromUrl((await fileToUrl(file, config, this)).replace((config.server?.origin ?? '') + devBase, '/'), ssr));
43389
+ : await moduleGraph.ensureEntryFromUrl(stripBase(await fileToUrl(file, config, this), (config.server?.origin ?? '') + devBase), ssr));
43333
43390
  }
43334
43391
  moduleGraph.updateModuleInfo(thisModule, depModules, null,
43335
43392
  // The root CSS proxy module is self-accepting and should not
@@ -43533,7 +43590,7 @@ function cssPostPlugin(config) {
43533
43590
  if (config.build.cssCodeSplit) {
43534
43591
  if (isPureCssChunk) {
43535
43592
  // this is a shared CSS-only chunk that is empty.
43536
- pureCssChunks.add(chunk.fileName);
43593
+ pureCssChunks.add(chunk);
43537
43594
  }
43538
43595
  if (opts.format === 'es' || opts.format === 'cjs') {
43539
43596
  const cssAssetName = chunk.facadeModuleId
@@ -43600,7 +43657,21 @@ function cssPostPlugin(config) {
43600
43657
  }
43601
43658
  // remove empty css chunks and their imports
43602
43659
  if (pureCssChunks.size) {
43603
- const emptyChunkFiles = [...pureCssChunks]
43660
+ // map each pure css chunk (rendered chunk) to it's corresponding bundle
43661
+ // chunk. we check that by comparing the `moduleIds` as they have different
43662
+ // filenames (rendered chunk has the !~{XXX}~ placeholder)
43663
+ const pureCssChunkNames = [];
43664
+ for (const pureCssChunk of pureCssChunks) {
43665
+ for (const key in bundle) {
43666
+ const bundleChunk = bundle[key];
43667
+ if (bundleChunk.type === 'chunk' &&
43668
+ arrayEqual(bundleChunk.moduleIds, pureCssChunk.moduleIds)) {
43669
+ pureCssChunkNames.push(key);
43670
+ break;
43671
+ }
43672
+ }
43673
+ }
43674
+ const emptyChunkFiles = pureCssChunkNames
43604
43675
  .map((file) => path$o.basename(file))
43605
43676
  .join('|')
43606
43677
  .replace(/\./g, '\\.');
@@ -43614,7 +43685,7 @@ function cssPostPlugin(config) {
43614
43685
  // and also register the emitted CSS files under the importer
43615
43686
  // chunks instead.
43616
43687
  chunk.imports = chunk.imports.filter((file) => {
43617
- if (pureCssChunks.has(file)) {
43688
+ if (pureCssChunkNames.includes(file)) {
43618
43689
  const { viteMetadata: { importedCss } } = bundle[file];
43619
43690
  importedCss.forEach((file) => chunk.viteMetadata.importedCss.add(file));
43620
43691
  return false;
@@ -43627,7 +43698,7 @@ function cssPostPlugin(config) {
43627
43698
  }
43628
43699
  }
43629
43700
  const removedPureCssFiles = removedPureCssFilesCache.get(config);
43630
- pureCssChunks.forEach((fileName) => {
43701
+ pureCssChunkNames.forEach((fileName) => {
43631
43702
  removedPureCssFiles.set(fileName, bundle[fileName]);
43632
43703
  delete bundle[fileName];
43633
43704
  });
@@ -43758,7 +43829,7 @@ async function compileCSS(id, code, config, urlReplacer) {
43758
43829
  }
43759
43830
  const postcssPlugins = postcssConfig && postcssConfig.plugins ? postcssConfig.plugins.slice() : [];
43760
43831
  if (needInlineImport) {
43761
- postcssPlugins.unshift((await import('./dep-9deb2354.js').then(function (n) { return n.i; })).default({
43832
+ postcssPlugins.unshift((await import('./dep-4ec4968a.js').then(function (n) { return n.i; })).default({
43762
43833
  async resolve(id, basedir) {
43763
43834
  const publicFile = checkPublicFile(id, config);
43764
43835
  if (publicFile) {
@@ -43782,7 +43853,7 @@ async function compileCSS(id, code, config, urlReplacer) {
43782
43853
  }));
43783
43854
  }
43784
43855
  if (isModule) {
43785
- postcssPlugins.unshift((await import('./dep-7591464a.js').then(function (n) { return n.i; })).default({
43856
+ postcssPlugins.unshift((await import('./dep-6d760e82.js').then(function (n) { return n.i; })).default({
43786
43857
  ...modulesOptions,
43787
43858
  // TODO: convert null to undefined (`null` should be removed from `CSSModulesOptions.localsConvention`)
43788
43859
  localsConvention: modulesOptions?.localsConvention ?? undefined,
@@ -45070,10 +45141,16 @@ function loadEnv(mode, envDir, prefixes = 'VITE_') {
45070
45141
  }));
45071
45142
  }));
45072
45143
  // let environment variables use each other
45073
- main({
45074
- parsed,
45144
+ const expandParsed = main({
45145
+ parsed: {
45146
+ ...process.env,
45147
+ ...parsed
45148
+ },
45075
45149
  // prevent process.env mutation
45076
45150
  ignoreProcessEnv: true
45151
+ }).parsed;
45152
+ Object.keys(parsed).forEach((key) => {
45153
+ parsed[key] = expandParsed[key];
45077
45154
  });
45078
45155
  // only keys that start with prefix are exposed to client
45079
45156
  for (const [key, value] of Object.entries(parsed)) {
@@ -45188,11 +45265,12 @@ function resolveBuildOptions(raw, logger) {
45188
45265
  }
45189
45266
  return resolved;
45190
45267
  }
45191
- function resolveBuildPlugins(config) {
45268
+ async function resolveBuildPlugins(config) {
45192
45269
  const options = config.build;
45193
45270
  const { commonjsOptions } = options;
45194
45271
  const usePluginCommonjs = !Array.isArray(commonjsOptions?.include) ||
45195
45272
  commonjsOptions?.include.length !== 0;
45273
+ const rollupOptionsPlugins = options.rollupOptions.plugins;
45196
45274
  return {
45197
45275
  pre: [
45198
45276
  completeSystemWrapPlugin(),
@@ -45200,9 +45278,9 @@ function resolveBuildPlugins(config) {
45200
45278
  watchPackageDataPlugin(config),
45201
45279
  ...(usePluginCommonjs ? [commonjs(options.commonjsOptions)] : []),
45202
45280
  dataURIPlugin(),
45203
- ...(options.rollupOptions.plugins
45204
- ? options.rollupOptions.plugins.filter(Boolean)
45205
- : [])
45281
+ ...(await asyncFlatten(Array.isArray(rollupOptionsPlugins)
45282
+ ? rollupOptionsPlugins
45283
+ : [rollupOptionsPlugins])).filter(Boolean)
45206
45284
  ],
45207
45285
  post: [
45208
45286
  buildImportAnalysisPlugin(config),
@@ -45482,29 +45560,30 @@ function resolveLibFilename(libOptions, format, entryName, root, extension) {
45482
45560
  }
45483
45561
  function resolveBuildOutputs(outputs, libOptions, logger) {
45484
45562
  if (libOptions) {
45485
- const hasMultipleEntries = typeof libOptions.entry !== 'string' &&
45563
+ const libHasMultipleEntries = typeof libOptions.entry !== 'string' &&
45486
45564
  Object.values(libOptions.entry).length > 1;
45487
- const formats = libOptions.formats || (hasMultipleEntries ? ['es', 'cjs'] : ['es', 'umd']);
45488
- if (formats.includes('umd') || formats.includes('iife')) {
45489
- if (hasMultipleEntries) {
45490
- throw new Error(`Multiple entry points are not supported when output formats include "umd" or "iife".`);
45491
- }
45492
- if (!libOptions.name) {
45493
- throw new Error(`Option "build.lib.name" is required when output formats ` +
45494
- `include "umd" or "iife".`);
45565
+ const libFormats = libOptions.formats ||
45566
+ (libHasMultipleEntries ? ['es', 'cjs'] : ['es', 'umd']);
45567
+ if (!Array.isArray(outputs)) {
45568
+ if (libFormats.includes('umd') || libFormats.includes('iife')) {
45569
+ if (libHasMultipleEntries) {
45570
+ throw new Error('Multiple entry points are not supported when output formats include "umd" or "iife".');
45571
+ }
45572
+ if (!libOptions.name) {
45573
+ throw new Error('Option "build.lib.name" is required when output formats include "umd" or "iife".');
45574
+ }
45495
45575
  }
45576
+ return libFormats.map((format) => ({ ...outputs, format }));
45496
45577
  }
45497
- if (!outputs) {
45498
- return formats.map((format) => ({ format }));
45499
- }
45500
- else if (!Array.isArray(outputs)) {
45501
- return formats.map((format) => ({ ...outputs, format }));
45502
- }
45503
- else if (libOptions.formats) {
45504
- // user explicitly specifying own output array
45505
- logger.warn(picocolors.exports.yellow(`"build.lib.formats" will be ignored because ` +
45506
- `"build.rollupOptions.output" is already an array format`));
45578
+ // By this point, we know "outputs" is an Array.
45579
+ if (libOptions.formats) {
45580
+ logger.warn(picocolors.exports.yellow('"build.lib.formats" will be ignored because "build.rollupOptions.output" is already an array format.'));
45507
45581
  }
45582
+ outputs.forEach((output) => {
45583
+ if (['umd', 'iife'].includes(output.format) && !output.name) {
45584
+ throw new Error('Entries in "build.rollupOptions.output" must specify "name" when the format is "umd" or "iife".');
45585
+ }
45586
+ });
45508
45587
  }
45509
45588
  return outputs;
45510
45589
  }
@@ -45515,11 +45594,11 @@ const dynamicImportWarningIgnoreList = [
45515
45594
  ];
45516
45595
  function onRollupWarning(warning, warn, config) {
45517
45596
  if (warning.code === 'UNRESOLVED_IMPORT') {
45518
- const id = warning.source;
45519
- const importer = warning.importer;
45597
+ const id = warning.id;
45598
+ const exporter = warning.exporter;
45520
45599
  // throw unless it's commonjs external...
45521
- if (!importer || !/\?commonjs-external$/.test(importer)) {
45522
- throw new Error(`[vite]: Rollup failed to resolve import "${id}" from "${importer}".\n` +
45600
+ if (!id || !/\?commonjs-external$/.test(id)) {
45601
+ throw new Error(`[vite]: Rollup failed to resolve import "${exporter}" from "${id}".\n` +
45523
45602
  `This is most likely unintended because it can break your application at runtime.\n` +
45524
45603
  `If you do want to externalize this module explicitly add it to\n` +
45525
45604
  `\`build.rollupOptions.external\``);
@@ -45735,7 +45814,7 @@ function toOutputFilePathWithoutRuntime(filename, type, hostId, hostType, config
45735
45814
  return toRelative(filename, hostId);
45736
45815
  }
45737
45816
  else {
45738
- return config.base + filename;
45817
+ return joinUrlSegments(config.base, filename);
45739
45818
  }
45740
45819
  }
45741
45820
  const toOutputFilePathInCss = toOutputFilePathWithoutRuntime;
@@ -49602,7 +49681,7 @@ const setFsWatchFileListener = (path, fullPath, options, handlers) => {
49602
49681
  /**
49603
49682
  * @mixin
49604
49683
  */
49605
- class NodeFsHandler$1 {
49684
+ let NodeFsHandler$1 = class NodeFsHandler {
49606
49685
 
49607
49686
  /**
49608
49687
  * @param {import("../index").FSWatcher} fsW
@@ -49958,7 +50037,7 @@ async _addToNodeFs(path, initialAdd, priorWh, depth, target) {
49958
50037
  }
49959
50038
  }
49960
50039
 
49961
- }
50040
+ };
49962
50041
 
49963
50042
  var nodefsHandler = NodeFsHandler$1;
49964
50043
 
@@ -50176,7 +50255,7 @@ const sameTypes = (info, stats) => (
50176
50255
  /**
50177
50256
  * @mixin
50178
50257
  */
50179
- class FsEventsHandler$1 {
50258
+ let FsEventsHandler$1 = class FsEventsHandler {
50180
50259
 
50181
50260
  /**
50182
50261
  * @param {import('../index').FSWatcher} fsw
@@ -50482,7 +50561,7 @@ async _addToFsEvents(path, transform, forceAdd, priorDepth) {
50482
50561
  }
50483
50562
  }
50484
50563
 
50485
- }
50564
+ };
50486
50565
 
50487
50566
  fseventsHandler.exports = FsEventsHandler$1;
50488
50567
  fseventsHandler.exports.canUse = canUse;
@@ -53309,7 +53388,7 @@ const kRun = Symbol('kRun');
53309
53388
  * A very simple job queue with adjustable concurrency. Adapted from
53310
53389
  * https://github.com/STRML/async-limiter
53311
53390
  */
53312
- class Limiter$1 {
53391
+ let Limiter$1 = class Limiter {
53313
53392
  /**
53314
53393
  * Creates a new `Limiter`.
53315
53394
  *
@@ -53352,7 +53431,7 @@ class Limiter$1 {
53352
53431
  job(this[kDone]);
53353
53432
  }
53354
53433
  }
53355
- }
53434
+ };
53356
53435
 
53357
53436
  var limiter = Limiter$1;
53358
53437
 
@@ -53381,7 +53460,7 @@ let zlibLimiter;
53381
53460
  /**
53382
53461
  * permessage-deflate implementation.
53383
53462
  */
53384
- class PerMessageDeflate$4 {
53463
+ let PerMessageDeflate$4 = class PerMessageDeflate {
53385
53464
  /**
53386
53465
  * Creates a PerMessageDeflate instance.
53387
53466
  *
@@ -53811,7 +53890,7 @@ class PerMessageDeflate$4 {
53811
53890
  callback(null, data);
53812
53891
  });
53813
53892
  }
53814
- }
53893
+ };
53815
53894
 
53816
53895
  var permessageDeflate = PerMessageDeflate$4;
53817
53896
 
@@ -54016,7 +54095,7 @@ const INFLATING = 5;
54016
54095
  *
54017
54096
  * @extends Writable
54018
54097
  */
54019
- class Receiver$1 extends Writable$1 {
54098
+ let Receiver$1 = class Receiver extends Writable$1 {
54020
54099
  /**
54021
54100
  * Creates a Receiver instance.
54022
54101
  *
@@ -54582,7 +54661,7 @@ class Receiver$1 extends Writable$1 {
54582
54661
 
54583
54662
  this._state = GET_INFO;
54584
54663
  }
54585
- }
54664
+ };
54586
54665
 
54587
54666
  var receiver = Receiver$1;
54588
54667
 
@@ -54623,7 +54702,7 @@ const maskBuffer = Buffer.alloc(4);
54623
54702
  /**
54624
54703
  * HyBi Sender implementation.
54625
54704
  */
54626
- class Sender$1 {
54705
+ let Sender$1 = class Sender {
54627
54706
  /**
54628
54707
  * Creates a Sender instance.
54629
54708
  *
@@ -55079,7 +55158,7 @@ class Sender$1 {
55079
55158
  this._socket.write(list[0], cb);
55080
55159
  }
55081
55160
  }
55082
- }
55161
+ };
55083
55162
 
55084
55163
  var sender = Sender$1;
55085
55164
 
@@ -55261,7 +55340,7 @@ const EventTarget = {
55261
55340
  * Register an event listener.
55262
55341
  *
55263
55342
  * @param {String} type A string representing the event type to listen for
55264
- * @param {Function} listener The listener to add
55343
+ * @param {(Function|Object)} handler The listener to add
55265
55344
  * @param {Object} [options] An options object specifies characteristics about
55266
55345
  * the event listener
55267
55346
  * @param {Boolean} [options.once=false] A `Boolean` indicating that the
@@ -55269,7 +55348,17 @@ const EventTarget = {
55269
55348
  * the listener would be automatically removed when invoked.
55270
55349
  * @public
55271
55350
  */
55272
- addEventListener(type, listener, options = {}) {
55351
+ addEventListener(type, handler, options = {}) {
55352
+ for (const listener of this.listeners(type)) {
55353
+ if (
55354
+ !options[kForOnEventAttribute$1] &&
55355
+ listener[kListener$1] === handler &&
55356
+ !listener[kForOnEventAttribute$1]
55357
+ ) {
55358
+ return;
55359
+ }
55360
+ }
55361
+
55273
55362
  let wrapper;
55274
55363
 
55275
55364
  if (type === 'message') {
@@ -55279,7 +55368,7 @@ const EventTarget = {
55279
55368
  });
55280
55369
 
55281
55370
  event[kTarget] = this;
55282
- listener.call(this, event);
55371
+ callListener(handler, this, event);
55283
55372
  };
55284
55373
  } else if (type === 'close') {
55285
55374
  wrapper = function onClose(code, message) {
@@ -55290,7 +55379,7 @@ const EventTarget = {
55290
55379
  });
55291
55380
 
55292
55381
  event[kTarget] = this;
55293
- listener.call(this, event);
55382
+ callListener(handler, this, event);
55294
55383
  };
55295
55384
  } else if (type === 'error') {
55296
55385
  wrapper = function onError(error) {
@@ -55300,21 +55389,21 @@ const EventTarget = {
55300
55389
  });
55301
55390
 
55302
55391
  event[kTarget] = this;
55303
- listener.call(this, event);
55392
+ callListener(handler, this, event);
55304
55393
  };
55305
55394
  } else if (type === 'open') {
55306
55395
  wrapper = function onOpen() {
55307
55396
  const event = new Event('open');
55308
55397
 
55309
55398
  event[kTarget] = this;
55310
- listener.call(this, event);
55399
+ callListener(handler, this, event);
55311
55400
  };
55312
55401
  } else {
55313
55402
  return;
55314
55403
  }
55315
55404
 
55316
55405
  wrapper[kForOnEventAttribute$1] = !!options[kForOnEventAttribute$1];
55317
- wrapper[kListener$1] = listener;
55406
+ wrapper[kListener$1] = handler;
55318
55407
 
55319
55408
  if (options.once) {
55320
55409
  this.once(type, wrapper);
@@ -55327,7 +55416,7 @@ const EventTarget = {
55327
55416
  * Remove an event listener.
55328
55417
  *
55329
55418
  * @param {String} type A string representing the event type to remove
55330
- * @param {Function} handler The listener to remove
55419
+ * @param {(Function|Object)} handler The listener to remove
55331
55420
  * @public
55332
55421
  */
55333
55422
  removeEventListener(type, handler) {
@@ -55348,6 +55437,22 @@ var eventTarget = {
55348
55437
  MessageEvent
55349
55438
  };
55350
55439
 
55440
+ /**
55441
+ * Call an event listener
55442
+ *
55443
+ * @param {(Function|Object)} listener The listener to call
55444
+ * @param {*} thisArg The value to use as `this`` when calling the listener
55445
+ * @param {Event} event The event to pass to the listener
55446
+ * @private
55447
+ */
55448
+ function callListener(listener, thisArg, event) {
55449
+ if (typeof listener === 'object' && listener.handleEvent) {
55450
+ listener.handleEvent.call(listener, event);
55451
+ } else {
55452
+ listener.call(thisArg, event);
55453
+ }
55454
+ }
55455
+
55351
55456
  const { tokenChars: tokenChars$1 } = validation.exports;
55352
55457
 
55353
55458
  /**
@@ -55590,7 +55695,7 @@ const subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
55590
55695
  *
55591
55696
  * @extends EventEmitter
55592
55697
  */
55593
- class WebSocket$1 extends EventEmitter$1 {
55698
+ let WebSocket$1 = class WebSocket extends EventEmitter$1 {
55594
55699
  /**
55595
55700
  * Create a new `WebSocket`.
55596
55701
  *
@@ -56034,7 +56139,7 @@ class WebSocket$1 extends EventEmitter$1 {
56034
56139
  this._socket.destroy();
56035
56140
  }
56036
56141
  }
56037
- }
56142
+ };
56038
56143
 
56039
56144
  /**
56040
56145
  * @constant {Number} CONNECTING
@@ -57641,18 +57746,18 @@ function createWebSocketServer(server, config, httpsOptions) {
57641
57746
  };
57642
57747
  }
57643
57748
 
57644
- // this middleware is only active when (config.base !== '/')
57749
+ // this middleware is only active when (base !== '/')
57645
57750
  function baseMiddleware({ config }) {
57646
- const devBase = config.base.endsWith('/') ? config.base : config.base + '/';
57647
57751
  // Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...`
57648
57752
  return function viteBaseMiddleware(req, res, next) {
57649
57753
  const url = req.url;
57650
57754
  const parsed = new URL(url, 'http://vitejs.dev');
57651
57755
  const path = parsed.pathname || '/';
57652
- if (path.startsWith(devBase)) {
57756
+ const base = config.rawBase;
57757
+ if (path.startsWith(base)) {
57653
57758
  // rewrite url to remove base. this ensures that other middleware does
57654
57759
  // not need to consider base being prepended or not
57655
- req.url = url.replace(devBase, '/');
57760
+ req.url = stripBase(url, base);
57656
57761
  return next();
57657
57762
  }
57658
57763
  // skip redirect and error fallback on middleware mode, #4057
@@ -57662,18 +57767,18 @@ function baseMiddleware({ config }) {
57662
57767
  if (path === '/' || path === '/index.html') {
57663
57768
  // redirect root visit to based url with search and hash
57664
57769
  res.writeHead(302, {
57665
- Location: config.base + (parsed.search || '') + (parsed.hash || '')
57770
+ Location: base + (parsed.search || '') + (parsed.hash || '')
57666
57771
  });
57667
57772
  res.end();
57668
57773
  return;
57669
57774
  }
57670
57775
  else if (req.headers.accept?.includes('text/html')) {
57671
57776
  // non-based page visit
57672
- const redirectPath = joinUrlSegments(config.base, url);
57777
+ const redirectPath = url + '/' !== base ? joinUrlSegments(base, url) : base;
57673
57778
  res.writeHead(404, {
57674
57779
  'Content-Type': 'text/html'
57675
57780
  });
57676
- res.end(`The server is configured with a public base URL of ${config.base} - ` +
57781
+ res.end(`The server is configured with a public base URL of ${base} - ` +
57677
57782
  `did you mean to visit <a href="${redirectPath}">${redirectPath}</a> instead?`);
57678
57783
  return;
57679
57784
  }
@@ -60118,6 +60223,10 @@ function transformMiddleware(server) {
60118
60223
  // error but a normal part of the missing deps discovery flow
60119
60224
  return;
60120
60225
  }
60226
+ if (e?.code === ERR_LOAD_URL) {
60227
+ // Let other middleware handle if we can't load the url via transformRequest
60228
+ return next();
60229
+ }
60121
60230
  return next(e);
60122
60231
  }
60123
60232
  next();
@@ -61909,28 +62018,12 @@ async function startServer(server, inlinePort, isRestart = false) {
61909
62018
  const port = inlinePort ?? options.port ?? 5173;
61910
62019
  const hostname = await resolveHostname(options.host);
61911
62020
  const protocol = options.https ? 'https' : 'http';
61912
- const info = server.config.logger.info;
61913
62021
  const serverPort = await httpServerStart(httpServer, {
61914
62022
  port,
61915
62023
  strictPort: options.strictPort,
61916
62024
  host: hostname.host,
61917
62025
  logger: server.config.logger
61918
62026
  });
61919
- // @ts-ignore
61920
- const profileSession = global.__vite_profile_session;
61921
- if (profileSession) {
61922
- profileSession.post('Profiler.stop', (err, { profile }) => {
61923
- // Write profile to disk, upload, etc.
61924
- if (!err) {
61925
- const outPath = path$o.resolve('./vite-profile.cpuprofile');
61926
- fs$l.writeFileSync(outPath, JSON.stringify(profile));
61927
- info(picocolors.exports.yellow(` CPU profile written to ${picocolors.exports.white(picocolors.exports.dim(outPath))}\n`));
61928
- }
61929
- else {
61930
- throw err;
61931
- }
61932
- });
61933
- }
61934
62027
  if (options.open && !isRestart) {
61935
62028
  const path = typeof options.open === 'string' ? options.open : server.config.base;
61936
62029
  openBrowser(path.startsWith('http')
@@ -62225,7 +62318,7 @@ async function preview(inlineConfig = {}) {
62225
62318
  // static assets
62226
62319
  const distDir = path$o.resolve(config.root, config.build.outDir);
62227
62320
  const headers = config.preview.headers;
62228
- app.use(previewBase, sirv(distDir, {
62321
+ const assetServer = sirv(distDir, {
62229
62322
  etag: true,
62230
62323
  dev: true,
62231
62324
  single: config.appType === 'spa',
@@ -62236,7 +62329,13 @@ async function preview(inlineConfig = {}) {
62236
62329
  }
62237
62330
  }
62238
62331
  }
62239
- }));
62332
+ });
62333
+ app.use(previewBase, async (req, res, next) => {
62334
+ if (shouldServe(req.url, distDir)) {
62335
+ return assetServer(req, res, next);
62336
+ }
62337
+ next();
62338
+ });
62240
62339
  // apply post server hooks from plugins
62241
62340
  postHooks.forEach((fn) => fn && fn());
62242
62341
  const options = config.preview;
@@ -62340,11 +62439,6 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development')
62340
62439
  configFileDependencies = loadResult.dependencies;
62341
62440
  }
62342
62441
  }
62343
- // Define logger
62344
- const logger = createLogger(config.logLevel, {
62345
- allowClearScreen: config.clearScreen,
62346
- customLogger: config.customLogger
62347
- });
62348
62442
  // user config may provide an alternative mode. But --mode has a higher priority
62349
62443
  mode = inlineConfig.mode || config.mode || mode;
62350
62444
  configEnv.mode = mode;
@@ -62380,6 +62474,11 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development')
62380
62474
  config.build ?? (config.build = {});
62381
62475
  config.build.commonjsOptions = { include: [] };
62382
62476
  }
62477
+ // Define logger
62478
+ const logger = createLogger(config.logLevel, {
62479
+ allowClearScreen: config.clearScreen,
62480
+ customLogger: config.customLogger
62481
+ });
62383
62482
  // resolve root
62384
62483
  const resolvedRoot = normalizePath$3(config.root ? path$o.resolve(config.root) : process.cwd());
62385
62484
  const clientAlias = [
@@ -62473,7 +62572,10 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development')
62473
62572
  ]
62474
62573
  }));
62475
62574
  }
62476
- return (await container.resolveId(id, importer, { ssr, scan: options?.scan }))?.id;
62575
+ return (await container.resolveId(id, importer, {
62576
+ ssr,
62577
+ scan: options?.scan
62578
+ }))?.id;
62477
62579
  };
62478
62580
  };
62479
62581
  const { publicDir } = config;
@@ -62507,7 +62609,8 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development')
62507
62609
  configFileDependencies: configFileDependencies.map((name) => normalizePath$3(path$o.resolve(name))),
62508
62610
  inlineConfig,
62509
62611
  root: resolvedRoot,
62510
- base: resolvedBase,
62612
+ base: resolvedBase.endsWith('/') ? resolvedBase : resolvedBase + '/',
62613
+ rawBase: resolvedBase,
62511
62614
  resolve: resolveOptions,
62512
62615
  publicDir: resolvedPublicDir,
62513
62616
  cacheDir,
@@ -62629,28 +62732,22 @@ function resolveBaseUrl(base = '/', isBuild, logger) {
62629
62732
  if (base.startsWith('.')) {
62630
62733
  logger.warn(picocolors.exports.yellow(picocolors.exports.bold(`(!) invalid "base" option: ${base}. The value can only be an absolute ` +
62631
62734
  `URL, ./, or an empty string.`)));
62632
- base = '/';
62735
+ return '/';
62633
62736
  }
62634
- // external URL
62635
- if (isExternalUrl(base)) {
62636
- if (!isBuild) {
62637
- // get base from full url during dev
62638
- const parsed = parse$j(base);
62639
- base = parsed.pathname || '/';
62640
- }
62737
+ // external URL flag
62738
+ const isExternal = isExternalUrl(base);
62739
+ // no leading slash warn
62740
+ if (!isExternal && !base.startsWith('/')) {
62741
+ logger.warn(picocolors.exports.yellow(picocolors.exports.bold(`(!) "base" option should start with a slash.`)));
62641
62742
  }
62642
- else {
62743
+ // parse base when command is serve or base is not External URL
62744
+ if (!isBuild || !isExternal) {
62745
+ base = new URL(base, 'http://vitejs.dev').pathname;
62643
62746
  // ensure leading slash
62644
62747
  if (!base.startsWith('/')) {
62645
- logger.warn(picocolors.exports.yellow(picocolors.exports.bold(`(!) "base" option should start with a slash.`)));
62646
62748
  base = '/' + base;
62647
62749
  }
62648
62750
  }
62649
- // ensure ending slash
62650
- if (!base.endsWith('/')) {
62651
- logger.warn(picocolors.exports.yellow(picocolors.exports.bold(`(!) "base" option should end with a slash.`)));
62652
- base += '/';
62653
- }
62654
62751
  return base;
62655
62752
  }
62656
62753
  function sortUserPlugins(plugins) {