Giter Club home page Giter Club logo

zsoltszabo / node-uglifier Goto Github PK

View Code? Open in Web Editor NEW
179.0 179.0 28.0 351 KB

Fully auto merging and obfuscating (uglify) a whole NodeJs project into one file with external files option. Thieves lose the module name and structure information, code runs faster. Makes deployement super easy! It can also separate a project's original files based on the dependency tree.

License: MIT License

JavaScript 77.52% HTML 8.00% CSS 0.16% CoffeeScript 14.32%

node-uglifier's People

Contributors

alecaste avatar laborzsolt avatar oogieboogieinjson avatar skia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-uglifier's Issues

throws requireStatements.each is not a function

If I run thru the below code its throws error, since the return is a object not a function. Can you explain why its not working?

[root@appserver]# cat index.js 
#!/usr/bin/env node
require('log-timestamp');
require('./boot/AppS/index.js').start();

Error

        requireStatements.each(function(o, i) {
                          ^

TypeError: requireStatements.each is not a function
    at recursiveSourceGrabber (/root/server/node_modules/node-uglifier/lib_compiled/NodeUglifier.js:153:27)
    at NodeUglifier.merge (/root/server/node_modules/node-uglifier/lib_compiled/NodeUglifier.js:232:7)
    at Object.<anonymous> (/root/server/index.js:5:35)
    at Module._compile (module.js:556:32)
    at Object.Module._extensions..js (module.js:565:10)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at Module.runMain (module.js:590:10)
    at run (bootstrap_node.js:394:7)

Sugar 2.0 update breaks the code

Sugar updated to version 2.0, methods like ".each" are now renamed ".forEach".

Possible fix are both bind the dependencies to 1.x or use the new methods.

Parse error when requiring json file

Just thought I'd leave a note. I assume this is because of a json file. If not, please disregard.

lib\app.js added to sources
lib\server.js added to sources
config.json added to sources

Error
    at new JS_Parse_Error (C:\Dev\desktop-master-service\node_modules\node-uglifier\node_modules\uglify-js\lib\parse.js:189:18)
    at js_error (C:\Dev\desktop-master-service\node_modules\node-uglifier\node_modules\uglify-js\lib\parse.js:197:11)
    at croak (C:\Dev\desktop-master-service\node_modules\node-uglifier\node_modules\uglify-js\lib\parse.js:657:9)
    at token_error (C:\Dev\desktop-master-service\node_modules\node-uglifier\node_modules\uglify-js\lib\parse.js:665:9)
    at unexpected (C:\Dev\desktop-master-service\node_modules\node-uglifier\node_modules\uglify-js\lib\parse.js:671:9)
    at semicolon (C:\Dev\desktop-master-service\node_modules\node-uglifier\node_modules\uglify-js\lib\parse.js:691:43)
    at simple_statement (C:\Dev\desktop-master-service\node_modules\node-uglifier\node_modules\uglify-js\lib\parse.js:865:73)
    at C:\Dev\desktop-master-service\node_modules\node-uglifier\node_modules\uglify-js\lib\parse.js:724:47
    at C:\Dev\desktop-master-service\node_modules\node-uglifier\node_modules\uglify-js\lib\parse.js:704:24
    at block_ (C:\Dev\desktop-master-service\node_modules\node-uglifier\node_modules\uglify-js\lib\parse.js:978:20)

cant seem to run it through mean stack

Hi,

Nice module. Tried it on simple console.log app and it works.

But seems like it does not work on a bigger project. Tried it on mean stack: https://github.com/meanjs/mean/zipball/master

it stops after adding a couple of sources:

processing main file: server.js
server.js added to sources 
config/init.js added to sources 
config/config.js added to sources 
config/env/all.js added to sources 

My code is:

var NodeUglifier = require("node-uglifier");
var mergedSource, uglifiedSource, nodeUglifier, uglifySourceMap;

uglifySourceMap = "resultFiles/sourcemaps.js";
nodeUglifier = new NodeUglifier("server.js");

mergedSource = nodeUglifier.merge();

uglifiedSource = mergedSource.uglify({
  strProtectionLvl: 1
}).toString();

nodeUglifier.exportToFile("resultFiles/server.compiled.js");
nodeUglifier.exportSourceMaps(uglifySourceMap);

How can I overcome this and continue on processing the other require modules

Include obfuscation

Whether or not 'protection through obfuscation' is a good thing, it does help against unsophisticated code thiefs.

Therefore I propose to add an .obfuscate() function to the chain, that maybe uses the javascript-obfuscator package. It could be run with its default options and, just like the .uglify() function, accept user options as well.

Obfuscation increases the size of the code, but since it's an extra function, it would be optional.

Thoughts?

Cannot read property 'toString' of undefined

When i try to uglify after the merge, i get this error:

/<directory>/node_modules/node-uglifier-es/lib_compiled/NodeUglifier.js:353
      return this.lastResult.source.toString();
                                    ^

TypeError: Cannot read property 'toString' of undefined
    at NodeUglifier.toString (/<directory>/node_modules/node-uglifier-es/lib_compiled/NodeUglifier.js:353:37)
    at NodeUglifier.exportToFile (/<directory>/node_modules/node-uglifier-es/lib_compiled/NodeUglifier.js:362:41)
    at Object.<anonymous> (/<directory>/buildServer.js:14:14)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Function.Module.runMain (module.js:684:10)
    at startup (bootstrap_node.js:187:16)

buildServer.js

const NodeUglifier = require("node-uglifier-es");
const nodeUglifier = new NodeUglifier("./server/index.js");
nodeUglifier.merge().uglify()

//exporting
nodeUglifier.exportToFile("./build/serverRelease.js");
nodeUglifier.exportSourceMaps("./build/sourcemaps/serverRelease.js");
//DONE

Any idea how to solve this? i really need my code to be uglifyed.
thank you very much for your support!

Support for uglify3.x

Since Harmony is also moved to uglify3.x now, node-uglifier does not work anymore. The API in 3.x is not backward compatible.

Any ETA on when node-uglifier will support uglify3.x?

Express routes don't work (once they are in a separate file)

Hi there,

Love your project.

I successfully compressed a very simple express test project. Here the layout:

app
-- router
---- router.js
-- node_modules
-- package.json
-- server.js
-- server_compiled.js

Here the content of the server.js

var express = require('express');
var app = express();
require('./router/router.js')(app);
app.listen(3000, function () {
  console.log('Example app listening on port 3000!');
});

and the content of router.js

module.exports = function(app) {
   app.get('/testroute', function (req, res) {
        res.send('Hello World!');
    });
};

If I run the uncompressed server.js I can reach the route but once the app is compressed and I run the server_compiled.js version I receive the "Cannot GET /testroute" messages as the route didn't exist:

Here the content of the server_compiled.js (beautified)

var cachedModules=[];
cachedModules[2977]={exports:{}},
    function(e,o){
        e.exports=function(e){
            e.get("/testroute",function(e,o){
                o.send("Hello World!")})
        }
    }.call(this,cachedModules[2977],cachedModules[2977].exports);
var express=require("express"), app=express();
cachedModules[2977].exports,
    app.listen(3e3,function(){
        console.log("Example app listening on port 3000!")
    });
//# sourceMappingURL=UGLIFY_SOURCE_MAP_TOKEN_

After seeing the uglyfied code it seemed the variable app didn't get passed to the module. After I changed the code by hand and added the app variable [exports(app)] to the compressed version the app worked as expected.

 ...
var express=require("express"), app=express();
cachedModules[2977].exports(app),
    app.listen(3e3,function(){
...

It would be great if you could fix that.

Cheers,
Tom

ES6 support

It's choking on ES6 syntax currently supported by node v4: `` strings, let keyword etc.

Add support to require a folder

Requiring a folder should load the index.js inside of the folder.

Current error output:

Warning!:
unhandled require type in file: [xxx]/build/index.js the problematic statement: require("./controllers/") probably something fancy going on the error: in file: [xxx]/build/index.js require for a directory not supported require("./controllers/")

Using source maps

My merged and uglified file works, but the sources in my generated sourcemap.map file is ["?"] - any idea what is causing this? And how do you recommend using this sourcemap to track down errors? Thanks very much, really appreciate your work on this excellent module!

Allow merge npm modules

At the moment, is there any option to also merge all npm dependencies into the output file?
Thanks

let context before the loop processed wrong way due to depreciated library uglify-js-harmony

Test source:

"use strict";

let a = 0;
for (let i = 0; i < 10; i++) {
  console.log("log");
}
console.log("final", a);

Output after node-uglifier:

var cachedModules=[];for(let a=0,i=0;10>i;i++)console.log("log");console.log("final",a);
//# sourceMappingURL=UGLIFY_SOURCE_MAP_TOKEN

So the source code works, but the output does not work.

Moreover:

Source:

'use strict';

var a = 0;
for (let i = 0; i < 10; i++) {
  console.log('log');
}
console.log('final', a);

Output:

var cachedModules=[];for(let a=0,i=0;10>i;i++)console.log("log");console.log("final",a);
//# sourceMappingURL=UGLIFY_SOURCE_MAP_TOKEN

Strange error if I add file with same syntax content as previous one

/home/yolo/yolo_rpi_server/mock/server/utils.js added to sources

undefined:1786
throw new JS_Parse_Error(message, filename, line, col, pos);
^
Error
at new JS_Parse_Error (eval at (/home/yolo/yolo_rpi_server/mock/server/node_modules/uglify-js-harmony/tools/node.js:22:1), :1778:18)
at js_error (eval at (/home/yolo/yolo_rpi_server/mock/server/node_modules/uglify-js-harmony/tools/node.js:22:1), :1786:11)
at croak (eval at (/home/yolo/yolo_rpi_server/mock/server/node_modules/uglify-js-harmony/tools/node.js:22:1), :2299:9)
at token_error (eval at (/home/yolo/yolo_rpi_server/mock/server/node_modules/uglify-js-harmony/tools/node.js:22:1), :2307:9)
at unexpected (eval at (/home/yolo/yolo_rpi_server/mock/server/node_modules/uglify-js-harmony/tools/node.js:22:1), :2313:9)
at block_ (eval at (/home/yolo/yolo_rpi_server/mock/server/node_modules/uglify-js-harmony/tools/node.js:22:1), :2708:28)
at function_body (eval at (/home/yolo/yolo_rpi_server/mock/server/node_modules/uglify-js-harmony/tools/node.js:22:1), :2682:21)
at function (eval at (/home/yolo/yolo_rpi_server/mock/server/node_modules/uglify-js-harmony/tools/node.js:22:1), :2636:20)
at expr_atom (eval at (/home/yolo/yolo_rpi_server/mock/server/node_modules/uglify-js-harmony/tools/node.js:22:1), :2968:24)
at maybe_unary (eval at (/home/yolo/yolo_rpi_server/mock/server/node_modules/uglify-js-harmony/tools/node.js:22:1), :3303:19)

Walking the directory

Express works with cash memory....
Instead of one file why not a packing list...
Scans app.js and pulls all files found....
I would like it to simply compress and ugly all files...
Like ejs client and also server require() not in the main package JSON .... EJS <=have SCRIPTS HTML and CSS

JSON array file would work..
Output a JSON packing list order of files.
You can view it and add or remove entry
Then run import JSON packing list
All done in rebuilding files where its converting variables.

TypeError: me.cycle.last is not a function

On this line of code

edgeToRemove = [me.cycle.last(2).last(), me.cycle.last(2).first()].reverse();

I can probably find the fix myself but I am not sure what was intended by [].last.
Where does that method come from? Native JS?

console.log(me.cycle); 
// [ '/home/ajax/repos/listium/Listium-web/es5-server/shared/scripts/Jsonify.js',
  '/home/ajax/repos/listium/Listium-web/es5-server/shared/scripts/ListTable.js' ]

'require' not always resolved correctly

the following require statement is not recognized by node-uglifier:

    var a=require("some-node-module").someFunction();

This works:

    var a=require("some-node-module");
    a=a.someFunction();

An example, where you want to do this, is the log4js module, for which you would do

var logger=require("log4js").getLogger();

Using Version 0.4.3 according to package.json. There seems to be a discrepancy between the actual npm version and the github version

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.