npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vitepress-plugin-theme-override

v0.1.0

Published

Makes it easy to further customize Vitepress's default theme without the need to import it all

Downloads

48

Readme

vitepress-plugin-theme-override

Vitepress makes it easy to setup documentation for whatever library you're working on. Its default theme is pretty clean and provides both great DX and UX out-of-the-box, along with basic customization capabilities through slots and CSS Custom Properties. While the default theme probably is enough to most people, some users might want to push customization further e.g. to get an even more impactful homepage.

This plugin allows users to override specific parts of Vitepress' default theme, without the need of forking the whole theme into their own repository. Just provide the path to your overrides' dedicated folder and get its structure aligned with the default theme's one.

Getting started

Install

# Using npm
npm i -D vite vitepress vitepress-plugin-theme-override
# Using Yarn
yarn add -D vite vitepress vitepress-plugin-theme-override
# Using pnpm
pnpm add -D vite vitepress vitepress-plugin-theme-override

Usage

Setup the plugin in Vitepress' Vite configuration file (you might have to create it).

import { resolve } from 'path';
import { defineConfig } from 'vite';
import VitepressThemeOverride from 'vitepress-plugin-theme-override';

export default defineConfig(() => ({
  plugins: [
    VitepressThemeOverride({
      overridePath: resolve(__dirname, './.vitepress/theme/overrides'),
    }),
  ],
}));

Options

overridePath: string

Path to the folder where your overrides are located.

This folder must mimic the default theme's one.

defaultThemeAlias?: string (optional, defaults to "@vptheme")

Alias used to resolve to Vitepress's default theme.

You might still want to import original files from overrides. Because overrides are located in a dedicated folder, using relative paths to import original files would be a real pain. The path to Vitepress' default theme is therefore aliased and automatically added into Vite's final config. However, it still requires that you manually add the path alias to your tsconfig.json, e.g.:

"paths": {
  "@myAlias/*": ["./node_modules/vitepress/dist/client/theme-default/*"]
}

Two types of overrides

Components

Each layer of Vitepress' Vue Single File Components can be specifically overriden. Whenever Vite requests a file which comes from Vitepress' theme and has a matching override, it parses both files to extract all layers data to merge them. This means that for a given component, you might just overwrite the style layer, or both the style and template layers, or any other set of layers you want while still relying on default layers of that component.

| Source                   | Override               | Output                  |
|--------------------------|------------------------|-------------------------|
| <!-- SourceScript -->    |                        | <!-- SourceScript -->   |
| <!-- SourceTemplate -->  |                        | <!-- SourceTemplate --> |
| <!-- SourceStyle -->     | <!-- OverrideStyle --> | <!-- OverrideStyle -->  |

Other files

Any other file will simply serve the overriden version, this includes e.g. composables and other utilities.