Can someone explain how Yii minimizing assets is s

2019-06-06 18:27发布

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条回答
做自己的国王
2楼-- · 2019-06-06 19:15

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'
] : [],
查看更多
登录 后发表回答