-
Notifications
You must be signed in to change notification settings - Fork 169
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
Custom helpers / custom handlebars library #3
Comments
I actually see https://github.com/altano/handlebars-loader#details about the helpers there, but can't figure it out. Can you provide an example how to use it? I'm trying to get this functionality incorporated into the template:
|
As you can tell from using this thing, it is basically almost completely untested. I used almost none of this functionality in my personal project. I just did very basic templating. I did some work to test these cases now, but not in proper unit tests. Let me know if you keep hitting issues and I'll keep trying to fix them. Fixed in 51f32d5 / v0.1.2 You need a module for the helper, e.g.: json.js
template.js
Due to how Handlebars parses the template, the helper has to be in the same directory as the template that references it. I know that sucks but I'm not sure how to workaround it. Let me know if it's a problem and I'll brainstorm some more. |
@sokra: regarding this comment I made:
Is there any chance you can make loader.resolve respect the "resolve" configuration option that webpack is using so I could solve the above problem? i.e. if someone sets resolve.fallback in webpack, loader.resolve should respect that? That makes sense conceptually, right? Thanks! |
@altano It should be this way. |
@altano, thanks man. I think it makes perfect sense to use them from the same folder as the template, but as you're saying, is there another way to setup a loader-specific option in resolve config or pass some params to the loader to say where it should look if it's not finding it there? Feels natural to have a separate folder for helpers and not use relative paths all over the templates. Maybe just pass query param? http://webpack.github.io/docs/using-loaders.html#query-parameters {
test: /\.hbs$/,
loader: "handlebars-loader"
query: { helpersDir: path(_dirname, '…') }
} |
@altano ok, I read your commit and I think I need to clarify what
I wouldn't redefine the meaning of |
@altano what do you think about this?
|
handlebars should be a peerDependency to fix this. |
v0.1.4 - 33f737e
@ianbytchek, let me know if there is anything left you need. |
And thanks for the help, @sokra. |
@altano the only thing that I still need is to thank you 😉 appreciate your help man. With regards to peer-dependency, it's definitely a x10 more flexible approach, but in real life when packaging for the web the project runtime dependencies would rather come from bower rather than npm. Is there a way we could pass an existing require name to depend on it, rather than using a build dependency? |
We could offer a query param to the runtime path, or you could use the NormalModuleReplacementPlugin to replace the original runtime with one of your choice. |
Sorry @ianbytchek, I'm very busy for a while and can't take care of that. Please feel free to either submit a pull-request that makes the runtime a query param or use the module replacement plugin suggestion above. |
Support for specifying a different runtime library path was added in #11 |
@altano commented on Mar 17 2014
Any thoughts?? |
Alan, thanks for putting this out. I remember seeing somewhere that custom helpers are not supported, but can't find that information now. Is this true?
Also, if I understand correctly, the loader pulls it's own copy of handlebars library and it kind of sucks that there's no way to use the dependency from the project. Is there any way to add that option into configuration? I'm not a guru on the subject, but something like configuring an alias in the main webpack.config and passing it to the loader to use instead of the default library would be fantastic.
The text was updated successfully, but these errors were encountered: