Skip to content

Latest commit

ย 

History

26 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

TypeScript Component/Library-Monorepo Template

Repository template for developing Vue 3 libraries in a monorepo powered by pnpm workspaces, heavily inspired by LinusBorg/vue-lib-template created by LinusBorg with a few additions and other spices

STATE: Still working on this here and there โ˜บ๏ธ

What is this and who is it for?

This is a batteries-included monorepo template for building libraries with TypeScript. It provides a complete development environment with all the tooling you need to:

  • ๐Ÿ“ฆ Build multiple library packages in a single repository
  • ๐ŸŽฎ Develop and test with an integrated playground app
  • ๐Ÿ“š Document your libraries with VitePress
  • โœ… Test with Vitest and proper TypeScript support
  • ๐Ÿš€ Publish packages to npm with confidence

Who should use this?

  • Library authors building reusable Vue 3 components or utilities
  • Teams maintaining multiple related packages in one repository
  • Open source maintainers who want a professional setup out of the box
  • Developers who value TypeScript, modern tooling, and best practices

When to use this template

โœ… Building a Vue component library
โœ… Creating TypeScript utilities that work
โœ… Managing multiple related packages together
โœ… Need a playground to test your libraries
โœ… Want documentation alongside your code

โŒ Building a single standalone app
โŒ Need a different meta-framework

Quick Start

Use the CLI (Recommended)

The fastest way to get started is with our CLI tool:

# Using pnpm (recommended)
pnpm create @glstep/vue-ts-lib my-library

The CLI will guide you through:

  • Choosing which packages to include (lib, lib-ts, playground, docs)
  • Setting up your package scope
  • Configuring project metadata

Project Structure

This monorepo contains multiple packages in the packages/ directory:

my-library/
โ”œโ”€โ”€ packages/
โ”‚   โ”œโ”€โ”€ cli/              # CLI tool for scaffolding new projects
โ”‚   โ”‚   โ”œโ”€โ”€ src/          # CLI source code
โ”‚   โ”‚   โ”œโ”€โ”€ templates/    # Project templates
โ”‚   โ”‚   โ””โ”€โ”€ bin/          # Executable entry point
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ lib/              # Vue 3 component library (example)
โ”‚   โ”‚   โ”œโ”€โ”€ src/          # Component source code
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Component.vue
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ index.ts
โ”‚   โ”‚   โ””โ”€โ”€ vite.config.ts
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ lib-ts/           # TypeScript utilities library (example)
โ”‚   โ”‚   โ””โ”€โ”€ src/
โ”‚   โ”‚       โ””โ”€โ”€ index.ts
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ playground/       # Development playground
โ”‚   โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ App.vue
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ main.ts
โ”‚   โ”‚   โ””โ”€โ”€ vite.config.ts
โ”‚   โ”‚
โ”‚   โ””โ”€โ”€ docs/             # VitePress documentation
โ”‚       โ”œโ”€โ”€ .vitepress/
โ”‚       โ”œโ”€โ”€ guide/
โ”‚       โ””โ”€โ”€ api/
โ”‚
โ”œโ”€โ”€ package.json          # Root package.json
โ”œโ”€โ”€ pnpm-workspace.yaml   # pnpm workspace configuration
โ””โ”€โ”€ tsconfig.json         # Root TypeScript config

Package Details

packages/cli

A CLI tool to scaffold new projects based on this template. Allows you to choose which packages to include and customize the setup.

Published to npm as: @glstep/create-ts-lib

packages/lib

Example Vue 3 component library with:

  • TypeScript support
  • Vite for building
  • Vitest for testing
  • Proper tree-shaking and type definitions

packages/lib-ts

Example TypeScript utilities library for:

  • Pure TypeScript code (no Vue dependency)
  • Shared utilities between packages
  • Type-only exports

packages/playground

Development and testing environment:

  • Hot module replacement (HMR)
  • Imports workspace packages automatically
  • Tailwind CSS pre-configured
  • Perfect for manual testing

packages/docs

VitePress documentation site:

  • Markdown-based documentation
  • Component demos
  • API documentation
  • Ready to deploy to Netlify/Vercel

Features

Development Experience

  • โœ… Full TypeScript support for the entire dev workflow
  • โšก๏ธ Vite-powered build system for lightning-fast development
    • ๐ŸŽฏ Build libraries with Vite
    • ๐Ÿ”ฅ Hot Module Replacement (HMR) in playground
    • ๐Ÿ“ฆ Optimized production builds
  • ๐ŸŽจ Type checking with vue-tsc and declaration file generation
  • ๐Ÿงช Unit tests with Vitest
    • Fast execution with native ESM
    • Vue component testing with @vue/test-utils
    • Watch mode for TDD
  • ๐Ÿ– Code quality with ESLint and Prettier
    • Consistent code style across all packages
    • Auto-fixing on save (VS Code)

Monorepo Management

  • ๐Ÿ“ฆ pnpm workspaces for efficient dependency management
    • Shared dependencies hoisted to root
    • Workspace protocol for local package linking
    • Fast installations with content-addressable storage
  • ๐Ÿ”— Automatic package linking between workspace packages
  • ๐ŸŽฏ Selective script execution with pnpm filters
  • ๐Ÿ—๏ธ TypeScript project references for incremental builds

Documentation & Publishing

  • ๐Ÿ“š VitePress documentation with:
    • Beautiful default theme
    • Markdown-based content
    • Vue component demos
    • Dark mode support
    • Ready for deployment
  • ๐Ÿš€ Publishing ready with:
    • Proper package.json configuration
    • Tree-shaking support
    • Type definitions
    • ESM and CJS builds (configurable)

CLI Tool

  • ๐Ÿ› ๏ธ Interactive scaffolding with @glstep/create-vue-ts-lib
  • โœจ Customizable templates - choose what you need
  • ๐ŸŽจ Package scope configuration - @yourorg/lib
  • โšก๏ธ Fast setup - from zero to development in seconds

Configuration

TypeScript

The project uses TypeScript project references for better IDE performance:

  • Root tsconfig.json - Coordinates all packages
  • tsconfig.app.json - For library source code
  • tsconfig.vitest.json - For test files

Vite

Each package has its own vite.config.ts configured for:

  • Library mode (for lib packages)
  • App mode (for playground)
  • Vue plugin with proper JSX support
  • Path aliases (@/ โ†’ src/)

pnpm

The pnpm-workspace.yaml defines workspace packages:

packages:
  - 'packages/*'

Best Practices

Package Naming

  • Use scoped packages: @yourorg/package-name
  • Keep names consistent: lib, lib-ts, playground, docs
  • Use workspace:* for internal dependencies

Versioning

Testing

  • Write tests alongside your code in __tests__ folders
  • Aim for high coverage on library packages
  • Use playground for integration testing
  • Test TypeScript types with expectTypeOf from Vitest

Documentation

  • Document public APIs with JSDoc comments
  • Add usage examples to VitePress docs
  • Include migration guides for breaking changes
  • Keep README files up to date

Troubleshooting

Common Issues

Problem: Package not found in workspace Solution: Run pnpm install to link workspace packages

Problem: TypeScript errors in IDE Solution: Restart TypeScript server (VS Code: Cmd+Shift+P โ†’ "TypeScript: Restart TS Server")

Problem: Tests fail with module resolution errors Solution: Check vitest.config.ts has correct aliases and resolvers

Problem: Build fails with type errors Solution: Run pnpm typecheck to see all type errors across packages

Getting Help

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

MIT ยฉ Gleb Stepanov

Acknowledgments

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages