Skip to content
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

Minification breaks certain libraries #9711

Closed
yogiben opened this issue Sep 2, 2016 · 12 comments
Closed

Minification breaks certain libraries #9711

yogiben opened this issue Sep 2, 2016 · 12 comments
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.

Comments

@yogiben
Copy link

yogiben commented Sep 2, 2016

We're using a library in our Android RN app.

It works fine in dev, but breaks once minified.

Is there a way to skip minification of certain files?

@maluramichael
Copy link

Which libraries and which lines break?

@ide
Copy link
Contributor

ide commented Sep 3, 2016

The current minifier is Uglify (may change to Babili later) so if you can figure out how to tell Uglify not to minify certain functions that would probably work for you.

@you-fail-me
Copy link

@ide Is there a way to generate a non-minified apk with react-native?

@ide
Copy link
Contributor

ide commented Sep 5, 2016

Grep through the build process searching for minify and change whatever code is requesting minify=true in a packager URL to minify=false.

@yogiben
Copy link
Author

yogiben commented Sep 8, 2016

In the end, we solved this by disabling mangling:

function minify(filename, code, sourceMap) {
  const minifyResult = uglify.minify(code, {
    fromString: true,
    inSourceMap: sourceMap,
    outSourceMap: true,
    mangle: false, // ADD THIS LINE
    output: {
      ascii_only: true,
      screw_ie8: true,
    },
  });

in node_modules/react-native/packager/react-packager/src/JSTransformer/worker/minify.js

We haven't found a nice way to commit this into version control yet.

@charpeni
Copy link
Contributor

@facebook-github-bot label Icebox

@charpeni
Copy link
Contributor

Hi there! This issue is being closed because it has been inactive for a while.

But don't worry, it will live on with ProductPains! Check out its new home: https://productpains.com/post/react-native/minification-breaks-certain-libraries

ProductPains helps the community prioritize the most important issues thanks to its voting feature.
It is easy to use - just login with GitHub.

Also, if this issue is a bug, please consider sending a PR with a fix.
We're a small team and rely on the community for bug fixes of issues that don't affect fb apps.

@charpeni
Copy link
Contributor

@facebook-github-bot close

@facebook-github-bot facebook-github-bot added Icebox Ran Commands One of our bots successfully processed a command. labels Nov 14, 2016
@facebook-github-bot
Copy link
Contributor

@charpeni tells me to close this issue. If you think it should still be opened let us know why.

@facebook-github-bot facebook-github-bot added the Ran Commands One of our bots successfully processed a command. label Nov 14, 2016
@ds300
Copy link

ds300 commented Jul 10, 2017

@yogiben you might be interested in patch-package for future situations like this. I use it to prevent mangling myself :-)

@coreh
Copy link

coreh commented Sep 6, 2017

For future reference: As of September 2017 the file that needs to be patched (as described by @yogiben's instructions) has been moved to the metro-bundler module, so the path should now be:

Edit: Path changed again, see the comment below by @jackylimel

node_modules/metro-bundler/src/JSTransformer/worker/minify.js

If you're using patch-package to patch it, here's patches/metro-bundler+0.9.2.patch:

diff --git a/node_modules/metro-bundler/src/JSTransformer/worker/minify.js b/node_modules/metro-bundler/src/JSTransformer/worker/minify.js
index 3f61ce9..4927afb 100644
--- a/node_modules/metro-bundler/src/JSTransformer/worker/minify.js
+++ b/node_modules/metro-bundler/src/JSTransformer/worker/minify.js
@@ -46,10 +46,11 @@ function minify(inputCode, inputMap) {
     fromString: true,
     inSourceMap: inputMap,
     outSourceMap: true,
+    mangle: false,
     output: UGLIFY_JS_OUTPUT_OPTIONS });
 
 }
 
 module.exports = {
   noSourceMap,
-  withSourceMap };
\ No newline at end of file
+  withSourceMap };

@liangfenxiaodao
Copy link

The file path mentioned here: #9711 (comment) is changed. It should be:

node_modules/metro-minify-uglify/src/minify.js

@facebook facebook locked as resolved and limited conversation to collaborators May 24, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

10 participants