-
Notifications
You must be signed in to change notification settings - Fork 181
Can't require images with webpack on the backend #59
Comments
@opportunato babel is not the problem here – you are trying to require an image directly from node, which doesn't work because you must require a js modules (indeed node is trying to read the JPG as javascript). In this case, just use the relative url: this.images.push('/assets/images/fb.jpg'); To make express to serve the content in import path from "path"
// snip...
const assetsDir = path.resolve(__dirname, "assets");
server.use("/assets", express.static(assetsDir, { maxAge: 365 * 24 * 60 * 60 } )); Note that i've set a this.images.push('/assets/images/fb.jpg?v=1.1'); |
After including this code in server.js, I've started getting this error:
Also, shouldn't every asset you require go through the webpack pipeline? Isn't it the main idea behind every build system? |
Yeah sorry there was a misplaced parenthesis in the middleware, I've updated my comment :) anyway check the express documentation for serving static files. As for the build thing, there's no need to build the server-side code: webpack here is used only to build the files that run on the client. In your case, your |
Thank you very much, everything is clear now! |
I've been using your template (which is great, btw) for my own project, and have run into some issues with the images. So, I am trying to include image from the meta, and I want it to be served by webpack. To make this happen, I am doing something like this in HtmlHeadStore:
Unfortunately, I am getting this error:
Here is my dev webpack loaders config:
I've found similar issue here, but I don't understand why babel could be the issue, since it should ignore files without .js extensions.
What could be my problem?
The text was updated successfully, but these errors were encountered: