Skip to content
CONSTRUCTING

Getting started

Word count
824 words
Reading time
6 minutes

Installation

Install @nolebase/vitepress-plugin-git-changelog to your project dependencies by running the following command:

shell
ni @nolebase/vitepress-plugin-git-changelog -D
shell
pnpm add @nolebase/vitepress-plugin-git-changelog -D
shell
npm install @nolebase/vitepress-plugin-git-changelog -D
shell
yarn add @nolebase/vitepress-plugin-git-changelog -D

Usage

This is roughly the most complex one to configure with!

Please pay attentions to the following configurations and steps to get started with the Git-based page histories plugin. It is not quite simple as other plugins.

It consists two major steps to integrate the Inline Links Previewing plugin into your VitePress project:

Configure Vite plugin

There are two ways to integrate the Git-based page histories Vite plugin into your VitePress project:

  1. Recommended: Use the vite option in VitePress's primary configuration file (usually located at docs/.vitepress/config.ts, file paths and extensions may be vary)
  2. Create a separated Vite configuration file (e.g. vite.config.ts) in the root directory of your VitePress project

Configure Vite plugin in VitePress's config file

In VitePress's primary configuration file (not this is not a theme configuration file, it's usually located at docs/.vitepress/config.ts, file paths and extensions may be vary), we need to import both GitChangelog (data fetcher), and GitChangelogMarkdownSection (widget embedder) the plugins and configure it properly:

If you've never seen a colored diff before

This is a markup rule for displaying diff in the user interface (UI).

Red parts usually represents the lines you are going to remove, commonly appeared with a Minus sign -, or you could simply understand it as: this line will be removed.

Green parts usually represents the lines you are going to add, commonly appeared with a Plus sign +, or you could simply understand it as: this line will be added.

To learn more about diff, you can check out this answer about the history of diffutils and Git's documentation

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"
  ]
}
typescript
import {  } from 'vitepress'
import { 
  , 
  , 
} from '@nolebase/vitepress-plugin-git-changelog/vite'

// https://vitepress.dev/reference/site-config
export default ({
  : { 
    : [ 
      ({ 
        // Fill in your repository URL here
        : () => 'https://github.com/nolebase/integrations', 
      }), 
      (), 
    ],
  }, 
  : 'en',
  : 'Site Name',
  : {
    // rest of the options...
  }
  // rest of the options...
})

Configure Vite plugin in a separated Vite configuration file

Ensure vite.config.ts is created

If you understand what vite.config.ts is already and have created it, you can skip this preparation step and jump to the next step Configure plugin in vite.config.ts.

New to vite.config.ts is?

First of all, vite.config.ts is a configuration file for Vite, the build tool that VitePress is built on. It allows developers to build and transform the assets, content and data in the project.

Even though VitePress itself contains entire set of Vite options in its primary configuration file (not this is not a theme configuration file, it's usually located at docs/.vitepress/config.ts, file paths and extensions may be vary), these options, and yet, the vite.config.ts are identical in terms of configurations.

However, due to the order of plugins it registered, it's not enough to transform the needed data and logs if we install the Git-based page histories plugin in this way.

Therefore, please create a separated vite.config.ts file in the root directory of your VitePress project:

Where is the root directory of VitePress project?

VitePress project's root directory is where the parent directory of .vitepress directory is.

For example:

shell
.
├── docs
   ├── .vitepress
   ├── config.ts
   └── theme
       └── index.ts
   └── README.md

In this case, the root directory is docs.

shell
.
├── .vitepress
   ├── config.ts
   └── theme
       └── index.ts
└── README.md

In this case, the root directory is ./.

shell
touch vite.config.ts
Configure plugin in vite.config.ts

In the standalone Vite configuration file (e.g. vite.config.ts) file we have under our root directory, we need to import both GitChangelog (data fetcher), and GitChangelogMarkdownSection (widget embedder) the plugins and configure it properly:

If you've never seen a colored diff before

This is a markup rule for displaying diff in the user interface (UI).

Red parts usually represents the lines you are going to remove, commonly appeared with a Minus sign -, or you could simply understand it as: this line will be removed.

Green parts usually represents the lines you are going to add, commonly appeared with a Plus sign +, or you could simply understand it as: this line will be added.

To learn more about diff, you can check out this answer about the history of diffutils and Git's documentation

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"
  ]
}
typescript
import {  } from 'node:path'
import {  } from 'vite'
import { 
  , 
  , 
} from '@nolebase/vitepress-plugin-git-changelog/vite'

export default (() => {
  return {
    : [ 
      ({ 
        // Fill in your repository URL here
        : () => 'https://github.com/nolebase/integrations', 
      }), 
      (), 
    ]
    // other vite configurations...
  }
})

Integrate with VitePress theme

Now, let's integrate the Git-based page histories UI widgets into your VitePress project.

In VitePress's theme configuration file (note that it's not a configuration file, it's usually located at docs/.vitepress/theme/index.ts, file paths and extensions may be vary), install the Vue plugin and use the components:

If you've never seen a colored diff before

This is a markup rule for displaying diff in the user interface (UI).

Red parts usually represents the lines you are going to remove, commonly appeared with a Minus sign -, or you could simply understand it as: this line will be removed.

Green parts usually represents the lines you are going to add, commonly appeared with a Plus sign +, or you could simply understand it as: this line will be added.

To learn more about diff, you can check out this answer about the history of diffutils and Git's documentation

typescript
import {  } from 'vue'
import  from 'vitepress/theme'
import type {  as ThemeConfig } from 'vitepress'
import { 
   
} from '@nolebase/vitepress-plugin-git-changelog/client'

import '@nolebase/vitepress-plugin-git-changelog/client/style.css'

export const : ThemeConfig = {
  : ,
  : () => {
    // other configurations...
  },
  ({  }) {
    .()  
  },
}

export default 

Troubleshooting

Encountered Cannot find module ... or its corresponding type declarations error?

If you are encountering this error with Nolebase Integrations packages inside of .ts or .vue files, you may need to configure the moduleResolution option in your tsconfig.json file.

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

If the error persists, please submit a GitHub issue for further assistance and troubleshooting.

Contributors

The avatar of contributor named as Neko Neko
The avatar of contributor named as Glom_ Glom_

Changelog