-
Notifications
You must be signed in to change notification settings - Fork 312
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
templateAdapter: avoid dynamic require if possible #394
base: master
Are you sure you want to change the base?
Conversation
Hey this is pretty interesting, can you post in the issues how you're trying to package this using webpack? Also, can you please add some tests for the code you added? Looks great overall, I like the simplicity of wrapping it in a function that can be overridden. |
Webpack has been working great for us since I opened this issue; and it also results in a 10% smaller bundle than browserify does - plus I feel I have a lot more control over it (admittedly after having to climb a pretty steep learning curve and monkey patching Rendr in a couple of places). Trimmed down webpack.config.js:
webpack-entry.js:
__layout.hbs:
|
After digging a bit more into webpack (so i can understand this stuffs) I'm not sure how this change is needed for webpack? is it simply for fixing the |
Nope, we don't use webpack when running in Node, only for the browser assets. This is required because without it webpack sees There may well be a better way of doing it, I'm a webpack newbie. |
heh - me too! i'll try poking around with using |
Hmm rather than passing in a string maybe we should pass an instance into the app creation for this instead? checkout: https://github.com/rendrjs/rendr/pull/447/files for an example |
@benjie and @saponifi3d it seems to me that dynamic requires and alias have been one of the major problems I have read about while improving/changing/upgrading rendr bundling. I wasn't able to create a browserify bundle with last browserify release due to alias mostly. |
@pjanuario +1, instead of crufting complex requiring logic, we can just provide simple mechanism of dependency injection. Instead of calling |
@benjie @pjanuario Now it's my turn to convert our huge Rendr app to webpack :) And it ain't easy task. I'm seeing similar warnings for other files:
|
@alexindigo haven't built it in webpack, but I have gotten it working fine in browserify - should be the same thing. Generally, it should just work in either environment. I'd recommend building the example app with webpack to get the config correct, then fix errors as they show up in your app. |
@saponifi3d Thanks. This is pretty much what I'm doing, small surface to big surface. From webpack we need on-demand loading, which is not as straightforward in browserify, and our desktop site switched to webpack already, so we don't have much say here. :) |
@saponifi3d @alexindigo i spent some quite time trying to update to lastest versions of browserify and the main reason why i put it on hold was related with the dynamic requires and alias since I mentioned before. I think @alexindigo suggestion to use dependency injection might be the best approach, but for that we need to change rendr core. Currently I am not spending that much time with rendr at the moment. |
@pjanuario thanks for the update. Yep, I'm in tight deadline at the moment, so will be hacking things in-place before submitting changes to upstream. |
Sorry I can't be much help; we moved off of rendr to react+react-router a long time ago (building our own rendr compatibility layers in the process to ease the transition - probably not that useful to others, alas, but if I recall correctly it only took about 3 days and a whole load of Vim macros despite the very large size of our codebase!). The warnings you see above are relatively harmless; it's probably from things like rendr requiring If you're interested I highly recommend using React in your Rendr stack as the rendering engine (rather than Backbone views); we did a presentation on it a couple years ago: http://timecounts.github.io/backbone-react-redux/#1 (Since then we've moved away from CoffeeScript to ES6 because CoffeeScript refuses to implement things like object splats and because ESLint is awesome compared to any of the offerings from the CoffeeScript community. We've also started implemented the "proper" way of doing React - i.e. using Flux instead of backbone models; this is a slow transition though so we've again got compatibility layers and use both flux and backbone in parallel in many places.) |
@benjie This is where are heading as well. Webpack being the first step. PS. I don't have much vim-macros fu, I'm more awk kind of guy, so we'll see. :) |
Okay, so this will be my last OT comment but I feel it's worth mentioning we've recently switched from webpack back to browserify because HMR on webpack was being too slow (due to this bug: webpack/webpack#1530). Since then Webpack have released 2.0 so maybe it's sorted now? My advice is to keep away from webpack-specific loaders (like style-loader) so that you can easily switch between webpack/browserify/rollup/whatever rather than being tied down. |
Cool thanks. I'll try to keep webpack for JS only things. PS. We really need on-demand loading and I couldn't figure it out with browserify. |
I thought I'd experiment with packaging Rendr under webpack. I've got around most issues with some method overriding but this one remains and a monkey-patch for it seems to be very heavy-handed. I believe the patch is clean enough to not break backwards compatibility. Note
templateAdapterModule
is now the module itself rather than its name.(In my code I'm overriding methods like
ModelUtils::fetchConstructor
,Router::getRouteBuilder
,Router::getAction
, andBaseView.getView
to do requires from my code rather than from Rendr's context.)