coffeescript-concat icon indicating copy to clipboard operation
coffeescript-concat copied to clipboard

Specific position for requires

Open B7th opened this issue 9 years ago • 4 comments

For a node project, I would like to have my index.coffee file using to do like such:

#= require <vendor>
#= require <functions>
(($) ->
  #= require <form-elements>
  #= require <main-site>
) jQuery

Unfortunately, instead of going where I expect them to go, they end up at the top of the file - which is the programmed intended action, but not what I am looking for.

I would like to be able not to always write the ready function for all files.

Is there a way to compile/concat coffeescript that can put included files at specific positions, say inside a function?

B7th avatar Mar 12 '16 19:03 B7th

Hi B7th, I want to make sure I understand your use case:

You want to build your coffeescript into javascript in single javascript file that will be run by node? What prevents you from using the build in node require and just compiling the files separately?

In any case, there isn't functionality for this currently. I'd consider adding something like

#= require-local <form-elements>

To be a decent solution. It would not be all that hard to add, though you'd probably want to restructure the "find dependencies -> concat files" flow to concatenate as you go for the local dependencies.

I'm probably not going to be able to work on this, but I'd be more than happy to offer help if you're interested in building it.

fairfieldt avatar Mar 16 '16 00:03 fairfieldt

Sorry for the awfully long responding time.

I am currently looking at the code and will try to find a solution that would concatenate code at the position of #= require . Thank you for offering your help, I will certainly need it at some point ^^

B7th avatar Aug 13 '16 11:08 B7th

I'd be very interested in this as well. Stuck on the same problem. I want to be able to load specifiy coffee files at specific locations in my master coffee file. @B7th any progress on a solution for this?

MyXoToD avatar Sep 07 '16 11:09 MyXoToD

I haven't looked at it lately, been cut up in life a bit, but I already worked on a DRYer version of the code, and the solution actually seems quite simple: Embedded text must level itself to the context of its inclusion. Right?

B7th avatar Sep 07 '16 18:09 B7th