2012-07-10 4 views
12

나침반 필터와 함께 Assetic을 사용하여 .scss 파일을 전달하고 컴파일합니다. 이 부분은 제대로 작동하는 것 같습니다. 그러나, app_dev 환경에서 symfony 2는 각 페이지로드에 대한 모든 애셋 (css 포함)을 다시 컴파일하고 깔끔한 환경을 위해 사용하는 캐싱 시스템을 사용하지 않는다는 것을 이해했습니다.symfony2 clear cache 명령으로 새로 고치지 않는 정적 자산

이것은 발생하지 않는 것처럼 보입니다.

내가 사용하는 경우 .scss이 변경에만 적용됩니다 파일을 만들 :

app/console cache:clear 

내가 dev에 환경의 요점이마다 할 것을 피하기 위해 줄 알았는데?!

캐시 폴더의 사용 권한을 확인했습니다 (안전하게 설정할 수 있으므로 누구나 읽고 쓸 수 있습니다). 누구 제안이 있습니까?

+0

Symfony를 ** less **와 함께 사용하고 변경 사항이 실제 포함 된 파일에 있고 파일에서 가져온 파일이 아니라면 모든 요청에 ​​대해 다시 컴파일합니다. 그게 네 문제 야? – solarc

답변

10

나는 내가 여기에 해답을 발견했습니다 생각 :

assetic compass filter, css not updating when changing imported file (google groups discussion)

것 같다을 그 변화는 부모 파일 부모를 변경하지 않고도 가져온 파일에 경우 파일은 다시 컴파일되지 않습니다. 변경 결과는 재 컴파일을 강제해야 나타납니다.

Google 그룹의 포스터는 AsseticController를 편집하여 가능한 수정 (해킹!)을 제안했습니다. 아직 시도하지는 않았지만 작동하더라도 벤더 패키지를 편집하지는 않을 것입니다.

3

자산 편집은 캐싱 시스템의 일부가 아닙니다. 환경에 관계없이 변경하면 자산을 다시 설치해야합니다.

app/console assets:install web 

하면 현재 파일 시스템이 기호 링크를 지원하는 경우, 모든 변경이 명령을 실행하는 것을 방지하고 대신 같은

app/console assets:install web --symlink 

으로 자산을 설치하지만 사용하고 있기 때문에 수 Sass, 아마도이 옵션은 당신에게 적당하지 않습니다.

HTH

+0

미안 피터, 내가 분명해야 했어. 이미지 파일과 같은 자산 파일 (CSS, JS)에 대해서만 이야기합니다. docs (http://symfony.com/doc/current/cookbook/assetic/asset_management.html)에서 개발자 환경에서 이러한 자산은 동적으로 처리되며 변경 사항은 즉시 확인되어야한다고 명시되어 있습니다. – musoNic80

3

나는 이것이 오래된 주제이지만 CompassElephantBundle과 위의 AsseticController 해킹 만 해답이라고 대답했다. 근본적으로 접근법이 있지만 벤더 패키지를 편집 할 필요가 없다는 것을 의미합니다.

내가 해낸 방법은 원래 AsseticController를 복사 한 다음 매개 변수에서 구성에 연결하는 것입니다.

parameters: 
    assetic.controller.class: Acme\RandomBundle\Controller\AsseticController 

는 복사 된 AsseticController은 소스 경로에서 파일 형식에 대해는 preg_match을 수행하고 거기에서 캐싱을 수정합니다.

<?php 

/* Original Assetic Controller */ 

public function render($name, $pos = null) 
{ 
    if (!$this->enableProfiler && null !== $this->profiler) { 
     $this->profiler->disable(); 
    } 

    if (!$this->am->has($name)) { 
     throw new NotFoundHttpException(sprintf('The "%s" asset could not be found.', $name)); 
    } 

    $asset = $this->am->get($name); 
    if (null !== $pos && !$asset = $this->findAssetLeaf($asset, $pos)) { 
     throw new NotFoundHttpException(sprintf('The "%s" asset does not include a leaf at position %d.', $name, $pos)); 
    } 

    $bustCache = preg_match('/\.(scss|sass|less)$/', $asset->getSourcePath()); 

    $response = $this->createResponse(); 
    $response->setExpires(new \DateTime()); 

    if ($bustCache) { 
     $lastModified = time(); 
     $date = new \DateTime(); 
     $date->setTimestamp($lastModified); 
     $response->setLastModified($date); 
    } 
    else 
    { 
     // last-modified 
     if (null !== $lastModified = $asset->getLastModified()) { 
      $date = new \DateTime(); 
      $date->setTimestamp($lastModified); 
      $response->setLastModified($date); 
     } 
    } 

    // etag 
    if ($this->am->hasFormula($name)) { 
     $formula = $this->am->getFormula($name); 
     $formula['last_modified'] = $lastModified; 
     $response->setETag(md5(serialize($formula))); 
    } 

    if ($response->isNotModified($this->request)) { 
     return $response; 
    } 

    if ($bustCache) { 
     $response->setContent($asset->dump()); 
    } 
    else { 
     $response->setContent($this->cachifyAsset($asset)->dump()); 
    } 

    return $response; 
} 

/* Rest of controller */ 
13

당신이 DEV에서 심포니 2 개 자산 작업하는 경우. 환경, 단순히 this command를 사용

php app/console assets:install 
php app/console assetic:dump --watch 

버전 2입니다.4 --watch is deprecated,에 의해 대체되었습니다 : 나는 기본적으로 발생하는 어떠한 자산 캐싱을 중지 내 parameters.yml의 마지막에 행을 추가하여 지역 발전에이 문제를 해결 한

php app/console assetic:watch 
+0

세부 정보 : http://symfony.com/blog/new-in-symfony-2-6-smarter-assets-install-command 및 http://symfony.com/doc/current/cookbook/assetic/asset_management.html – Dung

2

.

# parameters.yml 
... 

assetic.cache.class: Assetic\Cache\ArrayCache 

우리가 캐싱 일이 원하는대로 이것은 결코 프로덕션 환경에 포함되어야한다!

0

다른 방법을 사용합니다. 개발 도중 모든 .scss 파일을 추가하려고합니다.

{% block stylesheets %} 
     {% stylesheets filter='?uglifycss' filter='cssrewrite' filter="compass" 
      "@TESTSSassBundle/Resources/public/css/_vars.scss" <-- this will be removed 
      "@TESTSSassBundle/Resources/public/css/main.scss" 
      "@TESTSSassBundle/Resources/public/css/header.scss" 
      "@TESTSSassBundle/Resources/public/css/footer.scss" 
     %} 
      <link rel="stylesheet" href="{{ asset_url }}" /> 
     {% endstylesheets %} 
    {% endblock %} 

그리고 개발이 끝나면 제거합니다. 이렇게하면 캐시를 지우고 설정을 추가/변경할 필요가 없습니다. 그것은 항상 나를 위해 일합니다.

관련 문제