태그 보관물: magento-2.1

magento-2.1

Magento 2 Pub 정적 파일의 기본 또는 프로덕션 모드에서 Symlink 사용 났으며이 중 350MB는 복사 된

상황 : Magento 2 무료 평가판을 사용하고 있으며 VPS에서 HD 공간이 제한되어 있습니다. 이러한 이유로 HD 공간을 줄이려면 기본 또는 프로덕션 모드에서 Magento가 파일을 심볼릭 링크하고 싶습니다. 사이트가 처음 실행되면 기본 Magento 2 설치가 약 420MB 인 것으로 나타 났으며이 중 350MB는 복사 된 파일입니다.

app / etc / di.xml 줄을 수정했습니다.

 <item name="default" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Copy</item>

 <item name="default" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink</item>

이것은 정상적으로 작동하며 기본 모드에서도 사이트가 심볼릭 링크를 올바르게 만듭니다. 그러나 문제는 CSS가 생성되지 않거나 js-translation.json이 생성해야하지만 파일이 아닌 파일입니다.

/pub/static/version1488209436/frontend/Magento/luma/en_US/css/styles-m.css

/pub/static/version1488209436/frontend/Magento/luma/en_US/css/styles-l.css

/pub/static/version1488209436/frontend/Magento/luma/en_US/css/print.css

/pub/static/version1488209436/frontend/Magento/luma/en_US/js-translation.json

질문은 : 기본 또는 프로덕션 모드에서 심볼릭 링크를 사용할 때 어떻게 Magento가 이러한 파일을 생성하도록합니까?



답변

app/etc/di.xml: 새 항목 추가 stategiesList:

<virtualType name="developerMaterialization" type="Magento\Framework\App\View\Asset\MaterializationStrategy\Factory">
    <arguments>
        <argument name="strategiesList" xsi:type="array">
            <item name="view_preprocessed" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink</item>
            <item name="default" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink</item>
/* ++ */    <item name="asset" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Copy</item>
        </argument>
    </arguments>
</virtualType>

개발자 모드에 있다고 가정하면 pub/static브라우저에서 컨텐츠를 삭제하고 페이지로 이동하면 magento가 정적 컨텐츠를 재생성합니다.

Magento 2.1.4에서 나를 위해 일했습니다 (styles-m.css가 생성되고 다른 파일이 심볼 링크되었습니다).

모든 마법은 vendor/magento/framework/App/View/Asset/MaterializationStrategy/Factory.php다음 에서 발생합니다 .

public function create(Asset\LocalInterface $asset)
{   
    if (empty($this->strategiesList)) {
        $this->strategiesList[] = $this->objectManager->get(self::DEFAULT_STRATEGY);
    }   

    foreach ($this->strategiesList as $strategy) {
        if ($strategy->isSupported($asset)) {
            return $strategy;
        }   
    }   

    throw new \LogicException('No materialization strategy is supported');
}   

Magento는 stategiesList항목을 반복 하고 자산을 지원하는 첫 번째 상태를 사용합니다.

프로덕션 모드에서 작동시키는 방법?

면책 조항 : 이 핵에는 핵심 파일 편집이 포함되어 있습니다. 조심하십시오.

모두 마 젠토 2.1.4에서 테스트

  1. 정적 파일에서 버전 번호를 제거하십시오. Stores > Configuration > Advanced > Developer > Static Files Settings > No
  2. 기능을 다음과 같이 편집 vendor/magento/framework/App/StaticResource.php하고 작성 launch하십시오.

    public function launch()
    {   
    // disabling profiling when retrieving static resource
    \Magento\Framework\Profiler::reset();
    $appMode = $this->state->getMode();
    /*if ($appMode == \Magento\Framework\App\State::MODE_PRODUCTION) {
        $this->response->setHttpResponseCode(404);
    } else {*/
        $path = $this->request->get('resource');
        $params = $this->parsePath($path);
        $this->state->setAreaCode($params['area']);
        $this->objectManager->configure($this->configLoader->load($params['area']));
        $file = $params['file'];
        unset($params['file']);
        $asset = $this->assetRepo->createAsset($file, $params);
        $this->response->setFilePath($asset->getSourceFile());
        $this->publisher->publish($asset);
    /*}*/
    return $this->response;
    }   
    
  3. pub/static브라우저에서 컨텐츠를 삭제 하고 상점 URL을 방문하십시오.


답변

프로덕션 모드가 아닌 경우 Magento 2는 일부 정적 리소스에 대한 심볼릭 링크를 만들려고 시도합니다. 다음을 수행하여 해당 동작을 변경할 수 있습니다.

  1. app / etc / di.xml을 열고 virtualType name = “developerMaterialization”섹션을 찾으십시오. 이 섹션에는 수정하거나 삭제해야하는 항목 이름 = “view_preprocessed”이 있습니다. Magento \ Framework \ App \ View \ Asset \ MaterializationStrategy \ Symlink에서 Magento \ Framework \ App \ View \ Asset \ MaterializationStrategy \ Copy로 내용을 변경하여 내용을 수정할 수 있습니다.

  2. pub / static에서 파일을 삭제하십시오. .htaccess 파일을 삭제하지 마십시오.


답변