Magento 2 Pub 정적 파일의 기본 또는 프로덕션 모드에서 Symlink 사용


11

상황 : 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가 이러한 파일을 생성하도록합니까?


CSS 문제에 대해 Gulp 또는 Grunt를 사용할 수 있습니다 : magento.stackexchange.com/questions/162906/… js-translation.json 파일의 다른 모드를 살펴보십시오. gist.github.com/antonmakarenko/7538216
— B00MER

누군가가 나에게 단계별로 제공하고 작동하는지 확인할 수 있다면 고맙습니다.
— 케빈 차베스

pub / static 폴더 안에 .htaccess 파일이 있는데,이 파일은 URL을 다시 작성하고 URL에서 'version1488209436'을 제거하고 사용자 친화적 인 URL을 제공합니다. .htaccess가 제대로 작동하지 않으면이 유형의 문제 만 발생했습니다.
— Tonmoy

@ Tonmoy에게 감사하지만 전혀 관련이 없습니다. 문제는 기본 / 프로덕션 모드에서 복사하지 않고 심볼릭 링크를 사용하기 때문에 파일이 생성되지 않는다는 것입니다.
— 케빈 차베스

4 개의 파일이 있기 때문에 수동으로 또는 .sh 스크립트에서 해당 심볼릭 링크를 만들 수 있습니다.
— 불분명

답변:


5

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을 방문하십시오.


이것이 완벽하게 작동 해 주셔서 감사합니다! di.xml에서 한 줄만! 또한 작동 방식에 대한 귀하의 설명에 감사드립니다. 이제 설치는 770mb 대신 482mb이므로 VPS 무료 평가판 서버를 업그레이드 할 필요가 없습니다.
— 케빈 차베스

당신을 위해 일한 것을 기쁘게 생각합니다.
— Konstantin Gerasimov

StaticResource.php 만 수정하고 추가하지 않고 원래 app / etc / di.xml을 유지하는 것 <item name="asset" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Copy</item> 입니까?
— LucScu

0

프로덕션 모드가 아닌 경우 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 파일을 삭제하지 마십시오.


1
나는 당신이 내 질문을 이해했다고 생각하지 않습니다. 나는 "복사"하고 싶지 않습니다. 제한된 서버 리소스로 공간을 절약하기 위해 "심 볼링"하고 싶습니다.
— 케빈 차베스
당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.