0

I have a couchapp with the following structure in the _attachments directory:

_attachments/
|-- code
|   |-- model.js
|   |-- primary.js
|   |-- router.js
|   `-- view.js
|-- index.html
`-- style
    `-- main.css

When I run couchapp push, I want all the files in _attachments/code (or any arbitrary directory within _attachments) to be combined into a single file that I can reference in _attachments/code/index.html. It would be helpful to specify an order of files within a directory.

There is a couchapp hook available to compress files, but I don't see an easy way to combine them, especially since that may mean outputting some intermediate file, ensuring the original files don't get uploaded, and cleaning up.

Is a hook to combine files the best way, and if so, how would you recommend it work?

tephyr
  • 1,001
  • 2
  • 14
  • 26

1 Answers1

0

I'm afraid I don't know of a couchapp hook to do that, but you can achieve something similar by using the modules package in Kanso. It will load commonjs modules from directories, attach them to the design doc and then combine them into a single .js file you can include in your app. It can minify the code for you too.

You can see the modules package in use here: http://kan.so/docs/Using_CommonJS_modules

Basically, you just point it at the directory containing your JS modules, then:

<script src="modules.js"></script>

Of course, this would mean writing your JavaScript as CommonJS modules, but I find that preferable to messing with the global namespace from multiple scripts.

Caolan
  • 3,909
  • 1
  • 18
  • 8
  • I am hoping to get couchapp to do the work, rather than adding another dependency, but at least Kanso already solves the problem. Thanks for the pointer. – tephyr Jan 30 '12 at 17:12