emersonbottero / vitepress-plugin-mermaid

Add mermaid support for Vitepress
MIT License
87 stars 20 forks source link

fix: can't write alias properly #54

Open camera-2018 opened 1 year ago

camera-2018 commented 1 year ago

When I write config.vite.resolve.alias in withMermaid

export default withMermaid({
  vite: {
      resolve: {
        alias: [
          {
            find: /^.*\/VPSwitchAppearance\.vue$/,
            replacement: fileURLToPath(
              new URL('./components/CustomSwitchAppearance.vue', import.meta.url)
            )
          }
        ]
      }
    }
})

I've found they don't work. Because what I write will be turned into ☹

"0":{
  find: /^.*\/VPSwitchAppearance\.vue$/,
    replacement: fileURLToPath(
      new URL('./components/CustomSwitchAppearance.vue', import.meta.url)
  )
}

So I've tried to fix them

config.vite.resolve.alias = [
    ...config.vite.resolve.alias,
    {
      find: "dayjs/plugin/advancedFormat.js",
      replacement: "dayjs/esm/plugin/advancedFormat"
    },
    {
      find: "dayjs/plugin/customParseFormat.js",
      replacement: "dayjs/esm/plugin/customParseFormat"
    },
    {
      find: "dayjs/plugin/isoWeek.js",
      replacement: "dayjs/esm/plugin/isoWeek"
    },
    {
      find: "cytoscape/dist/cytoscape.umd.js",
      replacement: "cytoscape/dist/cytoscape.esm.js"
    },
  ];

But they haven't been tested much by me, so please review them carefully!

emersonbottero commented 1 year ago

The problem is that are several ways to pass the information..

resolve.alias Type:Record<string, string> | Array<{ find: string | RegExp, replacement: string, customResolver?: ResolverFunction | ResolverObject }> Will be passed to @rollup/plugin-alias as its entries option. Can either be an object, or an array of { find, replacement, customResolver } pairs.

I'll try to think of contemplating them all.