Adding the famous gulp-usemin and configure the source to www and the dest to app.
Now, I expect the command ionic serve to watch the app folder, not the www as initially. Is there a way to do that?
Indeed, I don’t want to deal with minified files in the browser; would be hard for debugging.
In my case, I have two different gulp commands, one that minifies and prepares everything for production, and another one that just copies everything to the www folder. Maybe that can be a solution for you too.
What I usually do is manually trigger the minification task to make www change, or set a watch that triggers the minification when it detect changes on the app folder. Not the ideal solution, but maybe it works for you.
Here is my workflow: I maintain all my files outside of the www folder and minify, merge and copy them to the www folder using gulp. I’m using Sass and it works with ionic serve. I hope it helps.
Thanks, really helpful.
How if you want to use the original files (not minified ones) with the ionic serve command?
Would be really useful for debugging in the browser.
The only way I found is to alter the serve.js file itself (executed by the ionic command), to specify /app (or /js as yours) instead of /www.
Any better solution?
I’m just looking into this myself. I think I’m going to:
Create a new folder in my root which is the contents of my existing www folder including all 3rd party bower components, sass files etc
Create 2 gulp scripts/tasks (for dev and release) to copy the necessary files into the (now empty) www folder.
Dev script will copy normal non minifed, non-concatenated files (or do the mini/concat but use mapping files) to enable easy debugging
Release script will minify, concantenate etc and then copy.
So ionic serve will still just look at the www folder - no change there
Just an update on this. I have now added a gulp build step that minifies and uglifies everything form a new “source” folder into the www folder. I use source maps when doing the minifying/uglifying, so debugging in the browser is like stepping through the original files. Works well so far.
Would be better if the CLI had this out of the box though!
What about installing cordova-minify and cordova-uglify?
like that during the build cordova will minify and uglify your code without using another folder.
Also like that you can use the power of ionic cli like the livereload and ionic serve
Yeah, something like that would be great, but that only solves half the problem for me.
e.g. It doesn’t strip out all the unnecessary files such as sass or bower package files that you don’t want copied over every time you do a build.
If the cordova hooks handled all the optimisation that gulp did then I would definitely consider using them over gulp. Although, at the minute, the ionic project is already using gulp for SASS compilation so it just makes sense to make further use of the Gulpfile.
Hi edd, could you give me some information to how you did minifying/uglifying the javascript files and create source maps? I am new to source maps, but I need source maps if I want to enable some remote debugging libraries like atatus.
Thanks in advance.
Mark
Hi @markdark - I ended up moving away form source maps and just having a dev and release build step. During dev and debugging etc I don’t minify/uglify and just use the original files. Then for release I do the minify/uglify.
I did originally try using source maps but found it much more time consuming and it seemed inconsistent and flakey when using them with Angular due to the exceptions not showing the stack trace or correct source file properly - I can’t remember exactly what the issue was, but it wasn’t working as well as my current method.
My Gulp build file is here if you want to try it out. Obviously you’ll have to edit it for your purposes. It has the source map generation in there, but just commented out.
Thanks for sharing. It will help me generating source maps. I need them in production also because the app we are building needs remote debugging capabilities even when in production. I am now using Atatus for this which I can enable remotely on user level. But I need some source maps to map back to the original JS file.
Thanks again for the information.