Alright, I was able to figure this out, but it still seems like there must be a simpler way.
In a separate project directory, I ran npm init
to create the bare minimum package.json
(my Transformer had no other dependencies, you'll have to include them here if yours does).
I then added my Transformer class as follows in the "main" class I specified in package.json
:
class Transformer {
static mimeTypes () {
return ['application/myformat']
}
parse (source) {
let parsed = // whatever parsing is necessary
return {
parsed
}
}
extendNodeType ({ graphql }) {
return {
// custom GraphQL fields for transformed node
}
}
}
module.exports = Transformer
Next, from the new directory, run npm link
, then from your main project directory (that will be using the Transformer), run npm link your-transformer-project-name
.
Finally, you should add the new plugin project to your main project's package.json
in the devDependencies
section:
...
"devDependencies": {
"gridsome-transformer-myformat": "^1.0.0"
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…