承接 laravel-ready/laravel-vitepress 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

laravel-ready/laravel-vitepress

Composer 安装命令:

composer require laravel-ready/laravel-vitepress

包简介

Serve VitePress documentation in Laravel with middleware and authentication support

README 文档

README

Laravel-VitePress

Latest Version on Packagist GitHub Tests Action Status Total Downloads License

Serve VitePress documentation in your Laravel application with full middleware support, authentication, and role-based access control.

✨ Features

  • 🚀 Pre-built VitePress documentation (no build step required in production)
  • 🔐 Laravel authentication and authorization integration
  • 🛡️ Middleware support for route protection
  • 👥 Role and permission-based access control (compatible with Spatie Laravel Permission)
  • ⚙️ Fully configurable routing
  • 📦 Easy installation and publishing
  • 🎨 Customizable views and layouts
  • 🔒 Path traversal protection
  • 🔐 Protected storage by default (docs stored outside public/ to enforce auth)
  • 💾 Cache control headers
  • 🌐 Multi-domain support

📋 Requirements

  • PHP 8.1+
  • Laravel 10.x, 11.x, or 12.x
  • Node.js 20+ (for building documentation)

📊 Support Matrix

PHP Laravel 10 Laravel 11 Laravel 12
8.1
8.2
8.3
8.4
8.5

📦 Installation

Install the package via Composer:

composer require laravel-ready/laravel-vitepress

Run the installation command:

php artisan vitepress:install

This will publish:

  • Configuration file to config/vitepress.php
  • Pre-built documentation assets to storage/app/vitepress/docs (protected by default)

Visit /docs in your browser to see your documentation.

⚙️ Configuration

Basic Setup

// config/vitepress.php

return [
    'route' => [
        'prefix' => 'docs', // Access at /docs
        'middleware' => ['web'],
    ],
];

Storage Location

By default, documentation is stored in storage/ to prevent direct file access and ensure authentication is enforced. For public documentation without auth, you can store in public/:

'assets' => [
    // 'storage' = protected (default), 'public' = directly accessible
    'storage' => 'storage',
    'path' => 'vitepress/docs',
],

Important: If you use authentication (auth.enabled = true), keep storage set to 'storage'. Otherwise users can bypass auth by accessing files directly at /vitepress/docs/index.html.

With Authentication

Require users to be logged in:

'auth' => [
    'enabled' => true,
    'middleware' => ['auth'],
],

With Role-Based Access

Works with spatie/laravel-permission (optional):

'auth' => [
    'enabled' => true,
    'middleware' => ['auth'],
    'roles' => ['admin', 'developer'],
],

With Permission-Based Access

'auth' => [
    'enabled' => true,
    'middleware' => ['auth'],
    'permissions' => ['view-documentation'],
],

Note: Role and permission checks use hasAnyRole() and hasAnyPermission() methods from Spatie Laravel Permission. If the package is not installed, these checks are automatically skipped. The package works without Spatie - you can use basic auth or custom gates instead.

Custom Domain

Serve documentation from a subdomain:

'route' => [
    'domain' => 'docs.example.com',
    'prefix' => '',
],

Custom Gate

Define a custom gate for complex authorization:

// In AuthServiceProvider
Gate::define('view-documentation', function ($user) {
    return $user->hasActiveSubscription();
});

// config/vitepress.php
'auth' => [
    'enabled' => true,
    'gate' => 'view-documentation',
],

🚀 Usage

Accessing Documentation

After installation, your documentation is available at:

https://your-app.com/docs

Using the Facade

use LaravelReady\VitePress\Facades\VitePress;

// Check if VitePress is enabled
if (VitePress::isEnabled()) {
    // ...
}

// Get the documentation URL
$url = VitePress::getRouteUrl();

// Check if current user can access docs
if (VitePress::canAccess()) {
    // Show documentation link
}

// Get configuration
$config = VitePress::getConfig();
$prefix = VitePress::getConfig('route.prefix');

In Blade Templates

@if(VitePress::isEnabled() && VitePress::canAccess())
    <a href="{{ VitePress::getRouteUrl() }}">Documentation</a>
@endif

🎨 Customization

Publishing VitePress Source

To customize the documentation:

php artisan vitepress:publish --stubs

This will publish VitePress source files to resources/docs/.

Configuration Files

The VitePress config is split into two files:

File Purpose Editable?
.vitepress/config.mts Package-managed (base URL, dotenv) No
.vitepress/config.docs.mts Your customizations (title, nav, sidebar) Yes

Edit config.docs.mts to customize your documentation. Don't edit config.mts - it contains package logic that reads from your .env file.

Building Documentation

After making changes, rebuild:

php artisan vitepress:build

Changing Route Prefix

Just update your .env file:

VITEPRESS_ROUTE_PREFIX=documentation

Then rebuild:

php artisan vitepress:build

The base URL is automatically read from your .env file - no need to pass environment variables manually.

Publishing Other Resources

# Publish configuration only
php artisan vitepress:publish --config

# Publish assets only
php artisan vitepress:publish --assets

# Publish views only
php artisan vitepress:publish --views

# Publish everything
php artisan vitepress:publish --all

# Publish everything (force overwrite, useful when package needs updating etc.)
php artisan vitepress:publish --all --force

🛠️ Artisan Commands

Command Description
vitepress:install Install the package (publishes config and assets)
vitepress:publish Publish specific resources
vitepress:build Build VitePress documentation

🔧 Environment Variables

VITEPRESS_ENABLED=true
VITEPRESS_ROUTE_PREFIX=docs
VITEPRESS_DOMAIN=
VITEPRESS_AUTH_ENABLED=false
VITEPRESS_ALLOWED_ROLES=admin,developer
VITEPRESS_ALLOWED_PERMISSIONS=view-docs
VITEPRESS_GATE=
VITEPRESS_STORAGE=storage
VITEPRESS_ASSETS_PATH=vitepress/docs
VITEPRESS_CACHE_ENABLED=true
VITEPRESS_CACHE_MAX_AGE=3600

🔬 Advanced Usage

Custom Headers

Add security or custom headers:

'options' => [
    'headers' => [
        'X-Frame-Options' => 'SAMEORIGIN',
        'X-Content-Type-Options' => 'nosniff',
    ],
],

Custom 404 Page

'options' => [
    'custom_404' => 'errors.docs-404',
],

CORS Support

Enable CORS for API documentation:

'options' => [
    'cors_enabled' => true,
],

SPA Fallback

The package includes SPA fallback routing by default. Disable it for traditional page routing:

'options' => [
    'spa_fallback' => false,
],

🧪 Testing

composer test

📝 Changelog

Please see CHANGELOG for more information on what has changed recently.

🤝 Contributing

Please see CONTRIBUTING for details.

laravel-ready/laravel-vitepress 适用场景与选型建议

laravel-ready/laravel-vitepress 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.11k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 12 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「documentation」 「docs」 「laravel」 「vitepress」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 laravel-ready/laravel-vitepress 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 laravel-ready/laravel-vitepress 我们能提供哪些服务?
定制开发 / 二次开发

基于 laravel-ready/laravel-vitepress 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.11k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-01