-14

This is my question How to uglify the source code of the whole NextJS project?.

Here is my point of view. I would like to uglify my source code following the provided criteria. Any solutions are acceptable. The best one gets to be the accepted answer. I do not, in any way, ask for recommendations for any books, tools, software libraries, and more (I don't know what "more" may include though). Basically, I just want to know how to do just that regardless of the method used. It could be tools, yes. It could be other ways.

However, the question is closed as seeking recommendations. I would like to know if this is justified.

6
  • 1
    From what I understand Next JS optimizes the code for production which includes minimizing, name mangling etc. when you build it. What more are you specifically looking for when you say uglify? Commented Oct 6, 2023 at 4:09
  • @AbdulAzizBarkat Can we have a discussion in chat? I would like to know some specifics about it.
    – holydragon
    Commented Oct 6, 2023 at 4:16
  • I am not an SME on Next.js, what I am stating is what I've read in the documentation: nextjs.org/learn/foundations/how-nextjs-works/minifying from what I understand minimizing is the default configuration. Commented Oct 6, 2023 at 4:21
  • Is this something like obfuscation?
    – user13267
    Commented Oct 6, 2023 at 5:08
  • @user13267 "uglify" is a tool that does code minification for JavaScript. Its purpose is not obfuscation, although the code does end up harder to read. There are dedicated obfuscators that do try and protect the code from scrutiny, however the uglify tool is not that. With that said, it's unclear what exactly OP means by the verb "uglify" here, as perhaps it isn't minification but actual obfuscation of the code. Moreover, if it's the former, it's unclear what's lacking - as Abdul Aziz Barkat pointed out, minification comes built in with Next.js
    – VLAZ
    Commented Oct 6, 2023 at 6:24
  • Next.js is itself a collection of technologies, these kind of tasks generally fall to the bundler which is Turbopack judging from the front page: turbo.build . So first stage: look what plugins it has. Judging from its documentation, it supports Webpack loaders. That is pretty smart since there are tons of those already. There really isn't a reason why the question has to take a form of "I don't know, you do it and I'll pick the best one". I can fully understand this is treated as a seeking recommendations, I'm not sure if the flag was really intended for this scenario though.
    – Gimby
    Commented Oct 6, 2023 at 8:37

2 Answers 2

15

Basically, I just want to know how to do just that regardless of the method used. It could be tools, yes. It could be other ways.

Anything that doesn't use a tool is impractical. If you had explicitly specified that you want to know how to write code for the task, I would have voted to close as "Needs More Focus".

We do not design or implement entire program features here. Simply saying that you want to "uglify" the code doesn't unambiguously specify the program behaviour; and any reasonable interpretation will include multiple steps for separate kinds of things to change in the input code (renaming variables, altering syntactical structures, adding filler etc., each of which could be broken down further and done in any number of ways).

2
  • So, if I edit my question to specify the tool that I want to use and the behavior I want it to change the code, the question can be reopened?
    – holydragon
    Commented Oct 6, 2023 at 3:47
  • 9
    Possibly. I would recommend that, after choosing a tool and code-changing behaviours, you read the documentation and try to figure it out, and see where you get stuck in order to ask a more specific, focused question. Commented Oct 6, 2023 at 3:49
16

I understand the "seeking recommendations" close vote, however, I would have gone with "Needs details or clarity".

I would like to uglify the whole source code of the project

It is not exactly clear what you mean by that:

  • Do you want to minify the code to make it more compact? This usually leaves it harder to read as well but the purpose of minification is not to attempt to hide code.
  • Do you want to obfuscate the code to make it harder to examine? This involves automated re-writing of the code to introduce more control structures and make understanding it harder.

Both end up with the code being "uglier", so which one is it?

There is a further reason why this is not clear: there is a tool for JavaScript code called uglify. A reasonable interpretation of your question is "I want to have a tool that does the same as the uglify too" thus I would be inclined to read your question as seeking to minify the code.

The problem with this interpretation is that Next.js already ships with a built-in minification capability. Thus if you are asking for a tool to minify the source code, I do not understand why Next.js is not sufficient already. Is it not doing it to a sufficient degree? Is the minification from Next.js not fit for your purpose?

Overall, I feel there is missing information in the question. The "seeking recommendations" is probably a red herring in this case. I would expect the question to explain more. For example "I use Next.js and I need result X and Y which I currently do not get when I build the project like this . Here is the toolchain I use ."

1
  • By "uglify", I used it as a verb to mean obfuscate because I didn't know what term to use at that moment. If the question is closed as "Needs details or clarity", I would indeed happy to clarify it. I was just confused a little bit being "seeking recommendations", but Karl Knechtel explained it to me. So, I'm satisfied now.
    – holydragon
    Commented Oct 6, 2023 at 6:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .