bootstrap 字体的 Yii2 BaseUrl
Yii2 BaseUrl for bootstrap fonts
我需要你们的帮助。我更改了所有资产的目录。它工作正常,但不适用于 bootstrap 字体。
例如:css 和 js 文件的路径现在是 project/www/web_assets/all.css
并且 Yii2 正确地找到了它们。
但它不适用于字体。 Yii2 正在寻找错误的字体 /var/www/tt_yii/web/assets/582582f3/fonts/glyphicons-halflings-regular.woff2
。
Bootstrap 被用在不同的地方。它已经由 BootstrapAsset 默认配置,并且是其他预定义资产的依赖项。但您可以覆盖默认位置。
假设您在 web_assets
中的文件结构与在 'vendor/bower-asset/bootstrap/dist' 中的文件结构相同(包含文件夹 css、字体和 js),您可以将以下内容添加到您的组件中配置:
use yii\bootstrap\BootstrapAsset;
...
'components' => [
...
'assetManager' => [
'bundles' => [
BootstrapAsset::class => [
'sourcePath' => null,
'baseUrl' => '@web/web_assets',
],
]
],
...
],
@web
指向 index.php 和您的 web_assets
目录文件也应该存在的 Web 文件夹。 sourcePath
设置为空,因为不会计算 baseUrl。
有关配置所用捆绑包的更多信息,请参见 AssetManager::$bundles or in the guide。
类似的问题是。
检查你的 nginx 设置。如果有文件类型列表,您还应该将这些字体类型插入其中:
location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar|eot|svg|ttf|woff|woff2)$
(bootstrap icon fonts not loading 的副本)
我需要你们的帮助。我更改了所有资产的目录。它工作正常,但不适用于 bootstrap 字体。
例如:css 和 js 文件的路径现在是 project/www/web_assets/all.css
并且 Yii2 正确地找到了它们。
但它不适用于字体。 Yii2 正在寻找错误的字体 /var/www/tt_yii/web/assets/582582f3/fonts/glyphicons-halflings-regular.woff2
。
Bootstrap 被用在不同的地方。它已经由 BootstrapAsset 默认配置,并且是其他预定义资产的依赖项。但您可以覆盖默认位置。
假设您在 web_assets
中的文件结构与在 'vendor/bower-asset/bootstrap/dist' 中的文件结构相同(包含文件夹 css、字体和 js),您可以将以下内容添加到您的组件中配置:
use yii\bootstrap\BootstrapAsset;
...
'components' => [
...
'assetManager' => [
'bundles' => [
BootstrapAsset::class => [
'sourcePath' => null,
'baseUrl' => '@web/web_assets',
],
]
],
...
],
@web
指向 index.php 和您的 web_assets
目录文件也应该存在的 Web 文件夹。 sourcePath
设置为空,因为不会计算 baseUrl。
有关配置所用捆绑包的更多信息,请参见 AssetManager::$bundles or in the guide。
类似的问题是
检查你的 nginx 设置。如果有文件类型列表,您还应该将这些字体类型插入其中:
location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar|eot|svg|ttf|woff|woff2)$
(bootstrap icon fonts not loading 的副本)