最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

compression - Compressing multiple JavaScript files with YUIcompressor? - Stack Overflow

programmeradmin0浏览0评论

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

I think that I'm getting the syntax wrong. I want to press all files in a directory that start with at_. However, when YUI Compressor runs, I find that YUI Compressor has placed only the pressed 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 pressed output of all three js files in at_min.js

I'm using the following syntax:

java -jar c:\Tools\yuipressor-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 pressed contents of at_1.js. What am I doing wrong?

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

I think that I'm getting the syntax wrong. I want to press all files in a directory that start with at_. However, when YUI Compressor runs, I find that YUI Compressor has placed only the pressed 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 pressed output of all three js files in at_min.js

I'm using the following syntax:

java -jar c:\Tools\yuipressor-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 pressed contents of at_1.js. What am I doing wrong?

Share Improve this question asked Sep 22, 2011 at 16:00 Vivian RiverVivian River 32.5k64 gold badges210 silver badges324 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

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

Or bining files before pressing with a simple mand:

copy /b at_1.js+at_2.js+at_3.js at_bined.js
java -jar c:\Tools\yuipressor-2.4.2.jar --type js --charset utf-8 -o at_min.js at_bined.js

I have written a small program to press multiple javascript files using yuipressor and node js.

var pressor = require('yuipressor');

//Compressor Options:
var pressorOptions = {

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;

    pressor.press(fileName, pressorOptions, 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);
发布评论

评论列表(0)

  1. 暂无评论