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

Requiring image in server app #77

Closed
joebanks10 opened this issue May 24, 2019 · 2 comments
Closed

Requiring image in server app #77

joebanks10 opened this issue May 24, 2019 · 2 comments

Comments

@joebanks10
Copy link

Is it possible to import/require an image in a server-side app? For instance, can you have require('static/myimg.jpg') in server.js` in this example: https://github.com/zeit/next.js/tree/canary/examples/custom-server-express

I'm specifically trying to import an image in an api endpoint and send the image data to my client-side app.

@joebanks10
Copy link
Author

@cyrilwanner
Copy link
Owner

This plugin is based on different webpack loaders. So, if you also build your server with webpack, it could work. But by default or when following the example you have linked, this is not the case and Next.js doesn't support building the server with webpack out of the box. So you would have to do that manually.

Another solution would be that you optimize the images with imagemin or another package on the server (the loader which this plugin uses also use imagemin). This would work without webpack, but maybe needs a few other adjustments.

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

2 participants