-
Notifications
You must be signed in to change notification settings - Fork 77
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
Add CJS option #19
Add CJS option #19
Conversation
I want to support this, but I think we need to discuss the option naming in general for this task. The possible combinations of cjs/client/amd/namespace seem a bit messy. Any thoughts on how to handle this? |
My thoughts: a single |
How about a Can anyone explain to me the point of the namespace property? Why is it there? |
If you compile multiple templates to a single file, |
A |
@OliverJAsh would you be game for attempting to implement this as a helper in grunt-lib-contrib? I'd like to add support for this across all of our plugins if we're going to do it. Eventually, we'll be able to allow chaining output through multiple tasks, obviating the need for this sort of ad-hoc solution, but it's a ways off. |
@tkellen I had a shot at implementing the API described above by @sindresorhus. I hope I'm heading in the right direction here… If I am, let me know and I'll try to abstract some of the |
@OliverJAsh It looks to me like you're headed in the right direction. I haven't thought this through completely, but the helper I have in mind would take the compiled template string, the mode, and perhaps the namespace as arguments and return the correct contents. That way we can re-use this logic across all of our templating tasks. Basically, this is a stopgap solution until we can pipe data between tasks (at which point we'd just have like, a single cjs wrapping task that could be part of any task pipeline). |
@tkellen What do you think? |
… template to string
So the formatting for templates has been abstracted to |
Sorry, it's been a crazy day here. I'll check on this further tomorrow Oliver. Thanks for taking the time to put this first draft together. |
@OliverJAsh I think it's fine to have this task do some wrapping internally in addition to what has been generalized out to lib-contrib. There is still a big win in being able to share the common case across multiple tasks. |
ping @OliverJAsh the changes to lib-contrib are live, if you want to move forward with this |
@tkellen As far as I can tell, I have made the necessary changes to this task. Can you tell me what's missing? I can't see what can be done about the wrappers. |
@mereskin Can you explain why |
@tkellen This instruction is an assumption, that module, defined as |
I can read the code--I'm asking why it is necessary. |
@tkellen On the server requirejs("jade") returns I would agree that AMD config is a better place for that. |
@OliverJAsh We can remove the additional wrapping stuff. Would you be willing to do that? If so, I think we're all set! |
ping @OliverJAsh |
@tkellen You want me to remove all of this wrapping code? I'm confused. Without this, AMD will not work, and CommonJS will not work if the namespace option is set. We still need the wrappers. I think I misunderstand — please explain. I'm not really sure how you would like me to move forward from here. |
I apologize for being so obscure--I haven't had the time to properly engage on this issue and I don't see that changing in the near future. The idea is to have as much of the wrapping code come from a shared method (formatForType in grunt-lib-contrib) as possible. We do this exact stuff on numerous templating tasks. This is basically a hack to make things consistent across grunt-contrib until we can pass tasks through a pipeline a-la http://github.com/node-task/spec Per our discussion above, this code is not needed at all: https://github.com/OliverJAsh/grunt-contrib-jade/blob/master/tasks/jade.js#L95 Here is a really rough sketch of what I'm thinking. formatForType({
string: template value here,
type: 'amd' | 'commonjs' | 'js' | 'html' | 'whatever',
namespace: 'namespace'
filename: 'filename',
header: "define(['blah'], function(blah) {",
footer: "});"
}); If that isn't clear enough, please rebase this PR and I'll just merge it and move on--I don't have the bandwidth to champion getting this implemented :( |
That's much clearer, thank you. I will give this a shot sometime in the next week, if that's okay. I shan't forget, though! |
perhaps we wouldn't even need header/footer and could instead have a list of dependencies like formatForType{{
...
deps: {
handlebars: 'Handlebars',
jade: 'jade',
}
}); ...which could expand out to load deps like |
Thanks Oliver! |
ping @OliverJAsh :) |
@tkellen As far as I can tell, there is still an issue with the implementation you propose. This code runs for every template (where This code runs for every file: https://github.com/OliverJAsh/grunt-contrib-jade/blob/patch-1/tasks/jade.js#L85-107 Thus, there are two places where the formatting needs to take place, and I'm failing to see how this can be achieved in a single sweep. Hence why I've stumbled and stopped where I have. Maybe it would be a good idea to list what all of the possibilites are. I have:
The items in bold are the ones which need formatting per file as well as per template. Can you see why formatting needs to happen in two places? Sorry for the poor correspondence. Up until yesterday I was final year university student. |
@OliverJAsh This code: https://github.com/OliverJAsh/grunt-contrib-jade/blob/patch-1/tasks/jade.js#L85-107 can be removed per this comment: #19 (comment) No worries about the slow reply--I'm swamped here too. |
@tkellen Can you respond to my issues that I posted previously? Otherwise I think I'm no good here anymore. |
+1 This should really be something in this package. Or is there any known workaround till this feature is implemented? |
Sorry for the double post but here is a question I would like to ask about this feature: There is a option in the code called Is this different form what is asked for here? Is it a good workaround for now? And is the options.node not documented on the README.md on purpose? Thanks. |
This is a long running PR and looks like sadly it won't get merged. We are still looking for the best way to either have a single module that takes care of CJS wrappers for all contrib plugins or at least something that is common between the plugins that takes care of such wrapping. |
No description provided.