-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
importing images #39
Comments
I've got it working, but only via css |
I can't get it to work with server side rendering too, any progress? |
Right, that was the problem. I'd forgotten Because you can't just wrap it in an |
Thanks, it's a temporary solution, but not a good idea since the Server-side code is discarded and the images start to load only if the of JS files were loaded. |
Maybe it's a problem of Babel. |
https://github.com/iam4x/isomorphic-flux-boilerplate/blob/master/app/utils/image-resolver.js import imageResolver from 'utils/image-resolver'
let image;
// On browser just require() the image as usual
if (process.env.BROWSER) {
image = require('images/logo.png');
}
else {
image = imageResolver('images/logo.png');
}
...
render () {
return (
<img src={image} />
);
}
... |
Just a thought, and it's also related to #48 |
@leonli Possibly. |
PR #66 sent. Implemented the solution I talked above. 😄 |
Still get issues with home page logo image rendering. The server markup isn't matching client markup, specifically because of the logo image. image.assets[0] is |
Good catch. I'm seeing that too. Will investigate. |
May I ask why this is not a circular reference? Since the requireServerImage/Css requires webpack-stats.json and the compilation of webpack-stats.json based on the files include requireServerImage/Css. React-hot-loader refreshes constantly in my repo if I require requireServerImage in the Components. |
@huangdawei It sort of is, but the circle is broken with the file system (it loads |
* master: (21 commits) improved syntax for including styles fixed #77 added apology for #60 in the README linted url-loader fix for images switched back to file-loader to avoid error from requireServerImage() fixes #39 Works on mac now Added better-npm-run to allow setting env-vars on all platforms fixed cat pic on server render minor grammar and js style tweak to README added url-loader to production webpack, too merged PR #67. lint-corrected merge. added obligatory cat pic. changed to use url-loader to encode small images. made pass lint incorporated PR #67 and added some comments to promise chaining in createTransitionHook() util import should be in single line. correct the , to , sorry for my keyboard. remove a space :P update README. correct the util error :P add the image server render example to the logo.png. ...
* master: (32 commits) fixed npm script problem and upgraded redux-form added form support with redux-form npm knows how to prefix binaries oops, left in debugger call improved syntax for including styles fixed #77 added apology for #60 in the README linted url-loader fix for images switched back to file-loader to avoid error from requireServerImage() fixes #39 Works on mac now Added better-npm-run to allow setting env-vars on all platforms fixed cat pic on server render minor grammar and js style tweak to README added url-loader to production webpack, too merged PR #67. lint-corrected merge. added obligatory cat pic. changed to use url-loader to encode small images. made pass lint incorporated PR #67 and added some comments to promise chaining in createTransitionHook() work on forms work on forms ...
I am also having circular builds in my project (but not having circular builds in the example).
But if I do the same in my project's entry point it immediately says that testing.json is not found. |
My solition to this issue: And it eliminates the initial build issue:
Still webpack outputs the green stats chart two times in a row - currently don't know why is the second time. |
Or one could write require('image') without differentiating between the client and the server and instrument all server require calls like coffeescript does through require("coffeescript/register"). |
Ok, I made these
and it works both on the client and on the server. I refactored the relevant code into a separate npm module in case someone needs that: |
That looks awesome!! Can I get a PR to implement it here? |
@erikras yeah, I think, I might do that. maybe in a week or two. cheers |
It would certainly warrant a place on the list of libraries making this project awesome in the README. |
@erikras oh, so tempting) okay, I'm on it |
@erikras So, I managed to integrate the two things together. I checked it on my machine and it seems to be working. By the way, http://127.0.0.1:3000/survey doesn't work on my machine, looks like there is an unrelated bug |
The survey thing was a package.json problem. A pull should fix. |
One little clarifying comment: We could have wrote it like this (and left it like this)
And it worked fine but if you changed the required file somehow it wouldn't update (the hash would be recalculated for the required file by webpack because it watches all the assets and rereuns the build process, and stats.json would be updated and re-loaded inside the express rendering middleware because of the |
A follow-up, for everyone's information |
How do you get this to work using universal-webpack? |
@brendanmh by studying |
@halt-hammerzeit can you give me a hint as to what part of the readme is relevant? I have been following the readme and have many other things working, but not being able to import images and css from my components. (Sidenote: I am also looking for a work-around for undefined window) |
@brendanmh the most relevant parts of the readme are the first ones. |
The advertisement or motivation section? |
Oh, better look somewhere in the middle then. |
Thanks for getting back to me so quickly. I trust that this exchange will be useful for other devs struggling with this problem. |
By the way, when you're finished setting up the whole thing you can write some sort of a detailed blog post explaining the process so that it "will be useful for other devs struggling with this problem". |
Has anyone got importing images with webpack working? For me it seems to break server render.
The text was updated successfully, but these errors were encountered: