英文:
markdown-it-textual-uml and vitepress-sidebar coexistence possible?
问题
I am trying to use both markdown-it-textual-uml
and vitepress-sidebar
plugins in my project.
我正在尝试在我的项目中同时使用 markdown-it-textual-uml
和 vitepress-sidebar
插件。
I started including markdown-it-textual-uml
and all was well.
我开始包括 markdown-it-textual-uml
,一切都正常。
Then I tried to add vitepress-sidebar
and apparently, being an ESM module, it needs "type": "module"
in package.json
. Unfortunately this broke markdown-it-textual-uml
which now complains about:
然后我尝试添加 vitepress-sidebar
,显然,由于它是一个 ESM 模块,它需要在 package.json
中设置 "type": "module"
。不幸的是,这破坏了 markdown-it-textual-uml
,现在它报错:
Error: Dynamic require of "file:///home/mcon/projects/@@SITE/node_modules/markdown-it-textual-uml/src/index.js" is not supported
错误:不支持动态请求 "file:///home/mcon/projects/@@SITE/node_modules/markdown-it-textual-uml/src/index.js"
My tentative and very partial config.ts
is:
我的初步且非常部分的 config.ts
如下:
import { defineConfig } from 'vitepress'
import { generateSidebar } from 'vitepress-sidebar'
export default defineConfig({
title: "Mauro Condarelli personal site",
description: "A random collection of unrelated projects",
themeConfig: {
nav: [
{ text: 'Home', link: '/' },
{ text: 'Examples', link: '/markdown-examples' }
],
sidebar: generateSidebar({
// use defaults
}),
socialLinks: [
{ icon: 'github', link: 'https://github.com/vuejs/vitepress' }
]
},
markdown : {
config: (md) => {
md.use(require("markdown-it-textual-uml"));
md.use(require("markdown-it-deflist"));
}
}
})
while my almost-default package.json
is:
而我的几乎默认的 package.json
如下:
{
"type": "module",
"scripts": {
"docs:dev": "vitepress dev vitepress",
"docs:build": "vitepress build vitepress",
"docs:preview": "vitepress preview vitepress"
},
"dependencies": {
"markdown-it-deflist": "^2.1.0",
"markdown-it-textual-uml": "^0.12.0"
},
"devDependencies": {
"@types/node": "^20.3.2",
"vitepress-sidebar": "^1.8.1"
}
}
How can I fix this (if at all possible)?
如何修复这个问题(如果可能的话)?
Note: while I'm an experienced programmer I'm not deep in JavaScript and friends, I'm just learning and I still don't really grok it yet.
注意:虽然我是一位有经验的程序员,但我对 JavaScript 等内容不是很精通,我正在学习,但我仍然不太理解它。
英文:
I am trying to use both markdown-it-textual-uml
and vitepress-sidebar
plugins in my project.
I started including markdown-it-textual-uml
and all was well.
Then I tried to add vitepress-sidebar
and apparently, being an ESM module, it needs "type": "module"
in package.json
. Unfortunately this broke markdown-it-textual-uml
which now complains about:
Error: Dynamic require of "file:///home/mcon/projects/@@SITE/node_modules/markdown-it-textual-uml/src/index.js" is not supported
My tentative and very partial config.ts
is:
import { defineConfig } from 'vitepress'
import { generateSidebar } from 'vitepress-sidebar'
export default defineConfig({
title: "Mauro Condarelli personal site",
description: "A random collection of unrelated projects",
themeConfig: {
nav: [
{ text: 'Home', link: '/' },
{ text: 'Examples', link: '/markdown-examples' }
],
sidebar: generateSidebar({
// use defaults
}),
socialLinks: [
{ icon: 'github', link: 'https://github.com/vuejs/vitepress' }
]
},
markdown : {
config: (md) => {
md.use(require("markdown-it-textual-uml"));
md.use(require("markdown-it-deflist"));
}
}
})
while my almost-default package.json
is:
{
"type": "module",
"scripts": {
"docs:dev": "vitepress dev vitepress",
"docs:build": "vitepress build vitepress",
"docs:preview": "vitepress preview vitepress"
},
"dependencies": {
"markdown-it-deflist": "^2.1.0",
"markdown-it-textual-uml": "^0.12.0"
},
"devDependencies": {
"@types/node": "^20.3.2",
"vitepress-sidebar": "^1.8.1"
}
}
How can I fix this (if at all possible)?
Note: while I'm an experienced programmer I'm not deep in JavaScript and friends, I'm just learning and I still don't really grock it yet.
答案1
得分: 0
为什么你需要它?只需导入它:
import { defineConfig } from 'vitepress';
// @ts-ignore
import markdownItTextualUml from 'markdown-it-textual-uml';
export default defineConfig({
markdown: {
config(md) {
md.use(markdownItTextualUml);
},
},
})
即使在你的 package.json 中设置了 type: module
,这也能正常工作。
演示: https://stackblitz.com/edit/vite-i24rds
英文:
Why are you requiring it? Just import it:
import { defineConfig } from 'vitepress';
// @ts-ignore
import markdownItTextualUml from 'markdown-it-textual-uml';
export default defineConfig({
markdown: {
config(md) {
md.use(markdownItTextualUml);
},
},
})
This would work even if you set type: module
in your package.json.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论