CodeKit-1-Old icon indicating copy to clipboard operation
CodeKit-1-Old copied to clipboard

Feature Request: JS and CoffeeScript imports

Open Fresheyeball opened this issue 12 years ago • 16 comments

I would really like to auto combine and minify compiled coffeeScript output with existing js files.

Fresheyeball avatar Apr 28 '12 06:04 Fresheyeball

It's particular useful in cases where you're depending on non-coffeescript libraries like backbone.

koen-serry avatar May 16 '12 14:05 koen-serry

@koen-serry for the time being I've been adding them as .coffee files containing javascript. Works well enough for the moment.

Fresheyeball avatar May 16 '12 15:05 Fresheyeball

Sorry I'm quite new to CodeKit, how do you do that?

koen-serry avatar May 16 '12 16:05 koen-serry

It's not a CodeKit thing, its a coffeescript thing. CoffeeScript lets you use normal JavaScript so long as its between tick marks . Check the documentation here http://coffeescript.org/#embedded . So I make a blank .coffee file and then do an embed of the js I need to include. That was I can include js into coffee compiles.

Fresheyeball avatar May 16 '12 16:05 Fresheyeball

+1 for the original feature request.

The trick @Fresheyeball suggested is cool, but I don't like having to modify other libraries just to use CoffeeScript.

petebrowne avatar Jun 29 '12 12:06 petebrowne

+1 for the original feature request

lifeiscontent avatar Nov 20 '12 00:11 lifeiscontent

Hi guys, this is already possible.

All you need to do is use an "@codekit-prepend/append" statement in your Javascript file to bring in the compiled output of your CoffeeScript file.

So, we have "fileC.coffee" that compiles to "fileC.js". Then, we have another Javascript file named "main.js". We just append/prepend "fileC.js" into "main.js".

Whenever you compile the CoffeeScript file, CodeKit will automatically re-process "main.js" so that it captures the changes.

bdkjones avatar Nov 20 '12 01:11 bdkjones

@bdkjones hmmm.... you are right. It is possible, but that doesn't really address the feature request. Lets say the desired result is something like this inside a .coffee file:

#@codekit-prepend 'basefile.coffee' #@codekit-prepend 'ajsliberary.js' #@codekit-prepend 'dependentClass.coffee'

Now I either have resolve to have codekit compile every coffeescript file and manage dependencies in a .js file instead, which means the number of files in the application nearly doubles. Or manage cascades of growing complexity. Being able to @codekit-prepend .js files directly alongside .coffee files would offer alot of value to me for application management.

What I am doing now, turning my .js files into .coffee files by surrounding those files as embedded js. is working and more manageable than cascading coffee to js to js again.

But the problem with converting js to embedded js in coffee, is that the files cannot update from git if they come from opensource. And my IDE detects them as .coffee and does not code hint or syntax highlight the js, making working with the two formats side by side abit cumbersome. Lastly co workers, who prefer to complete their tasks in js, means I have an additional step to include it in my final compiled output.

Fresheyeball avatar Nov 20 '12 17:11 Fresheyeball

I agree that the current method is not ideal. But there are some technical details involved in implementing what you propose that I just haven't tackled yet. I do want to get to this state at some point, though.

bdkjones avatar Nov 20 '12 17:11 bdkjones

@bdkjones rock on.

Fresheyeball avatar Nov 20 '12 17:11 Fresheyeball

@bdkjones while I got you here, I was considering writing an eclipse or sublime text pluggin to recognize @codekit-prepends for purpose of code hinting. But I'm not sure how to go about it yet. Would you be interested in participating?

Fresheyeball avatar Nov 20 '12 17:11 Fresheyeball

I'm afraid I can't right now; I've got my hands full just updating CodeKit. I have some great stuff planned for the next few months! But thanks!

bdkjones avatar Nov 20 '12 17:11 bdkjones

+1 for original request.

bokkagroup avatar Mar 21 '13 17:03 bokkagroup

I recently learned that snockets on nodejs does this. Perhaps there is something in there that can be reused, perhaps not.

Fresheyeball avatar Mar 21 '13 17:03 Fresheyeball

Can it be that the solution that @bdkjones suggests does not work in Maverick?

I have a similar javascript.coffeescript setup and codekit doesn't detect any changed in the compiled output of my coffeescript files. Every time when I updated one of my coffeescript, I have to compile my main.js by hand to bring everything together.

slimndap avatar Dec 03 '13 21:12 slimndap

Sorry, I found another open issue #667 dealing with this.

slimndap avatar Dec 03 '13 21:12 slimndap