Script file concatenation for better code organization #127

Open
danielgtaylor opened this Issue Oct 16, 2013 · 11 comments

Comments

Projects
None yet
@danielgtaylor

It would be nice to have a way to easily concatenate scripts so that you can split your js/coffee code into multiple files. How I would like to organize my code:

- main.js
| - main.coffee
| - users.coffee
| - utils.coffee
script(src="/main.js")

What I currently have to do:

script(src="/main.js/utils.js")
script(src="/main.js/users.js")
script(src="/main.js/main.js")

It looks like sprockets uses a special comment for this purpose:

#= include file.coffee

https://github.com/sstephenson/sprockets#the-include-directive

What are the chances of getting some kind of script preprocessing to allow this? It could potentially also be done with special folder names or JSON data files, so I'm not 100% set in the comment directive, it's just an idea. For example, any folder name that ends in .js could concatenate all files within it (but how do we manage order?).

@kennethormandy

This comment has been minimized.

Show comment
Hide comment
Collaborator

kennethormandy commented Oct 17, 2013

@drhayes

This comment has been minimized.

Show comment
Hide comment
@drhayes

drhayes Oct 19, 2013

+1 for browserify! I like Brian's idea of how to set it up.

drhayes commented Oct 19, 2013

+1 for browserify! I like Brian's idea of how to set it up.

@edrex

This comment has been minimized.

Show comment
Hide comment
@edrex

edrex Oct 29, 2013

Contributor

+1 for Browserify, es muy elegante

not sure about the whole smart directory thing, it doesn't add any new capability vs the leading _ convention combined with Browserify (appeal to orthogonality)

Contributor

edrex commented Oct 29, 2013

+1 for Browserify, es muy elegante

not sure about the whole smart directory thing, it doesn't add any new capability vs the leading _ convention combined with Browserify (appeal to orthogonality)

@z5h

This comment has been minimized.

Show comment
Hide comment
@z5h

z5h Nov 25, 2013

I've hacked something like this together.
See: #165
which references my example:
https://github.com/z5h/harp-start

z5h commented Nov 25, 2013

I've hacked something like this together.
See: #165
which references my example:
https://github.com/z5h/harp-start

@ncammarata

This comment has been minimized.

Show comment
Hide comment
@ncammarata

ncammarata Dec 4, 2013

I'd just like to post that this is the one real feature that's making me switch to Grunt at the moment. Was using Harp but had way too many JS includes in my HTML.

I'd just like to post that this is the one real feature that's making me switch to Grunt at the moment. Was using Harp but had way too many JS includes in my HTML.

@ncammarata

This comment has been minimized.

Show comment
Hide comment
@ncammarata

ncammarata Jan 28, 2014

Any update on this?

Any update on this?

@johanhalse

This comment has been minimized.

Show comment
Hide comment
@johanhalse

johanhalse Feb 17, 2014

I've worked around this: I use Harp as a node library and wrap it with a concatenation step. I've opted for a simple solution, but I'm sure it can be done more elegantly to track changes in JS too. Me, I'm lazy and use nodemon :)

I've worked around this: I use Harp as a node library and wrap it with a concatenation step. I've opted for a simple solution, but I'm sure it can be done more elegantly to track changes in JS too. Me, I'm lazy and use nodemon :)

@zeke

This comment has been minimized.

Show comment
Hide comment
@zeke

zeke Feb 18, 2014

Contributor

Browserify is an awesome and elegant way to solve this concatenation problem, and would be a great step for bringing browserify to a larger audience. I added a scrappy pull request to terraform enabling browserify support for coffee files: sintaxi/terraform#33

cc @brianleroux

Contributor

zeke commented Feb 18, 2014

Browserify is an awesome and elegant way to solve this concatenation problem, and would be a great step for bringing browserify to a larger audience. I added a scrappy pull request to terraform enabling browserify support for coffee files: sintaxi/terraform#33

cc @brianleroux

@thesmart

This comment has been minimized.

Show comment
Hide comment
@thesmart

thesmart May 15, 2015

Maybe I'm a bit late to the party, but I started writing a partial solution to this issue. One can specify a .man manifest file with the JavaScript and CoffeeScript files and folders they want included. I hope this is useful to others:
sintaxi/terraform@master...thesmart:master

We're using this in production now and it's been great!

Maybe I'm a bit late to the party, but I started writing a partial solution to this issue. One can specify a .man manifest file with the JavaScript and CoffeeScript files and folders they want included. I hope this is useful to others:
sintaxi/terraform@master...thesmart:master

We're using this in production now and it's been great!

@edinchez

This comment has been minimized.

Show comment
Hide comment
@edinchez

edinchez Sep 14, 2016

Has this not been implemented yet?

Has this not been implemented yet?

@temoto

This comment has been minimized.

Show comment
Hide comment
@temoto

temoto Sep 20, 2016

Please do this.

temoto commented Sep 20, 2016

Please do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment