Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need a quick Docusaurus V2 example of developing a plugin. #1928

Closed
goodlux opened this issue Nov 1, 2019 · 6 comments · Fixed by #2051
Closed

Need a quick Docusaurus V2 example of developing a plugin. #1928

goodlux opened this issue Nov 1, 2019 · 6 comments · Fixed by #2051
Labels
documentation The issue is related to the documentation of Docusaurus help wanted Asking for outside help and/or contributions to this particular issue or PR.

Comments

@goodlux
Copy link

goodlux commented Nov 1, 2019

📚 Documentation

Complete noob here, trying to write a simple plugin for Docusarus v2.

Trying to use these docs to reach that end:

https://v2.docusaurus.io/docs/advanced-plugins

I realize this doc is a WIP at this stage, but it is a bit of a mish-mash, and I'm having trouble trying to instantiate and use a local plugin after installing. I've tried everything and now my eyes are bleeding.

Would be really helpful to have a super easy example of a one-function plugin that does something easy like read and write a file, or even print something to the javascript console. I'm happy to write this doc if someone can get me started with a simple code sample.

The sample here appears to be a complete plugin scaffold:

https://v2.docusaurus.io/docs/lifecycle-apis#example

But again, having trouble understanding where this code is actually called in the build process after running :

npm start

Thanks!

Have you read the Contributing Guidelines on issues?

Yes

@wgao19
Copy link
Contributor

wgao19 commented Nov 3, 2019

Hi @goodlux what kind of plugins are you trying to write?

For plugins that perform a single task that does not participate in the static site's build step, you can take a look at the gtag plugin.

If you hope to write a plugin like docs or blog, i.e., the kind that parses content into pages, it can be slightly more complex. But docusaurus-plugin-content-pages is a relatively simple example.

@endiliey endiliey added 2.x help wanted Asking for outside help and/or contributions to this particular issue or PR. labels Nov 6, 2019
@endiliey
Copy link
Contributor

endiliey commented Nov 6, 2019

Another simpler example is https://github.com/facebook/docusaurus/blob/master/packages/docusaurus-plugin-ideal-image/src/index.js

It tries to modify webpack config. and it provides a theme component. Much much simpler than pages plugin (i think)

Help on documentation is appreciated

@endiliey endiliey added the documentation The issue is related to the documentation of Docusaurus label Nov 13, 2019
@vjpr
Copy link

vjpr commented Jun 8, 2020

Would be nice to have a boilerplate with all the TypeScript tooling setup, such that you can npm link to it or use it in a monorepo:

packages
  docusaurus-app
  docusaurus-plugin

@slorber
Copy link
Collaborator

slorber commented Jun 9, 2020

@vjpr you don't need a monorepo setup to handle your own plugins. If they are small and only useful for your site you can use a local plugin.

https://v2.docusaurus.io/docs/using-plugins/#installing-a-plugin

I think this is good enough for most sites, not sure we want to maintain a monorepo setup boilerplate. Maybe the init boilerplate could include a local plugin.

About TS, not all D2 users are frontend developers, so it's probably not a good idea to include anything related to TS by default.

@vjpr
Copy link

vjpr commented Jun 9, 2020

About TS, not all D2 users are frontend developers, so it's probably not a good idea to include anything related to TS by default.

For new users the auto-complete from TypeScript would be useful.

@slorber
Copy link
Collaborator

slorber commented Jun 9, 2020

One thing that we could do is bootstrap new projects with an empty JS plugin with all the lifecycles as noop.

For TS users, we could annotate the plugins JS files with JS docs comment? Need to check that, but maybe the IDE's would understand the syntax and provide autocomplete?

https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation The issue is related to the documentation of Docusaurus help wanted Asking for outside help and/or contributions to this particular issue or PR.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants