How to obfuscate ionic build to publish?


#1

Hello mates,

I’m going to publish my first app to the google store and I need some advice or help to how I can obfuscate, shrink, minify, etc, my Ionic 3 application when I generate the build to publish.

I found some articles like this one:

and

So, I believe that have someone here that already did this before. Help me! :stuck_out_tongue:

Best regards


#2

Building with --prod automatically runs uglify.js.


#3

What if there are css and js files under the assets folder?
The --prod build does not appear to have any impact on these files, even if they need to be optimized.


#4

I think putting scripts under the assets folder is a mistake. All code that can be managed by webpack should be. It’s not just minification; there’s also dead code elimination.


#5

Example:
the ionic conference app has a .json file (ok, not a “script” proper) under the “assets” folder.

How would one go about optimizing this file - e.g., minification - in ionic 3?


#6

I don’t see any point in trying to do that. If you change the property names, the data will no longer be usable in its intended form. Compressing it would be theoretically possible, but I don’t think it would be relevant as app binaries are zipped anyway.


#7

No point in minification if the file is large and minifying can significantly reduce the file size?


#8

Then do it manually or change to configuration so that it also minifies that one file.


#9

Techniques used in JavaScript minification don’t apply for JSON assets. Think about it from an information theory standpoint: every property name and value in a JSON file conveys as much information as that name or value’s string representation. There is no way you can shrink a JSON file (except for whitespace compression) while preserving the requirement that JSON.parse() will return a functionally identical object as it would on the original version.


#10

@Sujan12 - Can you please elaborate on where to get started with “changes to configuration” for a task like this?


#11

No idea. It is a not very good idea with minimal payoff as @rapropos mentioned.
Probably in ionic app-scripts somehow.


#12

So I’m here with the same question. By reading what you guys have responded --prod runs uglify and minify automatically, but what about obfuscating? Is it necessary? I found an npm package for ionic for what I need, but I want to make sure I even need it. https://www.npmjs.com/package/ionic-voricles-obfuscate

Thanks in advance.