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
项目并使用支持资产的第一个策略。
如何使其在生产模式下工作?
免责声明:此hack包含核心文件编辑。谨防。
全部在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
并在浏览器中访问您的商店网址。