campaigningbureau/critical-laravel-routes 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

campaigningbureau/critical-laravel-routes

Composer 安装命令:

composer require campaigningbureau/critical-laravel-routes

包简介

Automatically create and link Critical CSS for static routes in Laravel projects

README 文档

README

Automatically create and link Critical CSS for static routes.

Supports Laravel 7.*

Installation

Just require the package via composer:

composer require campaigningbureau/critical-laravel-routes

The package gets automatically discovered by Laravel.

Usage

  1. All static routes, that should use critical css, need to be named and have a critical attribute set to true:

    Route::get('/', ['as' => 'index', 'uses' => 'ViewController@index', 'critical' => true]);
  2. Generate the JSON that contains all critical routes:

    php artisan critical-urls:generate
  3. The generated file needs to be required in the webpack.mix.js and set as urls when creating the critical css:

    // urls that need to be passed for critical css
    const criticalUrls = require('./critical-routes.json');
    ...
    mix.criticalCss({
        enabled: mix.inProduction(),
        paths: {
            base: 'http://your-website.com',
            templates: 'public/css/'
        },
        urls: criticalUrls,
        options: {
            minify: true,
        },
    });

    When generating the css, one css file per defined route is created and saved.

  4. Automatically import the content of the critical css file (if it exists for the route) in the blade template as inline styles:

    {!! \CriticalLaravelRoutes::inlineCriticalCss() !!}
    

    Alternatively, the critical css file can be linked with:

    {!! \CriticalLaravelRoutes::linkCriticalCss() !!}
    

    This can be used safely vor every existing route, so it is best to put it in the base layout. If no critical css file is found for a route, nothing is displayed.

Configuration

The config can be changed by publishing the configuration file:

$ php artisan vendor:publish --provider="CampaigningBureau\CriticalLaravelRoutes\CriticalLaravelRoutesServiceProvider"

It is possible to configure the name of the generated JSON file and the suffix for the critical css filess.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-01-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固