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 2.1.4 (styles-m.css ถูกสร้างขึ้นและไฟล์อื่น ๆ มี symlinked)
ความมหัศจรรย์ทั้งหมดเกิดขึ้นใน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
ไอเท็มและใช้ stategy แรกที่รองรับสินทรัพย์
วิธีทำให้มันใช้งานได้ในโหมดการผลิต
คำเตือน:แฮ็คนี้มีการแก้ไขไฟล์หลัก ระวัง.
ทดสอบทั้งหมดใน magento 2.1.4
- ลบหมายเลขรุ่นจากไฟล์คงที่ใน
Stores > Configuration > Advanced > Developer > Static Files Settings > No
แก้ไข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;
}
ลบเนื้อหาpub/static
และเยี่ยมชม URL ร้านค้าของคุณในเบราว์เซอร์