ajaxray/gulp-buster-bundle

Symfony Bundle,用于整合gulp-buster npm包以实现缓存破坏

安装: 460

依赖者: 0

建议者: 0

安全性: 0

星星: 5

观察者: 4

分支: 1

开放问题: 0

类型:symfony-bundle

v1.0.1 2016-02-14 10:59 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:20:42 UTC


README

Build Status Coverage Status Latest Stable Version Total Downloads License SensioLabsInsight

当使用 gulp 来管理Symfony应用的资源时,这个Bundle将帮助你通过gulp-buster包来实现缓存破坏。

安装

使用以下命令安装最新版本

$ composer require ajaxray/gulp-buster-bundle

然后,在AppKernel中启用此Bundle

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Ajaxray\GulpBusterBundle\GulpBusterBundle(),
    );
}

使用方法

假设你正在使用 gulp-buster 来为你的网页资源(javascript、css、图片等静态资源)生成哈希值。

接下来,你需要将这些哈希值与你的网页资源结合使用。这个Bundle会通过添加一个Twig过滤器来简化这个过程。以下是如何在Twig视图中使用这个过滤器的方法

<link rel="stylesheet" href="{{ asset('css/example.min.css')|with_buster_hash  }}">

如果为该文件找到了哈希值,它将被附加到URL作为查询字符串

<link rel="stylesheet" href="/css/example.min.css?v=771191ec8571a3f46afdb78f3e7bed17">

如果没有为该文件找到哈希值

<link rel="stylesheet" href="/css/example.min.css?v=no-buster-hash-found">

就是这样 :)

配置

默认情况下,此Bundle假设以下路径

  • busters.json(或任何其他名称)文件:%kernel.root_dir%/../busters.json
  • web目录:%kernel.root_dir%/../web
  • gulp目录(gulpfile.js的目录):%kernel.root_dir%/..

如果你上述任何一个路径与默认不同,你可以通过以下键在你的app/config/config.yml文件中进行配置

gulp_buster:  
    # if you've configured it to be in web dir    
    busters_file: "%kernel.root_dir%/../web/busters.json"    
    web_dir: "%kernel.root_dir%/relative/path/to/web/dir"    
    gulp_dir: "%kernel.root_dir%/relative/path/to/dir"