geowarin / boot-react

A starter application with spring boot and react

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Static Assets (for example: Images)

nullsumme opened this issue · comments

Hey,

Thanks a lot for this great "starter" application. Since I'm very new to all of this I have a small quastion:
What do we need to add so we can access static files like images?

Okay, looks like for development we can use something like this:

app.use('/images', express.static(__dirname + '/assets/images'));

The best way IMHO is to use the URL loader of webpack.
I pushed a branch demoing that (requiring the image)

This way, you will have all your assets passed through webpack. You can do many types of optimizations from here.

With your method, keep in mind that you will also have to figure out a way to put the images in the public directory of the application's jar in prod. It can be as simple as simply putting them here in the first place.

Thanks for the reply.
With this way I can access the files via webpack, thats fine. But what can I do if i need the image for some CSS stuff like 'background: url()?

This should automatically work: see the section about urls of the css loader.

Perfect! You are right, it works just like that.
Thanks a lot.