Skip to content

Commit f5f38f9

Browse files
fix: load VuePress config file #12
1 parent d414dc9 commit f5f38f9

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

packages/vuepress-plugin-export-pdf-v2/src/serverApp.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
import { join } from "node:path";
22
import { createRequire } from "node:module";
3-
import { createDevApp, defaultTheme, viteBundler } from "vuepress";
3+
import {
4+
createDevApp,
5+
defaultTheme,
6+
loadUserConfig,
7+
resolveUserConfigConventionalPath as resolveVuePressConfig,
8+
transformUserConfigToPlugin,
9+
viteBundler,
10+
} from "vuepress";
411
import debug from "debug";
512
import type { CommandOptions } from "@condorhero/vuepress-plugin-export-pdf-core";
6-
import { checkEnv, generatePdf, loadModule, resolveUserConfigConventionalPath, resolveUserConfigPath, timeTransformer } from "@condorhero/vuepress-plugin-export-pdf-core";
13+
import {
14+
checkEnv, generatePdf,
15+
loadModule,
16+
resolveUserConfigConventionalPath,
17+
resolveUserConfigPath,
18+
timeTransformer,
19+
} from "@condorhero/vuepress-plugin-export-pdf-core";
720

821
import pkg from "../package.json";
922
import type { UserConfig } from ".";
@@ -45,8 +58,8 @@ export const serverApp = async (dir = "docs", commandOptions: CommandOptions = {
4558
devDebug("userConfig: %O", userConfig);
4659

4760
const {
48-
theme = defaultTheme(),
49-
bundler = viteBundler(),
61+
theme,
62+
bundler,
5063
sorter,
5164
puppeteerLaunchOptions,
5265
pdfOptions,
@@ -58,14 +71,20 @@ export const serverApp = async (dir = "docs", commandOptions: CommandOptions = {
5871
outlineContainerSelector,
5972
} = userConfig;
6073

74+
const { userConfig: vuePressConfig } = await loadUserConfig(resolveVuePressConfig(sourceDir));
75+
6176
const devApp = createDevApp({
6277
source: sourceDir,
63-
bundler,
64-
theme,
78+
...vuePressConfig,
79+
bundler: bundler || vuePressConfig.bundler || viteBundler(),
80+
theme: theme || vuePressConfig.theme || defaultTheme(),
6581
host: "localhost",
6682
port: 8714,
6783
});
6884

85+
// use user-config plugin
86+
devApp.use(transformUserConfigToPlugin(userConfig, sourceDir));
87+
6988
// initialize and prepare
7089
await devApp.init();
7190
await devApp.prepare();

0 commit comments

Comments
 (0)