test02/node_modules/@vuepress/plugin-theme-data/lib/node/prepareThemeData.js
罗佳鸿 6aa1ebe342
Some checks are pending
部署文档 / deploy-gh-pages (push) Waiting to run
first commit
2024-08-13 10:11:19 +08:00

26 lines
658 B
JavaScript

const HMR_CODE = `
if (import.meta.webpackHot) {
import.meta.webpackHot.accept()
if (__VUE_HMR_RUNTIME__.updateThemeData) {
__VUE_HMR_RUNTIME__.updateThemeData(themeData)
}
}
if (import.meta.hot) {
import.meta.hot.accept(({ themeData }) => {
__VUE_HMR_RUNTIME__.updateThemeData(themeData)
})
}
`;
export const prepareThemeData = async (app, themeData) => {
// theme data file content
let content = `\
export const themeData = JSON.parse(${JSON.stringify(JSON.stringify(themeData))})
`;
// inject HMR code
if (app.env.isDev) {
content += HMR_CODE;
}
await app.writeTemp('internal/themeData.js', content);
};