I want to create a compiled JavaScript file for my website. For development, I would prefer to keep the JavaScript in separate files and just as part of my automated scripts merge the files into one and run the compressor over it.
my problem is that if i use the old DOS copy command, it also puts the EOF tokens that the compressor complains about:
copy /A *.in JS compile.js / Y
What do other people do?
I recommend using Apache Ant and the Yui compressor.
http://ant.apache.org/
http://yui.github.com/yuicompressor/
Put something like this in the xml build of Ant. It will create two files, application.js and application-min.js.
<target name="concatenate" description="Concatenate all js files">
<concat destfile="build/application.js">
<fileset dir="src/js" includes="*.js" />
</concat>
</target>
<target name="compress" depends="concatenate" description="Compress application.js to application-min.js">
<apply executable="java" parallel="false">
<filelist dir="build" files="application.js" />
<arg line="-jar" />
<arg path="path/to/yuicompressor-2.4.2.jar" />
<srcfile />
<arg line="-o" />
<mapper type="glob" from="*.js" to="build/*-min.js" />
<targetfile />
</apply>
</target>
use binary mode to copy without EOF:
copy /B *.js compiled.js /Y
If the resulting file still has proofs, it could be from one of the source files, this can be fixed with this option:
copy /A *.js compiled.js /B /Y
/a removes the final proofs from the source files, if any, and /B prevents EOF from being added to the resulting file. If EOF is not at the end, the source file will be truncated in it. The order of the switches is important. If you write
copy /A *.js /B compiled.js /Y
The proof in the source files will not be removed, but the resulting EOF will still not be added.