vitepress 0.20.5 → 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/client.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ // re-export vite client types
2
+ // with strict installers like pnpm, user won't be able to reference vite/client
3
+ // in project root
4
+ /// <reference types="vite/client" />
package/dist/node/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var serve = require('./serve-f83deb60.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-f83deb60.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;
@@ -36431,6 +36432,81 @@ const getHeadMetaContent = (head, name) => {
36431
36432
  return meta && meta[1].content;
36432
36433
  };
36433
36434
 
36435
+ const loaderMatch = /\.data\.(j|t)s$/;
36436
+ let server;
36437
+ const idToLoaderModulesMap = Object.create(null);
36438
+ let idToPendingPromiseMap = Object.create(null);
36439
+ let isBuild = false;
36440
+ const staticDataPlugin = {
36441
+ name: "vitepress:data",
36442
+ configResolved(config) {
36443
+ isBuild = config.command === "build";
36444
+ },
36445
+ configureServer(_server) {
36446
+ server = _server;
36447
+ },
36448
+ async load(id) {
36449
+ var _a;
36450
+ if (loaderMatch.test(id)) {
36451
+ let _resolve;
36452
+ if (isBuild) {
36453
+ if (idToPendingPromiseMap[id]) {
36454
+ return idToPendingPromiseMap[id];
36455
+ }
36456
+ idToPendingPromiseMap[id] = new Promise((r) => {
36457
+ _resolve = r;
36458
+ });
36459
+ }
36460
+ const base = path$p.dirname(id);
36461
+ let pattern;
36462
+ let loader;
36463
+ const existing = idToLoaderModulesMap[id];
36464
+ if (existing) {
36465
+ ({ pattern, loader } = existing);
36466
+ } else {
36467
+ const loaderModule = (_a = await vite.loadConfigFromFile({}, id)) == null ? void 0 : _a.config;
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
+ });
36473
+ }
36474
+ loader = loaderModule.load;
36475
+ }
36476
+ const data = await loader();
36477
+ if (server) {
36478
+ idToLoaderModulesMap[id] = { base, pattern, loader };
36479
+ }
36480
+ const result = `export const data = JSON.parse(${JSON.stringify(JSON.stringify(data))})`;
36481
+ if (_resolve)
36482
+ _resolve(result);
36483
+ return result;
36484
+ }
36485
+ },
36486
+ transform(_code, id) {
36487
+ if (server && loaderMatch.test(id)) {
36488
+ const { base, pattern } = idToLoaderModulesMap[id];
36489
+ server._globImporters[id] = {
36490
+ module: server.moduleGraph.getModuleById(id),
36491
+ importGlobs: pattern == null ? void 0 : pattern.map((pattern2) => ({ base, pattern: pattern2 }))
36492
+ };
36493
+ }
36494
+ return null;
36495
+ },
36496
+ handleHotUpdate(ctx) {
36497
+ for (const id in idToLoaderModulesMap) {
36498
+ const { base, pattern } = idToLoaderModulesMap[id];
36499
+ const isLoaderFile = vite.normalizePath(ctx.file) === id;
36500
+ if (isLoaderFile) {
36501
+ delete idToLoaderModulesMap[id];
36502
+ }
36503
+ if (isLoaderFile || pattern && micromatch_1.isMatch(path$p.relative(base, ctx.file), pattern)) {
36504
+ ctx.modules.push(server.moduleGraph.getModuleById(id));
36505
+ }
36506
+ }
36507
+ }
36508
+ };
36509
+
36434
36510
  var __defProp$1 = Object.defineProperty;
36435
36511
  var __defProps$1 = Object.defineProperties;
36436
36512
  var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
@@ -36624,7 +36700,12 @@ function createVitePressPlugin(root, siteConfig, ssr = false, pageToHashMap, cli
36624
36700
  }
36625
36701
  }
36626
36702
  };
36627
- return [vitePressPlugin, vuePlugin, ...(userViteConfig == null ? void 0 : userViteConfig.plugins) || []];
36703
+ return [
36704
+ vitePressPlugin,
36705
+ vuePlugin,
36706
+ ...(userViteConfig == null ? void 0 : userViteConfig.plugins) || [],
36707
+ staticDataPlugin
36708
+ ];
36628
36709
  }
36629
36710
 
36630
36711
  async function createServer(root = process.cwd(), serverOptions = {}) {
@@ -39961,13 +40042,25 @@ async function renderPage(config, page, result, appChunk, cssChunk, pageToHashMa
39961
40042
  const pageClientJsFileName = `assets/${pageName}.${pageHash}.lean.js`;
39962
40043
  const { __pageData } = require(path__default["default"].join(config.tempDir, pageServerJsFileName));
39963
40044
  const pageData = JSON.parse(__pageData);
39964
- const preloadLinks = (config.mpa ? appChunk ? [appChunk.fileName] : [] : result && appChunk ? [
39965
- ...resolvePageImports(config, page, result, appChunk),
39966
- pageClientJsFileName,
39967
- appChunk.fileName
39968
- ] : []).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) => {
39969
40059
  return `<link rel="modulepreload" href="${siteData.base}${file}">`;
39970
40060
  }).join("\n ");
40061
+ const prefetchLinkString = prefetchLinks.map((file) => {
40062
+ return `<link rel="prefetch" href="${siteData.base}${file}">`;
40063
+ }).join("\n ");
39971
40064
  const stylesheetLink = cssChunk ? `<link rel="stylesheet" href="${siteData.base}${cssChunk.fileName}">` : "";
39972
40065
  const title = pageData.title && pageData.title !== "Home" ? `${pageData.title} | ${siteData.title}` : siteData.title;
39973
40066
  const head = addSocialTags(title, ...siteData.head, ...filterOutHeadDescription(pageData.frontmatter.head));
@@ -39992,7 +40085,8 @@ async function renderPage(config, page, result, appChunk, cssChunk, pageToHashMa
39992
40085
  <title>${title}</title>
39993
40086
  <meta name="description" content="${pageData.description || siteData.description}">
39994
40087
  ${stylesheetLink}
39995
- ${preloadLinks}
40088
+ ${preloadLinksString}
40089
+ ${prefetchLinkString}
39996
40090
  ${renderHead(head)}
39997
40091
  </head>
39998
40092
  <body>
@@ -40006,15 +40100,15 @@ async function renderPage(config, page, result, appChunk, cssChunk, pageToHashMa
40006
40100
  await lib$1.ensureDir(path__default["default"].dirname(htmlFileName));
40007
40101
  await lib$1.writeFile(htmlFileName, html);
40008
40102
  }
40009
- function resolvePageImports(config, page, result, indexChunk) {
40103
+ function resolvePageImports(config, page, result, appChunk) {
40010
40104
  const srcPath = vite.normalizePath(lib$1.realpathSync(path__default["default"].resolve(config.srcDir, page)));
40011
40105
  const pageChunk = result.output.find((chunk) => chunk.type === "chunk" && chunk.facadeModuleId === srcPath);
40012
- return Array.from(new Set([
40013
- ...indexChunk.imports,
40014
- ...indexChunk.dynamicImports,
40106
+ return [
40107
+ ...appChunk.imports,
40108
+ ...appChunk.dynamicImports,
40015
40109
  ...pageChunk.imports,
40016
40110
  ...pageChunk.dynamicImports
40017
- ]));
40111
+ ];
40018
40112
  }
40019
40113
  function renderHead(head) {
40020
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.5",
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",
@@ -10,7 +10,8 @@
10
10
  "files": [
11
11
  "bin",
12
12
  "dist",
13
- "types"
13
+ "types",
14
+ "client.d.ts"
14
15
  ],
15
16
  "engines": {
16
17
  "node": ">=12.0.0"
@@ -63,6 +64,7 @@
63
64
  "@types/koa-static": "^4.0.1",
64
65
  "@types/lru-cache": "^5.1.0",
65
66
  "@types/markdown-it": "^12.0.1",
67
+ "@types/micromatch": "^4.0.2",
66
68
  "@types/node": "^15.6.1",
67
69
  "@types/polka": "^0.5.3",
68
70
  "chalk": "^4.1.1",
@@ -75,6 +77,7 @@
75
77
  "esbuild": "^0.13.4",
76
78
  "escape-html": "^1.0.3",
77
79
  "execa": "^5.0.0",
80
+ "fast-glob": "^3.2.7",
78
81
  "fs-extra": "^10.0.0",
79
82
  "globby": "^11.0.3",
80
83
  "gray-matter": "^4.0.3",
@@ -87,6 +90,7 @@
87
90
  "markdown-it-container": "^3.0.0",
88
91
  "markdown-it-emoji": "^2.0.0",
89
92
  "markdown-it-table-of-contents": "^0.5.2",
93
+ "micromatch": "^4.0.4",
90
94
  "minimist": "^1.2.5",
91
95
  "npm-run-all": "^4.1.5",
92
96
  "ora": "^5.4.0",