question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide an easy way to remove minification

See original GitHub issue

Current Behavior

Currently, TSDX (v0.9, couldn’t upgrade to 0.10 due to various problems already reported) behavior concerning minification is:

if (opts.minify !== null && opts.minify !== null) { 
 // respect the set option
} else {
 switch (process.env.NODE_ENV) {
  case "PRODUCTION":
    opts.minify = true;
    break;
  defaut:
    opts.minify = false
  }
}

// later
if (opts.minify) {
  plugins.add(new Terser({});
}

The impact on me is the following. When building a NestJS, the swagger looks like this.

image 💩

There is an issue for Terser mangle options: #136

There is also a possibility to use the new “tsdx.config.js” to remove the plugin

// Not transpiled with TypeScript or Babel, so use plain Es6/Node.js!
module.exports = {
  // This function will run for each entry/format/env combination
  rollup(config, options) {
    config.plugins = config.plugins.filter(plugin => plugin.name !== 'terser');
    return config; // always return a config.
  },
};

But that is not easy to do and undocumented

Desired Behavior

An easy and documented way to disable minification.

Suggested Solution

  • Add --minify false to nest CLI
  • Add documentation in the main README.md

I will be super happy to contribute with a PR if you agree on the expected behavior

Who does this impact? Who is this for?

  • Me 😃 And my team
  • all user wanting to remove minification, such as nestjs user

Describe alternatives you’ve considered

As stated in Current Behavior:

  • #136
  • tsdx.config.js

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:5
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
techiesharkcommented, Oct 23, 2020

@agilgur5 thanks for the explanation! And the clever hack. Very helpful. 😃

I was actually using tsdx to build a little Node/TS service for cloud deployment, and wanted to turn off minification because doing so would have made cloud-based debugging a bit easier/quicker. I later realized there was also the unminified development file, so that helped too.

2reactions
agilgur5commented, Oct 25, 2020

@techieshark could you elaborate on your use case for disabling minification? A workaround was provided by OP using tsdx.config.js and #136 is possible via that route as well. If others still want this for other use-cases, I’d like to know what those are to shape decisions.

I’m not seeing any “minify” related CLI arguments for the tsdx build command:

There isn’t one, though tsdx build --minify=0 unintentionally works due to this line of code: https://github.com/formium/tsdx/blob/6c5da7444b7db006c9e3ec932006528b367bcd59/src/createRollupConfig.ts#L37 Notably, I’m using 0 instead of false because it’s not an official option and so it isn’t parsed; it only works because Boolean(0) === false

That’s quite hacky and relies on that line not changing and the fact that options get passed all the way through the CLI via sade even if they’re not explicitly defined, so I’m not sure I’d recommend that (but if an official flag is created, it may use that same name), but it does work.

if that’s supposed to be a way to turn off minification, it’s not clear (to me anyway, from those docs) how to do so.

It isn’t, that’s something you can use inside of your tsdx.config.js to tell if the current bundle being generated will be minified and write your own conditional around that. For instance, modifying OP’s workaround:

tsdx.config.js:

module.exports = {
  rollup(config, options) {
    if (options.minify) {
      // disable Terser's minification
      config.plugins = config.plugins.filter(plugin => plugin.name !== 'terser');
      // remove `.min` suffix since we're no longer minifying
      config.output.file = config.output.file.replace('.min', '');
    }
    return config;
  },
};

I’ve modified output.file here as well, but it would be prudent to note that output.file will be substituted with output.dir and output.entryFileNames in v0.15.0 with #367, so it’s not quite stable either.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ASP.NET Bundles how to disable minification - Stack Overflow
You can turn off minification in your bundles simply by Clearing your transforms. var scriptBundle = ...
Read more >
Unminify JS, CSS, HTML, XML and JSON Code
This tool will unminify, reformat and reindent ugly JavaScript, CSS, HTML, XML and JSON code, making it readable again.
Read more >
What is Minification | Why minify JS, HTML, CSS files - Imperva
To minify JS, CSS and HTML files, comments and extra spaces need to be removed, as well as crunch variable names so as...
Read more >
Minify Resources (HTML, CSS, and JavaScript)
Minification refers to the process of removing unnecessary or redundant data without affecting how the resource is processed by the browser ...
Read more >
How to Minify JavaScript — Recommended Tools and ... - Kinsta
You can input a .js file, provide an URL or directly paste your raw code to the TutorialsPoint JavaScript minifier tool. The tool...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found