Provide an easy way to remove minification
See original GitHub issueCurrent 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.
💩
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:
- Created 4 years ago
- Reactions:5
- Comments:7 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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.
@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.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 using0
instead offalse
because it’s not an official option and so it isn’t parsed; it only works becauseBoolean(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.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
:I’ve modified
output.file
here as well, but it would be prudent to note thatoutput.file
will be substituted withoutput.dir
andoutput.entryFileNames
in v0.15.0 with #367, so it’s not quite stable either.