Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I did almost this exact thing all in a Cakefile using node modules as needed.</p> <p>Set some global variables that are arrays with the path of each file, concatenate those files into a file in the compiled directory that you specify, then compile that one file into js.</p> <p>For the styles, same thing with the concatenation without the compiling, obviously. </p> <pre><code>fs = require 'fs' path = require 'path' {spawn, exec} = require 'child_process' parser = require('uglify-js').parser uglify = require('uglify-js').uglify cleanCss = require 'clean-css' coffees = [ "/src/shared/file1.coffee" "/src/shared/file2.coffee" "/src/ipad/file1.coffee" ] tests = [ "/src/ipad/tests.coffee" ] styles = [ "/src/ipad/styles1.css" "/src/shared/styles2.css" ] concatenate = (destinationFile, files, type) -&gt; newContents = new Array remaining = files.length for file, index in files then do (file, index) -&gt; fs.readFile file, 'utf8', (err, fileContents) -&gt; throw err if err newContents[index] = fileContents if --remaining is 0 fs.writeFile destinationFile, newContents.join '\n\n', 'utf8', (err) -&gt; throw err if err if type is 'styles' minifyCss fileName else compileCoffee fileName compileCoffee = (file) -&gt; exec "coffee -c #{file}", (err) -&gt; throw err if err # delete coffee file leaving only js fs.unlink 'path/specifying/compiled_coffee', (err) -&gt; throw err if err minifyJs file minifyJs = (file) -&gt; fs.readFile f, 'utf8', (err, contents) -&gt; ast = parser.parse contents ast = uglify.ast_mangle ast ast = uglify.ast_squeeze ast minified = uglify.gen_code ast writeMinified file, minified writeMinified = (file, contents) -&gt; fs.writeFile file, contents, 'utf8', (err) -&gt; throw err if err minifyCss = (file) -&gt; fs.readFile file, 'utf8', (err, contents) -&gt; throw err if err minimized = cleanCss.process contents clean = minimized.replace 'app/assets', '' fs.writeFile file, clean, 'utf8', (err) -&gt; throw err if err task 'compile_coffees', 'concat, compile, and minify coffees', -&gt; concatenate '/compiled/ipad/code.coffee', coffees, 'coffee' task 'concat_styles', 'concat and minify styles', -&gt; concatenate '/compiled/ipad/css/styles.css', styles, 'styles' task 'compile_tests', 'concat, compile, and minify test', -&gt; concatenate '/compiled/ipad/tests.coffee', tests, 'tests' </code></pre> <p>Now this is roughly what I think you're asking for.</p> <p>Could definitely be prettier, especially having a separate function for writing the minified contents, but it works.</p> <p>Not perfect for the styles either because I was using Sass and had other functions before it hit the minified function, but I think you get the idea.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload