Can someone explain how Yii minimizing assets is supposed to work on Heroku?

浪尽此生 提交于 2019-12-23 01:41:58

问题


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?


回答1:


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"

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!

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' => 'yii\gii\Module'
] : [],


来源:https://stackoverflow.com/questions/30429928/can-someone-explain-how-yii-minimizing-assets-is-supposed-to-work-on-heroku

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!