message: fix(md-enhance): fix playground vue preset ssr
diff: @@ -15,6 +15,10 @@ const VUE_SUPPORTED_EXTENSIONS = [
  "json",
  ];
  +const DEFAULT_VUE_CDN = "https://sfc.vuejs.org/vue.runtime.esm-browser.js";
  +const DEFAULT_VUE_SR_CDN =
  + "https://sfc.vuejs.org/server-renderer.esm-browser.js";
  +
  export const getVuePlaygroundPreset = (
  options: VuePresetPlaygroundOptions = {}
  ): PlaygroundOptions => ({
  @@ -30,25 +34,9 @@ export const getVuePlaygroundPreset = (
  ...localSettings,
  };
  - return {
  - key,
  - title,
  - link: encodeURIComponent(
  - `${settings.service}#${
  - // dev flag
  - settings.dev ? "__DEV__" : ""
  - }${
  - // ssr flag
  - settings.ssr ? "__SSR__" : ""
  - }${
  - // code base64
  - Buffer.from(
  - JSON.stringify(
  - Object.fromEntries(
  + const fileInfo = Object.fromEntries(
  Object.entries(files)
  - .filter(([, { ext }]) =>
  - VUE_SUPPORTED_EXTENSIONS.includes(ext)
  - )
  + .filter(([, { ext }]) => VUE_SUPPORTED_EXTENSIONS.includes(ext))
  .map(([key, { content }]) => {
  if (key === "import-map.json") {
  const importMap = <
  @@ -62,16 +50,15 @@ export const getVuePlaygroundPreset = (
  key,
  JSON.stringify(
  deepMerge(
  - {},
  {
  - // insure vue exists and vue/server-render exists when ssr is on
  imports: {
  - vue: "https://sfc.vuejs.org/vue.runtime.esm-browser.js",
  + // insure vue exists
  + vue: DEFAULT_VUE_CDN,
  + // insure vue/server-renderer exists
  ...(settings.ssr
  ? {
  // eslint-disable-next-line @typescript-eslint/naming-convention
  - "vue/server-renderer":
  - "https://sfc.vuejs.org/server-renderer.esm-browser.js",
  + "vue/server-renderer": DEFAULT_VUE_SR_CDN,
  }
  : {}),
  },
  @@ -84,9 +71,34 @@ export const getVuePlaygroundPreset = (
  return [key, content];
  })
  - )
  - )
  - ).toString("base64")
  + );
  +
  + if (settings.ssr && !fileInfo["import-map.json"])
  + fileInfo["import-map.json"] = JSON.stringify(
  + {
  + imports: {
  + vue: DEFAULT_VUE_CDN,
  + // eslint-disable-next-line @typescript-eslint/naming-convention
  + "vue/server-renderer": DEFAULT_VUE_SR_CDN,
  + },
  + },
  + null,
  + 2
  + );
  +
  + return {
  + key,
  + title,
  + link: encodeURIComponent(
  + `${settings.service}#${
  + // dev flag
  + settings.dev ? "__DEV__" : ""
  + }${
  + // ssr flag
  + settings.ssr ? "__SSR__" : ""
  + }${
  + // code base64
  + Buffer.from(JSON.stringify(fileInfo)).toString("base64")
  }`
  ),
  };
  