Skip to content

Configure Vite plugins

Word count
1198 words
Reading time
8 minutes

Deprecating the locales field of GitChangelogMarkdownSection plugin options

We migrated the locales configurations to UI config. You no longer need to set locales for GitChangelogMarkdownSection plugin.

For information, please refer to Migrate from v1 to v2.

Besides the UI widget components, Git-based page histories offer another two Vite plugins for data fetching and rendering. These plugins are GitChangelog and GitChangelogMarkdownSection.

A TypeScript User?

You need to configure at least the following options:

jsonc
{
  "compilerOptions": {
    "module": "ESNext", 
    "moduleResolution": "Bundler", 
  },
  "include": [
    "**/.vitepress/**/*.ts",
    "**/.vitepress/**/*.mts",
    "**/.vitepress/**/*.vue"
  ],
  "exclude": [
    "node_modules"
  ]
}

And the options

  • module option specifies the JavaScript/TypeScript module format, and Nolebase Integrations uses the ESNext-compatible module format by default.
  • moduleResolution option specifies the module resolution policy, since all Nolebase Integrations plugins follow the latest ECMAScript specifications and export declarations, if you encounter a Cannot find module ... or its corresponding type declarations error you may need to set moduleResolution to Bundler.

If you want more configurations, you can refer to the following example:

jsonc
{
  "compilerOptions": {
    "jsx": "preserve",
    "lib": [
      "DOM",
      "ESNext"
    ],
    "module": "ESNext",
    "moduleResolution": "Bundler",
    "resolveJsonModule": true,
    "strict": true,
    "strictNullChecks": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitAny": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noEmit": true,
    "removeComments": false,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "isolatedModules": true,
    "verbatimModuleSyntax": true,
    "skipLibCheck": true
  },
  "include": [
    "**/.vitepress/**/*.ts",
    "**/.vitepress/**/*.mts",
    "**/.vitepress/**/*.vue"
  ],
  "exclude": [
    "node_modules"
  ]
}

Configure GitChangelog plugin

Remember this part back at the time where we first introduced the GitChangelog plugin?

typescript
import { 
join
} from 'node:path'
import {
defineConfig
} from 'vite'
import {
GitChangelog
,
GitChangelogMarkdownSection
,
} from '@nolebase/vitepress-plugin-git-changelog/vite' export default
defineConfig
(() => {
return {
plugins
: [
GitChangelog
({
// Fill in your repository URL here //
repoURL
: () => 'https://github.com/nolebase/integrations',
}),
GitChangelogMarkdownSection
(),
] // other vite configurations... } })

In the GitChangelog plugin, you can configure the repoURL option to point to your repository URL. This is the only required option for the plugin to work properly.

Option mapAuthors - Map contributors' information

The mapAuthors field in the configuration options is used to map the contributors' information. You can provide the mapAuthors field in the configuration options to map the contributors' information, including the display name, avatar, email, social links, and aliases.

Let's say we have these logs:

plaintext
commit 1
Author: John Doe <john.doe@example.com>
Date:   Fri Oct 1 12:00:00 2021 +0800

    Add a new feature

commit 2
Author: John Doe <john.doe@anothersite.com>

    Fix a bug

We now have two commits from the same person, with only the email address is different. By default, the plugin will treat them as two different contributors. Such case happens when you changed your name or email address in the past.

To solve this, you can provide the mapAuthors field in the configuration options to map the contributors' information:

typescript
import { 
join
} from 'node:path'
import {
defineConfig
} from 'vite'
import {
GitChangelog
,
GitChangelogMarkdownSection
,
} from '@nolebase/vitepress-plugin-git-changelog/vite' export default
defineConfig
(() => {
return {
plugins
: [
GitChangelog
({
// Fill in your repository URL here
repoURL
: () => 'https://github.com/nolebase/integrations',
mapAuthors
: [
{
name
: 'John Doe',
username
: 'john_doe',
mapByEmailAliases
: ['john.doe@anothersite.com']
} ] }),
GitChangelogMarkdownSection
(),
] // other vite configurations... } })

All options

But the options don't stop there. We have more options to configure the plugin to fit your needs.

Full list of options
typescript
interface GitChangelogOptions {
    /**
   * The current working directory in which to search files.
   *
   * @default process.cwd()
   */
  
cwd
?: string
/** * When fetching git logs, what files should be included? * * @default ['** /*.md', '!node_modules'] */
include
?: string[]
/** * Map authors */
mapAuthors
?: Author[]
/** * Your repository URL. * Yes, you can dynamically generate it. * * @default 'https://github.com/example/example' */
repoURL
?: string |
CommitToStringHandler
/** * A function to get the release tag URL. * * @default (commit) => `${commit.repo_url}/releases/tag/${commit.tag}` */
getReleaseTagURL
?:
CommitToStringHandler
/** * A function to get the release tags URL. * * @default (commit) => commit.tags?.map(tag => `${commit.repo_url}/releases/tag/${tag}`) */
getReleaseTagsURL
?:
CommitToStringsHandler
/** * A function to get the commit URL. * * @default (commit) => `${commit.repo_url}/commit/${commit.hash}` */
getCommitURL
?:
CommitToStringHandler
/** * Rules to rewrite paths by patterns. * * This can be quite useful when your pages are in different directories, * or when they are generated at runtime according to path.ts. * * Since the plugin matches the git information for each page by comparing the local path, * you can override the local file path to `vitepress.useData.page.value.filePath` with this option. * * @example * * ```typescript * GitChangelog({ * rewritePathsBy: { * handler: (_commit, path) => { * if (path) { * // path: packages/characters/src/lib1.ts * if (path.startsWith('packages/characters/src/') && !path.includes('index.ts')) * return `${path.replace('packages/characters/src/', '').slice(0, -3)}.md` * } * return path * }, * }, * }) * ``` * * Besides that, we offer some built-in handlers to rewrite paths by patterns: * * - `rewritePathsByRewritingExtension(from: string, to: string)`: to rewrite paths by rewriting the extension. * * @example * * ```typescript * import { GitChangelog, rewritePathsByRewritingExtension } from '@nolebase/vitepress-plugin-git-changelog/vite' * * GitChangelog({ * rewritePathsBy: { * // to rewrite `example.md` to `example.html` * handler: rewritePathsByRewritingExtension('.md', '.html') * } * }) * ``` * * @see rewritePathsByRewritingExtension */
rewritePathsBy
?: RewritePathsBy
/** * The maximum number of git logs to fetch. */
maxGitLogCount
?: number
}

Configure GitChangelogMarkdownSection plugin

The GitChangelogMarkdownSection plugin is a plugin that helps you to inject the Markdown sections into your VitePress pages. It's a plugin that works with the GitChangelog plugin to provide the data for the Markdown sections.

typescript
import { 
defineConfig
} from 'vite'
import {
GitChangelogMarkdownSection
,
} from '@nolebase/vitepress-plugin-git-changelog/vite' export default
defineConfig
({
plugins
: [
GitChangelogMarkdownSection
(),
], // other vite configurations... })

Behind the scene, what this plugin does it simply appending <NolebaseGitContributors /> and <NolebaseGitChangelog /> components to your Markdown pages.

It does have more options to configure.

Full list of options
typescript
interface GitChangelogMarkdownSectionOptions {
  /**
   * The list of file names to exclude from the transformation
   *
   * @default ['index.md']
   */
  
excludes
?: string[]
/** * The function to exclude the file from the transformation * * @param id - the current transforming module ID (comes from vite when transform hook is called) * @param context - the context object, contains several helper functions * @returns boolean * @default () => false */
exclude
?: (
id
: string,
context
: Context) => boolean
/** * The sections options */
sections
?: {
/** * Whether to disable the changelog section */
disableChangelog
?: boolean
/** * Whether to disable the contributors section */
disableContributors
?: boolean
} }

Excluding a page from the transformation of GitChangelogMarkdownSection

You can exclude a page from the transformation of GitChangelogMarkdownSection by adding the nolebase.gitChangelog or gitChangelog frontmatter to the page:

markdown
---
nolebase:
  gitChangelog: false
---

or

markdown
---
gitChangelog: false
---

Globally exclude a page from the transformation of GitChangelogMarkdownSection

You can globally exclude a page from the transformation of GitChangelogMarkdownSection by configuring the exclude option:

typescript
import { 
defineConfig
} from 'vite'
import {
GitChangelogMarkdownSection
,
} from '@nolebase/vitepress-plugin-git-changelog/vite' export default
defineConfig
({
plugins
: [
GitChangelogMarkdownSection
({
exclude
: (
id
) =>
id
.
endsWith
('index.md'),
}), ], // other vite configurations... })

Globally disable the changelog or contributors section

You can globally disable the changelog or contributors section by configuring the sections option:

typescript
import { 
defineConfig
} from 'vite'
import {
GitChangelogMarkdownSection
,
} from '@nolebase/vitepress-plugin-git-changelog/vite' export default
defineConfig
({
plugins
: [
GitChangelogMarkdownSection
({
sections
: {
disableChangelog
: true,
disableContributors
: true,
}, }), ], // other vite configurations... })

Contributors

Changelog

Layout Switch

Adjust the layout style of VitePress to adapt to different reading needs and screens.

Expand all
The sidebar and content area occupy the entire width of the screen.
Expand sidebar with adjustable values
Expand sidebar width and add a new slider for user to choose and customize their desired width of the maximum width of sidebar can go, but the content area width will remain the same.
Expand all with adjustable values
Expand sidebar width and add a new slider for user to choose and customize their desired width of the maximum width of sidebar can go, but the content area width will remain the same.
Original width
The original layout width of VitePress

Page Layout Max Width

Adjust the exact value of the page width of VitePress layout to adapt to different reading needs and screens.

Adjust the maximum width of the page layout
A ranged slider for user to choose and customize their desired width of the maximum width of the page layout can go.

Content Layout Max Width

Adjust the exact value of the document content width of VitePress layout to adapt to different reading needs and screens.

Adjust the maximum width of the content layout
A ranged slider for user to choose and customize their desired width of the maximum width of the content layout can go.

Spotlight

Highlight the line where the mouse is currently hovering in the content to optimize for users who may have reading and focusing difficulties.

ONOn
Turn on Spotlight.
OFFOff
Turn off Spotlight.

Spotlight Styles

Adjust the styles of Spotlight.

Under
Add a solid background color underneath the hovering element to highlight where the cursor is currently hovering.
Aside
Add a fixed line with solid color aside the hovering element to highlight where the cursor is currently hovering.