vitepress 0.20.8 → 0.20.9

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/node/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var serve = require('./serve-13371594.js');
3
+ var serve = require('./serve-61783397.js');
4
4
  require('fs');
5
5
  require('path');
6
6
  require('url');
@@ -83,7 +83,7 @@ export declare interface ServeOptions {
83
83
  port?: number;
84
84
  }
85
85
 
86
- export declare interface SiteConfig<ThemeConfig = any> {
86
+ export declare interface SiteConfig<ThemeConfig = any> extends Pick<UserConfig, 'markdown' | 'vue' | 'vite' | 'shouldPreload' | 'mpa'> {
87
87
  root: string;
88
88
  srcDir: string;
89
89
  site: SiteData<ThemeConfig>;
@@ -93,10 +93,6 @@ export declare interface SiteConfig<ThemeConfig = any> {
93
93
  tempDir: string;
94
94
  alias: AliasOptions;
95
95
  pages: string[];
96
- markdown: MarkdownOptions | undefined;
97
- vue: Options | undefined;
98
- vite: UserConfig_2 | undefined;
99
- mpa: boolean;
100
96
  }
101
97
 
102
98
  export declare interface SiteData<ThemeConfig = any> {
@@ -153,6 +149,7 @@ export declare interface UserConfig<ThemeConfig = any> {
153
149
  vite?: UserConfig_2;
154
150
  srcDir?: string;
155
151
  srcExclude?: string[];
152
+ shouldPreload?: (link: string, page: string) => boolean;
156
153
  /**
157
154
  * Enable MPA / zero-JS mode
158
155
  * @experimental
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var serve = require('./serve-13371594.js');
5
+ var serve = require('./serve-61783397.js');
6
6
  require('vite');
7
7
  require('readline');
8
8
  require('assert');
@@ -13372,6 +13372,7 @@ async function resolveConfig(root = process.cwd(), command = "serve", mode = "de
13372
13372
  alias: resolveAliases(themeDir),
13373
13373
  vue: userConfig.vue,
13374
13374
  vite: userConfig.vite,
13375
+ shouldPreload: userConfig.shouldPreload,
13375
13376
  mpa: !!userConfig.mpa
13376
13377
  };
13377
13378
  return config;
@@ -36464,9 +36465,11 @@ const staticDataPlugin = {
36464
36465
  ({ pattern, loader } = existing);
36465
36466
  } else {
36466
36467
  const loaderModule = (_a = await vite.loadConfigFromFile({}, id)) == null ? void 0 : _a.config;
36467
- pattern = loaderModule.watch;
36468
- if (pattern && pattern.startsWith("./")) {
36469
- pattern = pattern.slice(2);
36468
+ pattern = typeof loaderModule.watch === "string" ? [loaderModule.watch] : loaderModule.watch;
36469
+ if (pattern) {
36470
+ pattern = pattern.map((p) => {
36471
+ return p.startsWith("./") ? p.slice(2) : p;
36472
+ });
36470
36473
  }
36471
36474
  loader = loaderModule.load;
36472
36475
  }
@@ -36485,7 +36488,7 @@ const staticDataPlugin = {
36485
36488
  const { base, pattern } = idToLoaderModulesMap[id];
36486
36489
  server._globImporters[id] = {
36487
36490
  module: server.moduleGraph.getModuleById(id),
36488
- importGlobs: [{ base, pattern }]
36491
+ importGlobs: pattern == null ? void 0 : pattern.map((pattern2) => ({ base, pattern: pattern2 }))
36489
36492
  };
36490
36493
  }
36491
36494
  return null;
@@ -40039,13 +40042,25 @@ async function renderPage(config, page, result, appChunk, cssChunk, pageToHashMa
40039
40042
  const pageClientJsFileName = `assets/${pageName}.${pageHash}.lean.js`;
40040
40043
  const { __pageData } = require(path__default["default"].join(config.tempDir, pageServerJsFileName));
40041
40044
  const pageData = JSON.parse(__pageData);
40042
- const preloadLinks = (config.mpa ? appChunk ? [appChunk.fileName] : [] : result && appChunk ? [
40043
- ...resolvePageImports(config, page, result, appChunk),
40044
- pageClientJsFileName,
40045
- appChunk.fileName
40046
- ] : []).map((file) => {
40045
+ let preloadLinks = config.mpa ? appChunk ? [appChunk.fileName] : [] : result && appChunk ? [
40046
+ ...new Set([
40047
+ ...resolvePageImports(config, page, result, appChunk),
40048
+ pageClientJsFileName,
40049
+ appChunk.fileName
40050
+ ])
40051
+ ] : [];
40052
+ let prefetchLinks = [];
40053
+ const { shouldPreload } = config;
40054
+ if (shouldPreload) {
40055
+ prefetchLinks = preloadLinks.filter((link) => !shouldPreload(link, page));
40056
+ preloadLinks = preloadLinks.filter((link) => shouldPreload(link, page));
40057
+ }
40058
+ const preloadLinksString = preloadLinks.map((file) => {
40047
40059
  return `<link rel="modulepreload" href="${siteData.base}${file}">`;
40048
40060
  }).join("\n ");
40061
+ const prefetchLinkString = prefetchLinks.map((file) => {
40062
+ return `<link rel="prefetch" href="${siteData.base}${file}">`;
40063
+ }).join("\n ");
40049
40064
  const stylesheetLink = cssChunk ? `<link rel="stylesheet" href="${siteData.base}${cssChunk.fileName}">` : "";
40050
40065
  const title = pageData.title && pageData.title !== "Home" ? `${pageData.title} | ${siteData.title}` : siteData.title;
40051
40066
  const head = addSocialTags(title, ...siteData.head, ...filterOutHeadDescription(pageData.frontmatter.head));
@@ -40070,7 +40085,8 @@ async function renderPage(config, page, result, appChunk, cssChunk, pageToHashMa
40070
40085
  <title>${title}</title>
40071
40086
  <meta name="description" content="${pageData.description || siteData.description}">
40072
40087
  ${stylesheetLink}
40073
- ${preloadLinks}
40088
+ ${preloadLinksString}
40089
+ ${prefetchLinkString}
40074
40090
  ${renderHead(head)}
40075
40091
  </head>
40076
40092
  <body>
@@ -40084,15 +40100,15 @@ async function renderPage(config, page, result, appChunk, cssChunk, pageToHashMa
40084
40100
  await lib$1.ensureDir(path__default["default"].dirname(htmlFileName));
40085
40101
  await lib$1.writeFile(htmlFileName, html);
40086
40102
  }
40087
- function resolvePageImports(config, page, result, indexChunk) {
40103
+ function resolvePageImports(config, page, result, appChunk) {
40088
40104
  const srcPath = vite.normalizePath(lib$1.realpathSync(path__default["default"].resolve(config.srcDir, page)));
40089
40105
  const pageChunk = result.output.find((chunk) => chunk.type === "chunk" && chunk.facadeModuleId === srcPath);
40090
- return Array.from(new Set([
40091
- ...indexChunk.imports,
40092
- ...indexChunk.dynamicImports,
40106
+ return [
40107
+ ...appChunk.imports,
40108
+ ...appChunk.dynamicImports,
40093
40109
  ...pageChunk.imports,
40094
40110
  ...pageChunk.dynamicImports
40095
- ]));
40111
+ ];
40096
40112
  }
40097
40113
  function renderHead(head) {
40098
40114
  return head.map(([tag, attrs = {}, innerHTML = ""]) => {
@@ -83,7 +83,7 @@ export declare interface ServeOptions {
83
83
  port?: number;
84
84
  }
85
85
 
86
- export declare interface SiteConfig<ThemeConfig = any> {
86
+ export declare interface SiteConfig<ThemeConfig = any> extends Pick<UserConfig, 'markdown' | 'vue' | 'vite' | 'shouldPreload' | 'mpa'> {
87
87
  root: string;
88
88
  srcDir: string;
89
89
  site: SiteData<ThemeConfig>;
@@ -93,10 +93,6 @@ export declare interface SiteConfig<ThemeConfig = any> {
93
93
  tempDir: string;
94
94
  alias: AliasOptions;
95
95
  pages: string[];
96
- markdown: MarkdownOptions | undefined;
97
- vue: Options | undefined;
98
- vite: UserConfig_2 | undefined;
99
- mpa: boolean;
100
96
  }
101
97
 
102
98
  export declare interface SiteData<ThemeConfig = any> {
@@ -153,6 +149,7 @@ export declare interface UserConfig<ThemeConfig = any> {
153
149
  vite?: UserConfig_2;
154
150
  srcDir?: string;
155
151
  srcExclude?: string[];
152
+ shouldPreload?: (link: string, page: string) => boolean;
156
153
  /**
157
154
  * Enable MPA / zero-JS mode
158
155
  * @experimental
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitepress",
3
- "version": "0.20.8",
3
+ "version": "0.20.9",
4
4
  "description": "Vite & Vue powered static site generator",
5
5
  "main": "dist/node/index.js",
6
6
  "typings": "types/index.d.ts",