有人可以解释 Yii 最小化资产应该如何在 Heroku 上工作吗?
我刚刚完成了缩小工作(如何在 Heroku 上为 Yii 应用程序合并和缩小 JS 和 CSS?).但是,它会在 web/assets/
下创建 all-1bc649be34b1e6afc9b2419687cde016.js
文件.Yii 创建了一个 .gitignore
来忽略该目录中的所有内容.没有任何文件会进入 Heroku.即使我使用 heroku run yii asset assets.php config/assets-prod.php
它也只会创建 web dynos 无法访问的临时文件.(怀疑它在生产中确实失败了.CSS 不在那里!)缩小如何与 Heroku 一起工作?如果我更改文件会怎样?我是否必须再次手动运行 assets
命令?有没有办法让它自动?
I just got through getting the minification to work (How do I combine & minify JS and CSS for a Yii app on Heroku?) locally. However, it creates the all-1bc649be34b1e6afc9b2419687cde016.js
file under web/assets/
. Yii creates a .gitignore
to ignore everything in that directory. None of the files will make it to Heroku. Even if I use heroku run yii asset assets.php config/assets-prod.php
it will only create ephemeral files that are not accessible to the web dynos. (As suspected it does fail in production. The CSS is not there!) How does minification work with Heroku? What happens if I change a file? Do I have to manually run the assets
command again? Is there a way to make it automatic?
推荐答案
好的,我在 Heroku 文档中找到了这个 gem.https://devcenter.heroku.com/articles/php-support#custom-编译步骤.原来有一种方法可以在 Composer 的 composer.json
中指定一个命令,以便在 slug 编译期间运行.所以我加了
Ok I found this gem in Heroku docs. https://devcenter.heroku.com/articles/php-support#custom-compile-step. Turns out there is a way to specify a command in Composer's composer.json
to run during the slug compilation. So I added
"scripts": {
"compile": "php yii asset assets.php config/assets-prod.php"
并部署并自动生成缩小的资产!哇!这该死的 ----- 花了大约 10 个小时才开始工作 - 比它应该有的要多得多!
and deployed and it generated the minified assets automatically! Whew! This f----- took like 10 hours to get working - way more than it should have!
哦,我应该提到我必须破解 config/console.php
也为了让 yii
命令在 Heroku 上运行,因为它给出了关于 Gii 的错误.
Oh I should probably mention I had to hack config/console.php
also to get the yii
command to run on Heroku, because it gives an error about Gii.
'bootstrap' => YII_ENV == 'dev' ? ['log', 'gii'] : ['log'],
'modules' => YII_ENV == 'dev' ? [
'gii' => 'yiigiiModule'
] : [],
相关文章