(编写插件的文档非常稀少.)
目标
创建一个插件来向页面添加页眉。
的尝试
创建了一个插件,遵循指导原则和一个示例插件(大概可以.)做类似的事。
THE ISSUE
插件不会加载。
config.js
plugins: [
[
'vuepress-plugin-headertags',
{ headerTags: ["<script src='https://cdn.jsdelivr.net/npm/netlify-identity-widget@1.5.2/build/netlify-identity-widget.min.js'></script>"]}
]
],(在这种情况下,标记就是我要插入的。
插件index.js
const { path } = require('path')
// was: const { path } = require('@vuepress/shared-utils')
// dunno. No documentation on this...
// got the current version from the 'default-theme' code
module.exports = (options) => ({
define () {
return {
headerTags: options.headerTags || []
}
},
enhanceAppFiles () {
return [path.resolve(__dirname, 'enhanceAppFile.js')]
},
globalUIComponents: ['HeaderTags']
})插件安装--我把它作为vuepress-plugin-headertags发布给npm,然后用以下方式安装:
yarn add -D vuepress-plugin-headertags
以下是相关的package.json内容:
{
"name": "vuepress-netlifycms",
"version": "0.0.0",
"scripts": {
"dev": "vuepress dev",
"build": "vuepress build",
"debug": "node --nolazy --inspect=9229 /home/rickb/.yarn/bin/vuepress build"
},
"devDependencies": {
"vuepress": "^0.14.8",
"vuepress-plugin-headertags": "^1.0.3"
},
"dependencies": {}
}VUEPRESS安装
我从git中克隆了vuepress repo,并做了一个纱线链接,这使得它在全球范围内都可以使用。有了它,我可以通过“调试”脚本在调试器中跟踪它。
跟踪
我遵循调试器中的VP源代码,并在resolvePathPackage()中使用moduleResolver.js。传入路径不正确:
/home/(...)/VuePress-NetlifyCMS/vuepress-plugin-headertags
它应该是:
/home/(...)/VuePress-NetlifyCMS/node_modules/vuepress-plugin-headertags
无论如何,即使在“正常化”过程之后,它也不会解决。
更多的眼睛
我需要更多的目光来帮助我解决这个问题。该项目已经在github上推出,名为“rickbsgu/VuePress-NetlifyCMS.git”。如果您安装,插件将位于项目目录下的‘node_node/vuepress- plugin标签’。
任何想法都值得赞赏
发布于 2020-04-10 15:50:11
现在起作用了。两个问题:
运行/调试的
const { path } = require('path')更改为const { path } = require('@vuepress/shared-utils'). --这是我的文档问题--我没有看到任何文档。谢谢@Sun Haoran让我找对地方。
https://stackoverflow.com/questions/61130390
复制相似问题