app/etc/di.xml: thêm mục mới vào 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>
Giả sử bạn đang ở chế độ nhà phát triển, chỉ cần xóa nội dung của pub/static và truy cập trang của bạn trong trình duyệt - magento sẽ tạo lại nội dung tĩnh.
làm việc cho tôi trong Magento 2.1.4 (style-m.css đã được tạo và các tệp khác được liên kết với nhau).
tất cả các phép thuật xảy ra trong 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 chỉ vòng qua stategiesListcác vật phẩm và sử dụng chiến lược đầu tiên hỗ trợ tài sản.
Làm thế nào để làm cho nó hoạt động trong chế độ sản xuất?
Tuyên bố từ chối trách nhiệm: hack này chứa chỉnh sửa tập tin cốt lõi. coi chừng
tất cả đã được thử nghiệm trên magento 2.1.4
- xóa số phiên bản khỏi tệp tĩnh trong
Stores > Configuration > Advanced > Developer > Static Files Settings > No
chỉnh sửa vendor/magento/framework/App/StaticResource.phpvà làm cho launchchức năng trông như thế này:
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;
}
xóa nội dung pub/staticvà truy cập url cửa hàng của bạn trong trình duyệt.