Concat & minify problem

UPDATED:::: see my reply below

I’m using this tutorial to concat & minify my files.

The issue I’m running into is that I have to call

ionic serve 

to rebuild my concat js file. I have have a before_prepare hook to run my gulp build (which it does) but it just creates all my files in the dist folder but doesn’t concatenate my js…just my css.

Everything works as expected if call

ionic serve
ionic run ios

but I always have to call serve first or my concat js file doesn’t get created. Any ideas on what I’m doing wrong? I’m following the tutorial to the letter…

I’ve seen that approach, but I wouldn’t do it that way because you’re spreading your build tasks between Gulp and Cordova. It’s easier and more transparent to just have Gulp do everything.

So I should just do a 2 step process of gulp and then “ionic run”?

Yes, that’s how I am doing it - here’s my gulp file:

https://github.com/leob/ionic-quickstarter/blob/master/gulpfile.js

For “ionic run” you first manually execute a “gulp build” (full concat/minify), for “ionic serve” it’s automatically running the ‘gulp default’ task (no concat/minify) as per the ionic.project file (https://github.com/leob/ionic-quickstarter/blob/master/ionic.project):

{
 "name": "app",
 "app_id": "",
...
 "gulpStartupTasks": [
    "default",
    "watch"
 ],
 "watchPatterns": [
    "src/**/*",
    "!src/lib/**/*"
 ]
...
}
1 Like

For anyone else trying to do this, the issue I was running into using that tutorial was the fact that gulp is asynchronous. Meaning the first time my tasks ran via my hook there were no files there to concat. Any time after that though, it always worked because the ng-annotate files were already there when my tasks kicked off.

The solution I found was to run my tasks synchronously (one by one in order) with this npm module.
https://www.npmjs.com/package/run-sequence