Skip to content

Commit 6db42f0

Browse files
committed
perf: replace object literals with json when generating client codes
1 parent de6b43d commit 6db42f0

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

packages/@vuepress/core/src/app/prepare/preparePageData.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ if (import.meta.hot) {
2020
*/
2121
export const preparePageData = async (app: App, page: Page): Promise<void> => {
2222
// page data file content
23-
let content = `export const data = ${JSON.stringify(page.data, null, 2)}\n`
23+
let content = `export const data = JSON.parse(${JSON.stringify(
24+
JSON.stringify(page.data)
25+
)})
26+
`
2427

2528
// inject HMR code
2629
if (app.env.isDev) {

packages/@vuepress/core/src/app/prepare/prepareSiteData.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ if (import.meta.hot) {
2020
*/
2121
export const prepareSiteData = async (app: App): Promise<void> => {
2222
let content = `\
23-
export const siteData = ${JSON.stringify(app.siteData, null, 2)}
23+
export const siteData = JSON.parse(${JSON.stringify(
24+
JSON.stringify(app.siteData)
25+
)})
2426
`
2527

2628
// inject HMR code

packages/@vuepress/plugin-theme-data/src/node/prepareThemeData.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ export const prepareThemeData = async (
2222
): Promise<void> => {
2323
// theme data file content
2424
let content = `\
25-
export const themeData = ${JSON.stringify(themeData, null, 2)}
25+
export const themeData = JSON.parse(${JSON.stringify(
26+
JSON.stringify(themeData)
27+
)})
2628
`
2729

2830
// inject HMR code

0 commit comments

Comments
 (0)