6

I'm trying to compress multiple JS files using the YUI Compressor.

I think that I'm getting the syntax wrong. I want to compress all files in a directory that start with at_. However, when YUI Compressor runs, I find that YUI Compressor has placed only the compressed version of one file in the output.

To be specific, suppose I have three files: at_1.js, at_2.js, and at_3.js. I would like the compressed output of all three js files in at_min.js

I'm using the following syntax:

java -jar c:\Tools\yuicompressor-2.4.2.jar --type js --charset utf-8 -o c:\temp\at_min.js c:\temp\scripts\at_*

When I open up at_min.js, I find only the compressed contents of at_1.js. What am I doing wrong?

2 Answers 2

5

If you are using Windows you can use YUI Compressor for .Net to do that.

Or combining files before compressing with a simple command:

copy /b at_1.js+at_2.js+at_3.js at_combined.js
java -jar c:\Tools\yuicompressor-2.4.2.jar --type js --charset utf-8 -o at_min.js at_combined.js
Sign up to request clarification or add additional context in comments.

Comments

0

I have written a small program to compress multiple javascript files using yuicompressor and node js.

var compressor = require('yuicompressor');

//Compressor Options:
var compressorOptions = {

charset: 'utf8',
type: 'js',
nomunge: false
}

/* List of files and file path. Just replace the file names and path with yours */
    var file = [{
    "path": "assets/www/modules/eApp/controllers/",
    "type": "js",
    "name": ["BuyOnlineController", "CustomerDetailsController", "DashboardController", "DashboardListingController", "DocumentUploadController", "HomeController", "KYCDetailsController", "PaymentAcknowledgementController", "PaymentController", "ProductListingController", "ReviewAndAcceptanceController"]
},
{
    "path": "assets/www/modules/login/controllers/",
    "type": "js",
    "name": ["EappLoginController", "InboxController", "LandingController", "LoginController", "MenuController", "MyAccountController", "SyncForEappController"]
},
{
    "path": "assets/www/lib/vendor/general/",
    "type": "js",
    "name": ["overlays"]
}];

function minify(i, j){
    i = (i == undefined) ? 0 : i;
    j = (j == undefined) ? 0 : j;
    filePath = file[i].path;
    fileType = file[i].type;
    name = file[i].name[j];
    fileName = filePath+name+"."+fileType;
    minifiedFileName = filePath+name+".min."+fileType;

    if(j == file[i].name.length - 1){
        i += 1;
        j = 0;
    }
    else
        j += 1;

    compressor.compress(fileName, compressorOptions, function(err, data, extra) {
        var fs = require('fs');
        fs.writeFile(minifiedFileName, data, function(err) {
            if(err) {
                console.log(err);
            } else {
                console.log("The file "+minifiedFileName+" was saved successfully!");
                if(i != file.length)
                    minify(i, j);

            }
        }); 
    }); 


}

minify(0,0);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.