简体   繁体   中英

How to minify your nodejs project and delete the Comment?

I'm writing a Node.js project. How can I protect it for being copied or read? Are there any tools to minify/uglify/compress my nodejs code?

Should I use tools to turn the project into binary files so that the code can't be read?

I want to delete comments like this:

// i'm a comment  
/**
 * i'm another comment
 */

It looks like you're asking for a couple of things here:

  1. Something to remove comments from your source code
  2. Something to make it impossible to read the source code

Removing comments/reducing file size

Minification reduces source code file size by remove unnecessary indentation, semicolons, newlines, etc. It also removes all comments as they are not necessary for the code to function properly. javascript-obfuscator can help you out with this.

If you only want the comments removed (keeping indentation, newlines, etc.), I'd suggest using strip-comments .

Making code unreadable

The above options will reduce your source code size, but not make it unreadable. For that you have 2 options: a code obfuscator, or packaging your code into an executable (this has the added benefit of not requiring node on the target device).

Obfuscation makes your code difficult for a human to understand. However, will not guarantee that nobody can read your source code, as a determined person could theoretically reverse engineer the obfuscated code. If all you'd like is to deter someone through obfuscation, javascript-obfuscator can help you.

The best way to ensure your code is unreadable is to package it into an executable. This also will eliminate the need for the target device your code will run on to have node installed. pkg by Vercel is a good package for this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM