ionic-cli icon indicating copy to clipboard operation
ionic-cli copied to clipboard

Minification and uglification question ?

Open okonon opened this issue 11 years ago • 42 comments

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?

okonon avatar Dec 22 '14 04:12 okonon

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.

okonon avatar Dec 29 '14 14:12 okonon

@softBarbarian

We'll be looking at adding this around version 1.3.1.

jbavari avatar Jan 03 '15 00:01 jbavari

Great, not to bug you, but what is the ETA on 1.3.1?

okonon avatar Jan 05 '15 13:01 okonon

Currently, it's looking towards the end of January.

In the meantime, you might try my friend Ross' cordova-uglify.

jbavari avatar Jan 06 '15 01:01 jbavari

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

okonon avatar Jan 06 '15 02:01 okonon

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.

mica16 avatar Jan 07 '15 00:01 mica16

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.

EdL avatar Jan 07 '15 01:01 EdL

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.

mica16 avatar Jan 07 '15 01:01 mica16

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?

jbavari avatar Jan 22 '15 19:01 jbavari

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.

cdarken avatar Jan 22 '15 19:01 cdarken

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.

jbavari avatar Jan 22 '15 19:01 jbavari

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.

cdarken avatar Jan 22 '15 20:01 cdarken

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?

jbavari avatar Jan 22 '15 20:01 jbavari

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.

cdarken avatar Jan 22 '15 20:01 cdarken

To clarify - the steps you're describing a user might do:

  • ionic setup optimization
  • ionic.project file is added with gulpRunTasks (see changes below)
  • Runs npm install for uglify-js, clean-css, ng-annotate
  • When cordova run ios or cordova 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?

jbavari avatar Jan 22 '15 21:01 jbavari

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.

cdarken avatar Jan 23 '15 07:01 cdarken

Any ETA on when/if this will materialize into a release ?

keithdmoore avatar Jan 30 '15 03:01 keithdmoore

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?

okonon avatar Feb 04 '15 14:02 okonon

@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 avatar Feb 04 '15 14:02 jbavari

@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

okonon avatar Feb 26 '15 19:02 okonon