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
Uglify terser #243
Uglify terser #243
Conversation
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"metro-minify-uglify": "^0.45.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Version needs to be hard set - e.g. remove the "^" - node CI tests should be good after this. 👍
inputMap?: ?BabelSourceMap, | ||
filename: string, | ||
options?: MinifyOptions, | ||
) => ResultWithMap; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing terser
param type definition as 5th arg.
type MinifierWithoutSourceMap = ( | ||
code: string, | ||
options?: MinifyOptions, | ||
) => ResultWithoutMap; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing terser
param type definition as 3rd arg.
@@ -23,17 +23,19 @@ import type {BabelSourceMap} from '@babel/core'; | |||
function noSourceMap( | |||
code: string, | |||
options?: MinifyOptions = {}, | |||
uglifyModule: ?Object, | |||
): ResultWithoutMap { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Types need updating here to add the extra uglifyModule
arg.
} | ||
|
||
function withSourceMap( | ||
code: string, | ||
sourceMap: ?BabelSourceMap, | ||
filename: string, | ||
options?: MinifyOptions = {}, | ||
uglifyModule: ?Object, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Types need updating here to add the extra uglifyModule
arg.
This is great @haggholm! Thank you, Terser is a great minifier to have available! I believe that we already have a configuration option to give a custom minifier to metro (https://github.com/facebook/metro/blob/master/packages/metro-config/src/defaults/index.js#L79). I think it would make most sense to add Does that make sense? I can also take a stab at this if that's okay with you! |
The reason I made it a parameter is that the alternative is to literally duplicate the code of I suppose an arguably cleaner way would be to have some sort of I don’t really care too much ;) – after all I’m not a maintainer! I just wanted to keep it DRY. But I’ll happily do either one: (a) the way I first did it, (b) making A fourth alternative (d) might be to add a different option: keep just But either way, let me know which way you’d like it to go and I’ll gladly contribute it. (Or, obviously, if you’d rather do it, that’s fine—I just want to use |
Hi @haggholm ! Thanks for the contribution! We're indeed exploring using As @CompuIves mentioned, it would be better to make I agree that this means some duplication currently, but we are also going to simplify the API of the minifier so it'll only need to expsoe a single Also, we're going to have to move the flow types of the minifier API to the Metro repo, so they can be reused by any other potential minify implementation. For now, I'm fine if you just copy the current If you also want to do the cleaning, this is the two things that I would do (I'd appreciate a lot 😍): 1- Simplify the minifier API by getting rid of the Thanks again! |
Since the changes from the current |
Closing this PR then |
Summary: <!-- Thanks for submitting a pull request! Please provide enough information so that others can review your pull request. The two fields below are mandatory. --> **Summary** <!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? --> Add support for using [terser](https://github.com/fabiosantoscode/terser/). `terser` is a fork of `uglify-es`, which is not really maintained; and maintains API compatibility with `uglify-es`. In order to avoid duplicating configuration like default options in `metro-minify-uglify`, this PR adds a parameter to `metro-minify-uglify` that allows passing in an alternative minifier module, and the new package `metro-minify-terser` calls this, passing in `terser`. This is based on discussion in #230. After earlier submitting #243, I created this alternative PR to address comments from rafeca **Test plan** <!-- Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes UI. --> The tests are simply copied from `metro-minify-uglify`, since the API is and the results should be identical. Pull Request resolved: #256 Reviewed By: pvdz Differential Revision: D9908604 Pulled By: rafeca fbshipit-source-id: 30dfe4f8cc6b614e50874be51aad0883a1997061
Summary
Add support for using terser.
terser
is a fork ofuglify-es
, which is not really maintained; and maintains API compatibility withuglify-es
.In order to avoid duplicating configuration like default options in
metro-minify-uglify
, this PR adds a parameter tometro-minify-uglify
that allows passing in an alternative minifier module, and the new packagemetro-minify-terser
calls this, passing interser
.This is based on discussion in #230.
Test plan
The tests are simply copied from
metro-minify-uglify
, since the API is and the results should be identical.