我在了解Yii2资产的合并和压缩方式时遇到了麻烦。我阅读了指南中的部分(http://www.yiiframework.com/doc-2.0/guide-structure-assets.html),但仍然无法使它起作用或至少不了解此事的基本知识。
从给出的示例中,我无法重现该问题并解决以下情况。
AppAsset包含应用程序的主要css / js。应该在此处包含共享的基本代码。这个依赖于另一个名为ExternalAssets的文件,该文件又依赖于YiiAsset,BootstrapAsset等。
CheckoutAsset包含仅与结帐过程相关的代码。上述内容也应包括在内,因为它添加了自定义功能,但仅与本节相关。$取决于AppAsset。
ProductViewAsset与上述相同,但与给定产品的可视化有关。
资产配置如下:
'bundles' => [
'yii\web\JqueryAsset',
'rmrevin\yii\fontawesome\AssetBundle',
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
'yii\bootstrap\BootstrapPluginAsset',
'yii\widgets\ActiveFormAsset',
'frontend\assets\ExternalAssets',
'frontend\assets\AppAsset',
],
'targets' => [
'app' => [
'class' => 'yii\web\AssetBundle',
'basePath' => '@webroot/assets',
'baseUrl' => '@web/assets',
'js' => 'js/app-{hash}.js',
'css' => 'css/app-{hash}.css',
'depends' => [ ],
],
]
Run Code Online (Sandbox Code Playgroud)
在这一点上,我可以压缩所有应该通用的内容(尽管可能会剥离一些不必要的文件),但是在使用ProductViewAsset或CheckoutAsset的页面中,其中包含的文件不会以相同的方式进行压缩。
也许可以在签出过程中将所有内容压缩到单个文件(公共数据+签出数据),或者可能不是由于缓存原因。不知道这是否可能,但我无法使其工作。据我所知。我尝试这样做是因为它看起来很自然,但是在尝试制作不同的资产捆绑包组时,我开始出现类似这样的错误,即PHP通知'yii \ base \ ErrorException'并显示消息'Undefined index:frontend \ assets \ ExternalAssets':
'targets' => [
'app' => [
'class' => 'yii\web\AssetBundle',
'basePath' => '@webroot/assets',
'baseUrl' => '@web/assets', …Run Code Online (Sandbox Code Playgroud)