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

Image Requires #4

Open
tomatau opened this issue Oct 11, 2015 · 17 comments
Open

Image Requires #4

tomatau opened this issue Oct 11, 2015 · 17 comments
Labels

Comments

@tomatau
Copy link

tomatau commented Oct 11, 2015

Nice work on this example, really interesting!

Experimenting locally and I can't find a solution for universal image requires using this setup.

I've worked with WebpackIsomorphicLoader to solve this problem but the css-modules-require-hook seems so elegant, is there an approach similar to this for getting generated image filenames from a require?

@glenjamin
Copy link
Owner

I've never used image loading via require myself - but hopefully someone else can chime in with an answer!

@adri
Copy link
Contributor

adri commented Oct 13, 2015

https://github.com/petehunt/webpack-require looks interesting. If this works we could ditch the css-modules-require-hook. @tomatau What do you think?

@adri
Copy link
Contributor

adri commented Oct 13, 2015

The css-modules-require-hook is nice but a bit limited to only providing css-modules. Would be nice to just reuse the same webpack config actually.

@glenjamin
Copy link
Owner

It's possible to build a webpack bundle for the server and require that, but it does take a bit longer to apply the change.

See webpack-contrib/webpack-hot-middleware#1 for an example

@tomatau
Copy link
Author

tomatau commented Oct 15, 2015

@adri Personally I've been attempting to use import from or the standard require where possible and avoiding custom require functions.

https://github.com/halt-hammerzeit/webpack-isomorphic-tools has allowed me to do this quite comfortably although the module filter function for some assets can get a little messy. It supports one webpack config for both client and server compile and can be extended for more asset types.

@adri
Copy link
Contributor

adri commented Oct 16, 2015

@tomatau Thanks! I integrated webpack-isomorphic-tools in the ultimate-hot-reloading-example and it works well for loading assets, also with css-modules. It also allows us to only use webpack for client and server rendering which is very neat.

There is only one issue left before I could make a pull request. When there was an error while parsing a file (for example a CSS file) the node process seems to not respond anymore. Not sure yet why. master...adri:webpack-isomorphic-tools

@adri
Copy link
Contributor

adri commented Oct 16, 2015

Did anyone of you experience problems that the node process gets stuck after a syntax error in the parsed code using webpack? I'm not sure how to debug it.

PS: Got hot reloading working with external connections like databases. Thats another pull request.

@adri
Copy link
Contributor

adri commented Oct 17, 2015

Found the issue. catamphetamine/webpack-isomorphic-tools#6

@tomatau
Copy link
Author

tomatau commented Oct 17, 2015

nice work @adri 👍

@tomatau
Copy link
Author

tomatau commented Nov 3, 2015

I've built a react & redux universal starter-kit/boilerplate heavily based on the examples of this repo along with universal image handling.

Check it out:
https://github.com/tomatau/breko-hub

Thanks again for this repo, it's been great to learn from whilst building that ^

@adri
Copy link
Contributor

adri commented Nov 3, 2015

I'm experimenting now with running mocha tests after clearing the require caches, all in the same process.
Pretty sweet so far.

@tomatau
Copy link
Author

tomatau commented Nov 3, 2015

@adri can you share? I'm looking to add test runners to breko-hub so would be interesting to look at your setup

@adri
Copy link
Contributor

adri commented Nov 3, 2015

Yeah https://gist.github.com/adri/7d5127d03ce5ba3e7531#file-hotreload-js-L59
At the moment it is only one test, I'll add a glob soon – it's still 'in development'.

@kevinsimper
Copy link

There is a module like css-require 😄

https://www.npmjs.com/package/images-require-hook

@tomatau
Copy link
Author

tomatau commented Oct 27, 2017

I've been using this https://github.com/tomatau/node-hook-filename

Works for any require type and allows you to specify how to deal with the file.

@kevinsimper
Copy link

@tomatau nice and do you have an example that would fit into this repo?

@tomatau
Copy link
Author

tomatau commented Oct 27, 2017

I use it in my boilerplate when running tests

https://github.com/tomatau/breko-hub/blob/master/test/node-setup.js#L20

I use webpack-isomorphic-tools for images on the server render though

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

No branches or pull requests

4 participants