Code Monkey home page Code Monkey logo

Comments (17)

srod avatar srod commented on May 25, 2024

Is java installed ?

java -version

And can you provided me some code to test ?

Thanks.

from node-minify.

joseph-jja avatar joseph-jja commented on May 25, 2024

Basically I have a grunt task that has this.files setup. So you end up with something like this:

this.filesforEach( function ( f ) {
    var i, slen;
    slen = f.src.length;
    for ( i = 0; i < slen; i += 1 ) {
        // pseudo filter
        if ( f.src[ i ].indexOf( "min.js" ) === -1 ) {
            fname = f.src[ i ].replace( /^src\//, '' );

            // copy source file
            grunt.file.copy( f.src[ i ], destOut + fname );

            // create minified dest file 
            if ( minDest === '' ) {
                minFileOut = destOut + fname.replace( ".js", "-min.js" );
            } else {
                minFileOut = minDest + fname;
            }

            compress( destOut + fname, minFileOut, type );
        }
    }

and then the compress function is below.

function compress( sourceFile, destFile, type ) {

var comp;

function errorHandler( error, min ) {

    if ( error ) {
        grunt.log.warn( error, min );
        return;
    }
    grunt.log.writeln( 'File `' + destFile + '` created.' );
    // Let Grunt know the asynchronous task has completed
    return;
}

try {
    comp = new Compressor.minify( {
        'type': type,
        'fileIn': sourceFile,
        'fileOut': destFile,
        'callback': errorHandler
    } );
} catch ( e ) {
    grunt.log.error( 'File `' + destFile + '` NOT created. ' + e );
}

}

from node-minify.

srod avatar srod commented on May 25, 2024

I tried in a simple grunt task :

module.exports = function (grunt) {
    'use strict';

    grunt.initConfig({
        minify: {
            options: {},
            files:  []
        }
    });

    grunt.registerMultiTask('minify', 'compress files', function() {
        var compressor = require('node-minify');

        function errorHandler( error, min ) {

            if ( error ) {
                grunt.log.warn( error, min );
                return;
            }
            //grunt.log.writeln( 'File `' + destFile + '` created.' );
            // Let Grunt know the asynchronous task has completed
            return;
        }

        try {
            var comp = new compressor.minify( {
                'type': 'yui-js',
                'fileIn': 'pm.share.js',
                'fileOut': 'pm.share-min.js',
                'callback': errorHandler
            } );
        } catch ( e ) {
            console.log(e);
            //grunt.log.error( 'File `' + destFile + '` NOT created. ' + e );
        }
    });

    grunt.registerTask('default', ['minify']);
};

It's working with that.
Can you give me the values of your 3 variables ? sourceFile, destFile, type

from node-minify.

joseph-jja avatar joseph-jja commented on May 25, 2024

type: is "yui-js"
sourceFile is a js file under src, destFile is that file copied over to target/classes

from node-minify.

joseph-jja avatar joseph-jja commented on May 25, 2024

Hmm I wonder if this is a mac thing? I ran your code and it does nothing on my mac.

from node-minify.

srod avatar srod commented on May 25, 2024

I'm on mac too.
Put that code in a Gruntfile.js
Then npm install grunt node-minify
And run "grunt".
Also change fileIn and fileOut values.

from node-minify.

joseph-jja avatar joseph-jja commented on May 25, 2024

Ok, I updated the plugin and yui-js still does not work, but uglifyjs does.

from node-minify.

joseph-jja avatar joseph-jja commented on May 25, 2024

Ok, well uglify-js works and I can mangle variable names so I will just move forward with uglify-js. Also uglify-js seems smaller with the -m option.

from node-minify.

srod avatar srod commented on May 25, 2024

So, this is related to java.
What version are you using ?

from node-minify.

joseph-jja avatar joseph-jja commented on May 25, 2024

I think java 6, but it may be 7. Does that make a difference?

from node-minify.

srod avatar srod commented on May 25, 2024

I tried on both, it's the same.

from node-minify.

joseph-jja avatar joseph-jja commented on May 25, 2024

64 or 32 bit? I have

java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

from node-minify.

srod avatar srod commented on May 25, 2024

64 bits for me too.
Have you try yui from the command line ?
Here an exemple :

java -jar /path/to/yuicompressor-2.4.8.jar /path/to/filetocompress.js -o /path/to/output.js --type js

You can download yui : https://github.com/yui/yuicompressor/releases

from node-minify.

joseph-jja avatar joseph-jja commented on May 25, 2024

Ok, I've published the plugin I am working on, it is located here: https://github.com/joseph-jja/grunt-minify-each. It works fine with uglify, but has issues with yui-js. If you want to look at it and see any issues, let me know why it might not work with yui-js.

from node-minify.

srod avatar srod commented on May 25, 2024

I found why it's not working in your plugin.
This is because of parameters you passed : "--max-line-len=10000 --lift-vars -m"
These are not recognized by yui compressor, but only uglifyjs.
With an empty parameters, it's ok : "parameters: []"

from node-minify.

joseph-jja avatar joseph-jja commented on May 25, 2024

I removed those and still it does not work for me. Must be something else on my system. Some other setting. For certain files I get messages about spawn EMFILE so I have to set ulimit each time

from node-minify.

srod avatar srod commented on May 25, 2024

Yes, that must be that, it's ok for me with an empty parameters.
Try to test on another system.

from node-minify.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.