Minification and uglification question ?
Quick question. How does one Minify and uglify your code? This functionality is provided by yeoman generatior-ionic and I was wondering if there is something like that is offered by ionic-cli?
Here is the related, but closed issue #143 I think that process of minification and uglification is important even before ionic 1.0 release because tons of devs deploying ionic apps to production today.
Thanks.
@softBarbarian
We'll be looking at adding this around version 1.3.1.
Great, not to bug you, but what is the ETA on 1.3.1?
Currently, it's looking towards the end of January.
In the meantime, you might try my friend Ross' cordova-uglify.
Reopening, wrong button. Thanks, I will check it out. You saw this right? This a @cdarken's gist from issue #143 : https://gist.github.com/cdarken/daf8b983f70b66230a30
Personally, I left Gulp and copied (and lightly altered) this great Gruntfile: https://github.com/diegonetto/generator-ionic/blob/master/Gruntfile.js My app weighs now 8mo instead of 30mo.
Looking forward to seeing this added to the CLI - will be great to have it integrated rather than everyone trying to come up with their own way to create a release build - or worse, lots of people not even realising that they should be doing this.
lots of people not even realising that they should be doing this
=> really true I think that this feature is really really needed regarding the obfuscation (role of uglify) of the application code in an Android context. Otherwise, any smart Android users would be able to read the production code and start to detect some weaknesses.
The challenge with this feature is making assumptions about the end users.
Do we make it optional for those who want it? Or for everyone?
Do we add it as a cordova hook? Or have it be run by users directly?
Can't it be done like I suggested in issue #143, as hookable steps in ionic.project? I believe that putting the sources directly in www was a wrong decision. You should have put them by default in other dir, like app, or src.
Yes, it could be done as hookable steps, for sure.
The thing is, you'd have to have the node modules available to do it.
I'm considering just adding cordova-uglify in the dependencies of the ionic starting app.
Alternatively, I could provide a command, something like ionic minify or ionic release, that would run all the uglify/minify stuff.
Just trying to figure out which direction to take.
Can't it be done as an argument to ionic setup ? Like the optional step to add sass support?
Something like ionic setup minification.
I don't think hooking to cordova is the best solution, remaining in gulp teritory would be a much safer choice.
Having it as a cordova hook would let users have it run every time they execute cordova run, thereby not needing to run it via gulp.
However, having it as a gulp task would let the user have full control. They would just need to remember to run it before cordova run
With your suggestion, ionic setup minification, do you think it would add the gulp tasks to the gulpfile?
I see that for sass, everything is by default filled in, except that npm install is not executed, and when you run ionic setup sass, this is added to ionic.project:
"gulpStartupTasks": [
"sass",
"watch"
],
"watchPatterns": [
"www/**/*",
"!www/lib/**/*"
]
I think that this would be the correct approach for minification (or let's call it optimization, because as in my gist, you can also run a custom copy task to only copy what you need, for a recent app I reduced its size with about 6MB by copying only what's required). A lot of extra stuff can be done, not only minification, but also you can run ng-annotate, usemin, etc. Maybe for templates somebody can add template caching, for instance.
To clarify - the steps you're describing a user might do:
ionic setup optimizationionic.projectfile is added withgulpRunTasks(see changes below)- Runs npm install for uglify-js, clean-css, ng-annotate
- When
cordova run iosorcordova run android- these tasks are run before being copied to platforms 'optimized'
Add section to ionic.project file, something like this:
"gulpStartupTasks": [
"sass",
"watch"
],
"watchPatterns": [
"www/**/*",
"!www/lib/**/*"
],
"gulpRunTasks": [
"sass",
"minify"
]
The question is, if we did gulp tasks, how do we get them in the gulpfile of existing users?
The steps seem fine to me. For the migration of existing users, maybe a guide would be useful. A migration guide with info and code to be added to gulpfile.js.
Any ETA on when/if this will materialize into a release ?
Today I have ran npm update -g ionic and it updated my ionic-cli to 1.3.7 I could not find a CHANGELOG for this release.
@jbavari, is this enhancement incorporated in 1.3.7?
@softBarbarian - some of the other team members pushed those releases. I'm not entirely sure what was added. I'll update the changelog.
@keithdmoore - As far as the minification - I'm still trying to push for it coming up soon. I've been busy having to address crosswalk errors lately.
@jbavari - i know you guys are getting really close to 1.0 release and understand that you are very busy. However, i wanted to followup on the progress of this feature. it seems that 1.3.3 milestone that this feature was assigned did not have it.
I am wondering if there is a new milestone set for this to go in?
Thanks