Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set imagesPublicPath in runtime #33

Closed
theallseingeye opened this issue Oct 2, 2018 · 2 comments
Closed

How to set imagesPublicPath in runtime #33

theallseingeye opened this issue Oct 2, 2018 · 2 comments

Comments

@theallseingeye
Copy link

Currently I can use

app.setAssetPrefix('http://cdn.com/myapp')

to set the assetPrefix for next.js files in runtime, that way I can reuse my build file for both staging and production environment

Is it possible to set imagesPublicPath in runtime too?

@cyrilwanner
Copy link
Owner

Hi @theallseingeye

This is unfortunately not possible out of the box with the current version. But the next major version of this plugin (which I'm currently working on) will use the same asset prefix as next does, so this will work in the future.

Until then, you can achieve the same with a bit more manual setup if you want to.

You could create a new file (e.g. images-prefix.js) which stores and exports the prefix in a variable and exposes a function to set this variable.
Then, everywhere you use an image, you can prefix the src with this variable, e.g.
<img src={imagesPrefix + require('./image.png')}>. Of course, you could also create a wrapper component which adds this prefix automatically for every image.

@avaleriani
Copy link

avaleriani commented Oct 15, 2020

hey @cyrilwanner has this been fixed? I'm trying canary.10 but it looks like it's not working when using the or component. Also src property type does not allow to concatenate the prefix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants