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アイテムをループし、アセットをサポートする最初のステートジーを使用します。
プロダクションモードで機能させるにはどうすればよいですか?
免責事項:このハックにはコアファイルの編集が含まれます。注意してください。
すべて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にアクセスします。