This is probably a quick question. I'd like to run the YUI compressor so that, instead of overwriting all of the javascript files in the input directory, it dumps the output files into a subdirectory called min. I would like to do something like
java -jar yuicompressor-2.4.7.jar -o *.js .\min\*.js c:\MyJavascriptDirectory\*.*
but instead it just overwrites the existing files with the minified files. Does anyone know the correct syntax to accomplish this?
Thanks!
I'm not sure of the correct syntax to do that, but someone has made a modification so that you can set up your output directory as follows
java -jar yuicompressor.jar --output-dir /some/folder/for/compressed/js *js
This allows you to have a source folder and a compressed folder. As opposed to having source and a bunch of -min.js files in the same folder.
You can download the mod at the bottom of the page here http://yuilibrary.com/projects/yuicompressor/ticket/2528131
java -jar yuicompressor.jar -o '.js$:-min.js' *.js will minify all .js files and save them as -min.js then you could just move all those files: mkdir min; mv *-min.js min/.
Source
Related
I have multiple minified files in multiple folder in a single folder for minified js.
I wish to create single js file from all of minified js.
Now I am using type command to concatenate all files like
type .\\v2\\dist\\js\\*.js >> .\\build\\a.min.js && type .\\v2\\dist\\js\\config\\*.js >> .\\build\\a.min.js && ...
Like wise I need to append all recursive folders.
Is there any clean way to do it.
Please don't suggest using Gulp or Grunt as we are already in process of removing them & using Webpack. Any code using webpack or using npm or simple command line is welcome.
If on Windows, you can use command line like below (refer to #dbenham's answer):
for /r "c:\javascripts" %F in (*.js) do #type "%F" >>concatenated.js
If on Linux or Mac, you can use find:
find ./v2/dist/js/ -name '*.js' -exec cat {} \; > ./build/a.min.js
Is there a way to include files in a JavaScript file at "compile"-time in the source code? Basically what I'm looking for is a way to compile multiple files into one, without having to define the included files with the closure compile command.
As an example I'm using sass language to more precisely describe what I'm looking for;
# Sass file
# Include dimensions
#import "_dimensions.sass"
Edit
To clarify, comparably with the command;
java -jar compiler.jar --js file1.js file2.js main.js --js_output_file compiled_output.js
I was asking if there is a way to do these includes in code instead, so for example; If one file is called main.js, this file would itself include file1.js and file2.js by defining them in the source.
I have 2 js files: test1.js and test2.js. I want to minify it with yuicompressor to one file.
I tried:
./yuicompressor-2.4.7.jar --nomunge test1.js test2.js -o test3.js
But there is only one file in test3.js. How can i minify multiply files to one?
Thank you.
Merge them first using either:
copy and paste to a new file
script in the editor you're using collecting the file contents to a new file
use a file join command from command line or batch file
Then apply the the YUI compressor.
we have a problem at work, we are using require js but our folder structure is a bit different,
we have the following:
--js folder
--Folder
---some base js files
-Folder
---main
--src
---require.js
--- require JS modules
--plugin js files
--more js files
We would like to minify all these JS files to a SINGLe js file for production as such
---js folder
--min-all.js
Is this possible?
if so how? ..
Any help would be appreciated!
Thanks!
I just thought I would clarify that the other Folders contain standard non modular javascript files, they can be a mix of plugins or simple javascript helpers.
The short answer is: yes, RequireJS can do this.
Basically, you will need to create one JS file that requires all of the resources that you want minified. Then you will point the optimizer at that file and it will mash them all together.
require(["one", "../another/two", "folder/three", "folder/inner/four" ... ]);
If that file was called myfile.js, you would run the optimizer with similar parameters to this:
node r.js -o name=myfile out=optimized.js
If you have libraries or other files that you do not want included into the final optimized file, you would use the excludeShallow flag. e.g.
node r.js -o name=myfile out=optimized.js excludeShallow=jquery.min
There are more options so you should check out their optimization documentation if you haven't yet.
When I try to do build with steal/buildjs of Javascript MVC, envJS silently fail to compress and check JavaScript files for errors.
I read documentation for envJS and found there that if in some case you try to build empty .js files envJS will fail.
Obviously it is in my case, and later I founded some of empty .js files.
I need a way to add checking for empty .js and .ejs files before build.
What would be the most efficient way to do check for empty .js and .ejs when running steal/buildjs?
I would use find:
find . -type f \( -name *.js -o -name *.ejs \) -size 0 -print
Change -print to -delete when you're sure.