Can I use Bower and Rails on Heroku and save the bower_components directory from GIT?

I just started working with bower for client-side dependency management. I installed Bower to install all the files in /vendor/assets/components .

Then I run bower install to evaluate the bower.json file and install all the dependencies

 #/bower.json { "name": "My-App", "dependencies": { "angular": "1.0.8", "bootstrap": "3.0.0" } } 

Finally, in accordance with the instructions that I read, I deleted the component directory from GIT.

 #.gitignore #... # Ignore all stuff manged by bower /vendor/assets/components 

Thus, the project does not include any of these assets in slug and requires bower install run to bower install them.

It seems reasonable to me in the same way that decoupling the real gems from the project is reasonable. It also adheres to the principles of a 12-factor application and explicitly declares and isolates dependencies.

However, the exception of dependencies causes the compilation of assets to throttle ...

However, when I click on Heroku, pre-compilation of the assets fails because the asssets have not been added yet, and therefore, when the asterisks try to evaluate:

 #application.css.scss /* ... *= require bootstrap/dist/css/bootstrap *= require_self *= require_tree . */ 

he found that nothing was found in bootstrap/dist/css/bootstrap because bower hadn't installed anything yet.

Possible solution - use package.json to run post-install script

I followed this tutorial , which suggests adding a package.json file with the following contents:

 "dependencies": { "bower": "0.6.x" }, "scripts": { "postinstall": "./node_modules/bower/bin/bower install" } 

However, bower install does not need to be run as a post-install script, but after-push compilation of the script. I also wonder if Heroku will run the npm pre-processor for a Rails application

Is it better to figure out how to start a bower installation or just include files in GIT?

There are two solutions. The first and easiest is to simply run bower install locally and include the files in GIT. This is not a biggie, but I would like to adhere to the principles of the 12 Factor App.

The second solution is to figure out how to start npm and run bower install on Heroku before the resources are pre-compiled.

Is this viable in some easy way, or is it better to just compile the database assets locally?

Postscript

In conclusion, I just had to run bower install locally and include the files in GIT. Despite the fact that 12-factor principles suggest that this may not be the right route, I did not consider that it had any costs on it, and would rather have delved into the complexity of complex custom buildpacks.

+6
source share
1 answer

You should try ddollar multi-buildpack . When installing two buildpacks, you get the added benefit of being able to run the postinstall script after installing nodejs, but before ruby ​​buildpack is installed. This will allow you to tear down your assets with bower install before they are precompiled.

I put together a leak that tells how to handle the Heroku + Rails + Bower script.

https://coderwall.com/p/6bmygq

+3
source

Source: https://habr.com/ru/post/956567/


All Articles