Question

In Rails, we can use variable and function in js files with extension .js.erb like that

# application.js.erb
var env = "<%= Rails.env%>";
var imageUrl = "<%= asset_path('favicon.png')%>";

Is there any way to use them in js files for Nodejs.

I have imageUrl in js files and these images were uploaded in amazon s3 through express-cdn, and want to use CDN(asset_path) function in that files.

Était-ce utile?

La solution

Yes. You can checkout asset-smasher lib for this. We are doing the same in our project which is a migration of rails project.

We use something like application.js.ejs which is converted to application.js after asset-smashing.

You can specify custom helper functions like ImageUrl etc while smashing.

https://github.com/jriecken/asset-smasher

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top