mermaid/packages/mermaid/src/docs/vite.config.ts

56 lines
1.5 KiB
TypeScript
Raw Normal View History

2022-10-15 05:50:11 +02:00
import { defineConfig, searchForWorkspaceRoot } from 'vite';
2022-09-24 04:33:24 +02:00
import path from 'path';
2022-10-18 00:32:47 +02:00
// @ts-ignore: still in alpha
2022-09-25 04:24:48 +02:00
import { SearchPlugin } from 'vitepress-plugin-search';
2022-09-24 04:33:24 +02:00
const virtualModuleId = 'virtual:mermaid-config';
const resolvedVirtualModuleId = '\0' + virtualModuleId;
2022-09-22 00:40:49 +02:00
export default defineConfig({
2022-09-24 04:33:24 +02:00
plugins: [
2022-09-25 04:24:48 +02:00
SearchPlugin(),
2022-09-24 04:33:24 +02:00
{
2022-09-25 04:24:48 +02:00
// TODO: will be fixed in the next vitepress release.
2022-09-24 04:33:24 +02:00
name: 'fix-virtual',
async resolveId(id) {
if (id === virtualModuleId) {
return resolvedVirtualModuleId;
}
},
async load(this, id) {
if (id === resolvedVirtualModuleId) {
return `export default ${JSON.stringify({
securityLevel: 'loose',
startOnLoad: false,
})};`;
}
},
},
],
2022-09-22 00:40:49 +02:00
resolve: {
alias: {
2022-10-18 00:32:47 +02:00
mermaid: path.join(__dirname, '../../dist/mermaid.esm.min.mjs'), // Use this one to build
2022-11-14 17:36:26 +01:00
'@mermaid-js/mermaid-mindmap': path.join(
__dirname,
'../../../mermaid-mindmap/dist/mermaid-mindmap.esm.min.mjs'
), // Use this one to build
// '@mermaid-js/mermaid-timeline': path.join(
// __dirname,
// '../../../mermaid-timeline/dist/mermaid-timeline.esm.min.mjs'
// ),
2022-09-22 00:40:49 +02:00
},
},
2022-10-15 05:50:11 +02:00
server: {
fs: {
allow: [
// search up for workspace root
searchForWorkspaceRoot(process.cwd()),
// Allow serving files from one level up to the project root
path.join(__dirname, '..'),
],
},
},
2022-09-22 00:40:49 +02:00
});