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

There is one single change that makes everything simpler: the addition of "documentRoot" in ionic.project. This way I just modified the scripts to output production code into www and then I run ionic build. Edit: thanks for the work you're doing.

cdarken avatar Mar 05 '15 09:03 cdarken

+1 for the ability to change the root folder, this will easily fix this problem.

w3apps avatar Apr 01 '15 09:04 w3apps

Hi @jbavari - don't want to bug you at all but just wondering if there was any update on this or thoughts as to how it's going to be implemented?

I'm currently using a separate "source" folder where I store what was originally in the www folder. I then use a gulpfile to minify, uglify, concatenate and then copy everything over to the www folder. From the forum I can see that several people are doing something similar.

This is working alright but an integrated "out of the box" solution would be awesome.

Thanks

EdL avatar Apr 10 '15 16:04 EdL

+1 for this.

anwaramoon avatar Apr 12 '15 22:04 anwaramoon

Hi - just seen that this is being discussed on another thread https://github.com/driftyco/ionic-cli/pull/270

Also here https://github.com/driftyco/ionic-cli/issues/16

EdL avatar Apr 13 '15 11:04 EdL

Yep, this out of the box solution would be very helpful. Almost a month ago I volunteered to help the creation of this something like it (#270), but I think this is not a priority for ionic at least for now.

lfv89 avatar Apr 19 '15 17:04 lfv89

I really wished this was a higher priority. The community could really use it. Because this functionality is missing, I find my self going back to using the Yeoman Ionic Generator when starting a new project.

keithdmoore avatar Apr 24 '15 13:04 keithdmoore

I will post an updated version of my gist when I have some time. As I said above, just by changing the value of "documentRoot" in ionic.project, everything becomes very simple.

cdarken avatar Apr 24 '15 13:04 cdarken

Yes. My small contribution was to add a "createDocumentRoot" property in ionic.project, covering the case when your project was just cloned and doesn't have yet your "output" folder.

lfv89 avatar Apr 24 '15 14:04 lfv89

*** Since these "output" folders should be in your .gitignore

lfv89 avatar Apr 24 '15 14:04 lfv89

@jbavari Any updates as to when/if ionic-cli will have these new build features?

keithdmoore avatar May 25 '15 18:05 keithdmoore

@keithdmoore I dont have a time estimate yet.

@vasconcelloslf had put in some work on a new gulpfile that would help solve all of those build min/uglify issues.

Would you mind taking a look and giving your input on his suggested build process?

Keep in mind - this will mainly affect the masses that download and use this tool. For starters, though, we can add it in as an experimental flag or command of its own.

You can find it in the comments here:

https://github.com/driftyco/ionic-cli/pull/270

jbavari avatar May 26 '15 17:05 jbavari

Hi guys,

Sorry I'm a bit late to the party! I've been following these threads relating to a "build step" both on GitHub and the Ionic forum for a while now and been meaning to post my thoughts. Excuse the lengthy post.

First up, I think its great that this is going to be added in one way or another.

@vasconcelloslf - thanks for putting together your build process and sharing it. I have a gulp file I posted a while ago that I have been working with on and off - it's not quite as neat or finished as yours!

http://forum.ionicframework.com/t/improve-assets-setup-in-ionic-framework/12859/5 https://gist.github.com/EdL/b1922462fd33b15c5984

I have searched quite a bit through the forums and most people are using Gulp as the build tool either as a manual step or using watchers, so given that, I think Gulp would be the way to go.

I think the main ideas people agree on are the following:

Providing Dev and Release modes Providing a way to supply different source and destination folders Providing a way to list which resources, js, css files should be used

For both dev and release:

Sass build. Copy files from source to destination - this will include js, css, fonts, images, other. Each in separate steps as they will probably be going in different locations. Having watchers auto update the build destination files

Creating an index.html file referencing the correct destinations depending on whether it is dev or release - I'm still unsure of the best way to do this? Maybe gulp-html-replace ? I see how @vasconcelloslf is doing it but would be interested if there are other opinions on this?

(Optionally could have a linting step e.g. gulp-jshint with jshint-stylish)

For release:

Concatenating files Add AngularJS dependency injection annotations e.g. gulp-ng-annotate Minifying Uglifying Renaming with .min.js or .min.css (Optionally could have template html minification and injection e.g. gulp-ng-html2js or gulp-angular-templatecache) (Optionally could have source maps e.g. gulp-sourcemaps, although personally I don't think I will use them if there is a dev mode)

Extra thoughts

The build step could be triggered by the addition of an attribute on the ionic serve, emulate or build commands.

e.g ionic build -b dev or ionic build -b release

I don't see the need for having a separate cordova hook, or for a different workflow when running ionic build vs ionic serve or emulate. They could all just take the same attribute and trigger the same build process but for dev or release depending what arg is passed.

I really like the idea of providing a setup for source and destination directories in the ionic.project files. Note that running "ionic update" should be able to pickup the source directory and update the ionic libs in there, and running ionic serve, emulate or build, should pickup the build from the destination directory not be tied to the normal www directory.

I like @vasconcelloslf idea of having dev and release variables and a config file for these. You could say this isn't necessary on the build step as a user could load the relevant constants depending on if they have a dev or build flag set somewhere, but it would be nice if running the build step set a dev/release flag. e.g. set a "build: release" or "build: dev" in a config file somewhere that could then be used at runtime by an app to determine which set of constants to use.

@https://github.com/vasconcelloslf/ionic-starter-app#8-configure-the-constant-values-gulp

Links to the main forum posts on build steps

http://forum.ionicframework.com/t/improve-assets-setup-in-ionic-framework/12859/7 http://forum.ionicframework.com/t/ionic-app-dev-with-gulp-minify-compress-etc/8087/10 http://forum.ionicframework.com/t/my-restructure-of-the-ionic-apps/11184 http://forum.ionicframework.com/t/restructuring-from-www-to-app-folder-in-order-to-minify/14601/7

Thanks

Ed

EdL avatar Jun 03 '15 12:06 EdL

@jbavari hello is there any update for this?

okonon avatar Jul 24 '15 03:07 okonon

@jbavari Any update on this?

keithdmoore avatar Oct 19 '15 18:10 keithdmoore

@keithdmoore I had a good branch going that included all the sass compilation/minification as well as html/js minification done in this branch.

Lately though, I've been working on the tooling for Ionic v2, which will lean more on the webpack side of things, and leave gulp up to the users to use if they so wish to leave config/customization to users.

Are you all still using your custom gulp tasks to build / minify things?

jbavari avatar Oct 22 '15 21:10 jbavari

Hi @jbavari

Yes, I still use my own custom gulp tasks to handle config variables, different environments and tasks like minification/concatenation, etc... And I still think that the user shouldn't have to worry about such basic and repetitive tasks that should come by default with an advanced framework as Ionic.

You said earlier in the thread that "The challenge with this feature is making assumptions about the end users.", but I don't see this as a bad thing, I see as a great advantage. For example, Rails embraced this concept and even coined the "Convention over Configuration" jargon, and it worked pretty well for them.

But hey, that's just my opinion. By the way, can you tell us more about these default ionic v2 tools that you have been working on?

lfv89 avatar Oct 22 '15 22:10 lfv89

I tend to use the ionic generator. It's too much of a pain to write all that custom infrastructure code. The downside is that I can't use other ionic services. I agree with @vasconcelloslf

keithdmoore avatar Oct 22 '15 23:10 keithdmoore

Interested in updates.

lpotapczuk avatar Nov 17 '15 20:11 lpotapczuk

Ionic V2 seems to run webpack on ionic build android and imposes the webpack configuration file name to be webpack.config.js (hardcoded).

The way I used to do that with Ionic 1 was to have my own cordova hook that reads the --release param (or any custom param), and chooses accordingly the right webpack config file (or eventually add '-p') to make the bundle with or without minification.

My webpack.prod.js was basically an import of the default (dev) config where the devtool (source-map) param was removed and UglifyJs options were added.

It is great to see that Ionic V2 includes the webpack build, but it is not flexible, and I am not even sure we can remove it.

So I am also interested in updates :)

antoineol avatar Dec 20 '15 09:12 antoineol