-
Notifications
You must be signed in to change notification settings - Fork 507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide an easy way to remove minification #310
Comments
at a minimum i’m happy to take a documentation pr with those exact keywords. im always wary of adding a new flag because of flag sprawl, so that can be a separate discussion. |
@tychota current version already have --minify option |
@ambroseus I'm not seeing any "minify" related CLI arguments for the https://github.com/formium/tsdx/blob/569c3ed36863d0cbe3f869f397d1852beefd8d5d/src/index.ts#L363 I see the following in the Rollup config section you link to, but 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.
If anyone else knows how to disable minification or can point to something that documents it that'd be appreciated. Thanks! |
@techieshark could you elaborate on your use case for disabling minification? A workaround was provided by OP using
There isn't one, though 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
It isn't, that's something you can use inside of your
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 |
@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 the |
@agilgur5 can't remove the 'use strict'
if (process.env.NODE_ENV === 'production') {
module.exports = require('./my-library.cjs.production.min.js')
} else {
module.exports = require('./my-library.cjs.development.js')
} Correct? |
Run into the exact same problem with NestJS and Swagger, but the real issue is that the minify process renames the class to "m" or "u" or any other letter: (exports.CreateDepartamentoDto = u),
(exports.CreateFueroDto = m),
(exports.UpdateDepartamentoDto = g),
(exports.UpdateFueroDto = l); The issue is with the compressing and mangling of the function names, which I managed to disable like this: // Remove terser plugin
config.plugins = config.plugins.filter(plugin => plugin.name !== 'terser');
// Add it again, with `keep_fnames` option set to true and the default options found on
// https://github.com/jaredpalmer/tsdx/blob/master/src/createRollupConfig.ts#L214.
config.plugins.push(
terser({
output: { comments: false },
compress: {
keep_infinity: true,
pure_getters: true,
keep_fnames: true,
passes: 10,
},
ecma: opts.legacy ? 5 : 2020,
module: isEsm,
toplevel: opts.format === 'cjs' || isEsm,
warnings: true,
mangle: {
keep_fnames: true,
},
}),
); This could be improved by getting the original plugin and overwriting the desired options, but it seems like it cannot be done because it only exposes a { name: 'terser', renderChunk: [Function: renderChunk] } |
Current Behavior
Currently, TSDX (v0.9, couldn't upgrade to 0.10 due to various problems already reported) behavior concerning minification is:
The impact on me is the following.
When building a NestJS, the swagger looks like this.
💩
There is an issue for
Terser
mangle options: #136There is also a possibility to use the new "tsdx.config.js" to remove the plugin
But that is not easy to do and undocumented
Desired Behavior
An easy and documented way to disable minification.
Suggested Solution
--minify false
to nest CLII will be super happy to contribute with a PR if you agree on the expected behavior
Who does this impact? Who is this for?
Describe alternatives you've considered
As stated in Current Behavior:
The text was updated successfully, but these errors were encountered: