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

v3 - gulp tasks not called

Open Richie765 opened this issue 9 years ago • 22 comments

What version of the CLI are you using? Output of ionic --version

3.0.0-beta.4

Short description of the problem:

With 2.0, the following gulp tasks were automatically called:

serve:before emulate:before run:before build:before

In v3 this no longer happens.

What behavior are you expecting?

Gulp tasks to be called.

Post the output of ionic info below please Cordova CLI: 6.5.0 Ionic Framework Version: 2.2.0 Ionic CLI Version: 3.0.0-beta.4 ios-deploy version: 1.9.1 ios-sim version: 5.0.13 OS: macOS Sierra Node Version: v6.9.4 Xcode version: Xcode 8.2.1 Build version 8C1002

Richie765 avatar Mar 14 '17 18:03 Richie765

Could you provide me with details on what you are using the gulp tasks for? We removed these in favor of just supporting @ionic/app-scripts.

jthoms1 avatar Mar 16 '17 14:03 jthoms1

@jthoms1 I use a gulp build to be able to use ES6 in my Ionic 1 app, with linting and other stuff. In my case I do gulp.task('serve:before', ['default', 'watch']); which triggers the build when doing ionic serve. This is not happening anymore and I need to manually run the tasks. If we are moving to @ionic/app-scripts, is there a way to trigger gulp tasks when certain ionic commands are run?

leandroz avatar Mar 16 '17 15:03 leandroz

I use it for several things, for example

  • To modify some source files to set access tokens of external services, so I use a token during development and another one for production (build).
  • Same, but to put the version from packages.json into the about page.
  • To remove the comments from index.html.
  • To copy some files from node_modules/../ to app/assets. These are fonts, css files and .js files. Some of them I don't want to include in main.js / main.css so they can be parallel loaded and to make building faster.
  • To resize and optimize images

Some tasks are specifically for production (build), others can be for development with watch.

Richie765 avatar Mar 16 '17 18:03 Richie765

@Richie765 @leandroz Thanks, very insightful! We will address this in a later release. I can tell you that a suitable replacement is coming. We definitely want to support custom workflows.

imhoffd avatar Apr 20 '17 21:04 imhoffd

In addition to the above, it seems that #1358 is still an issue - when running ionic serve for an Ionic 1 project, any changes to sass files are not live reloaded in the browser. In v2 of the CLI we could add the following line to the end of the gruntfile:

gulp.task('serve:before', ['default','watch']);

But now this doesn't work for v3 of the CLI.

This has been such a long standing bug - just like for Ionic 2+ projects, I'd expect ionic serve to watch and compile SASS files for Ionic 1 projects.

fiznool avatar May 12 '17 10:05 fiznool

As serve:after is working fine, temporary replacement could be something like this:

gulp.task('serve:after', ['watch']);

This just starts the watch task after the serve has completed, which kind of does the job we wanted it to. However, we need to run the gulp command to run the default task before ionic serve

magician03 avatar May 21 '17 11:05 magician03

I also use ionic-1 with a lot of gulp tasks, but because ionic-upgrades ever broke gulp stuff I ever stayed on older version, with the downside to never be able to try out ionic-2.

But why don't do it ourself?

var server = require('gulp-server-livereload');
gulp.task('webserver', ['watch'], function() {
    gulp.src('www')
        .pipe(server({
            livereload: true,
            directoryListing: false,
            open: false,
            port: 8111,
        }));
});

Now for me ionic can also drop v1 in ionic-cli. why drop everywhere v1 support core, ionic-native but ionic-cli wants to continue support a thing, which doesn't get support everywhere else.

ok, maybe some still want to use gulp in ionic-2+, but that's another story..

pablomaurer avatar May 29 '17 09:05 pablomaurer

@Richie765 @leandroz @fiznool @magician03 @mnewmedia As a heads up, I have been working on this as a new feature for the CLI. Please take a minute to read what I'm thinking.

Right now, we can boil down the CLI v2 serve/emulate/run/build events to two events: watch and build.

These are the commands that kick off a watch:

  • ionic serve
  • ionic cordova run
  • ionic cordova emulate

These are the commands that kick off a build:

  • ionic build (not yet a thing)
  • ionic cordova build
  • ionic upload
  • ionic package build

Unless there's a good reason, I am going to hold off on the notion of firing events when a command executes, and go forward with firing events when a thing happens. If something in your project needs to happen during a Cordova build, you can use Cordova hooks.

I want to create a separate plugin for gulp integration (separate from @ionic/cli-plugin-ionic1), called @ionic/cli-plugin-gulp. It will be responsible for calling the following gulp tasks defined in your gulpfile.js:

  • ionic:watch:before: This event fires before the file watcher activates
  • ionic:build:before: This event fires before the Ionic build starts
  • ionic:build:after: This event fires after the Ionic build completes (when running ionic cordova build, it fires after the Ionic build and before the Cordova build)

Additionally, the CLI gulp plugin will look for a sass task in your gulpfile.js. If it finds it, it runs the task during watch when SCSS files change. (Just like before, but faster 🚀)

I've already programmed everything, and this makes the most sense, but now that I've explained it in detail, you all have the opportunity to tell me what a horrible idea it all is before the plugin is released.

imhoffd avatar Jun 05 '17 23:06 imhoffd

@dwieeb sounds good to me, the import thing here is to have that documented so people know how to use the events and which ones are available.

Great work!, thanks!

leandroz avatar Jun 06 '17 00:06 leandroz

@dwieeb I like the idea of separating the functionality into a dedicated plugin. Your approach of firing the events seems reasonable. Good work!

But this sounds like it doesn't resolve the missing option to call npm script hooks which was available in ionic-cli v2 (see issue #2124). I haven't looked much into the code of ionic-cli v3 and wasn't aware the plugin architecture is so powerful. From what I understand of your post, it should be easy to write a similar plugin for npm scripts, especially if your plugin code can be used as a blueprint. If this is the case and the ionic team does not have something in the pipeline, I will look into it and work on a solution after my holiday trip.

GerritErpenstein avatar Jun 06 '17 08:06 GerritErpenstein

@GerritErpenstein Part of the work here will easily enable npm scripts to be called. I think I'll make it work out of the box. ionic:watch:before, ionic:build:before, and ionic:build:after will all be available npm scripts that the CLI will run.

imhoffd avatar Jun 06 '17 17:06 imhoffd

@GerritErpenstein @Richie765 @leandroz @fiznool @magician03 @mnewmedia

Calling the gulp side of this complete. These changes are in master, which means you can start testing them right now.

See how it works for new and existing Ionic 1 projects.

npm i -g ionic@canary

imhoffd avatar Jun 07 '17 22:06 imhoffd

Hi all - just a general question based on the comment above - https://github.com/ionic-team/ionic-cli/issues/1989#issuecomment-287095549. I have the same setup as @leandroz:

via @leandroz

In my case I do gulp.task('serve:before', ['default', 'watch']); which triggers the build when doing ionic serve.

So looking at the new @ionic/cli-plugin-gulp plugin to be used with ionic cli v3 (thanks @dwieeb) for the work on that by the way, I understand that basically the task above will at the very least need a new ionic:watch:before event, which should run the watch task, so that any edits to my code will automatically be recompiled. But what is unclear, is when the default task does/should get run. In other words, how do I compile my code, running the default task as part of running ionic serve.

I have tried using ionic:build:after and ionic:build:after for this, and maybe it is already being done automatically, however, when I do run ionic serve, I run it with the --verbose option, and don't see anything about the gulp tasks being run, as I used to see in CLI v1, which I was on before this.

So any ideas on the best way to transfer the previous gulp task link of gulp.task('serve:before', ['default', 'watch']) into the new plugin syntax? I will be happy to update the examples in that plugin once I have solved this, because I guess that anyone still running a ionic1 app and upgrading to the new CLI will have the same issue, and unfortunately this is not 100% clear right now.

Thanks!

jacquesdev avatar Jun 20 '17 22:06 jacquesdev

So it looks like the only changes needed are: gulp.task('ionic:watch:before', ['default', 'watch']).

However, as mentioned I don't see the output anywhere to confirm that the default gulp task has actually been completed, not sure if that is possible in the current setup or if I need to add an issue to request this. @dwieeb - I guess you would be the best person to answer this.

jacquesdev avatar Jun 20 '17 22:06 jacquesdev

@jacquesdev What are you trying to do? If you're not doing anything fancy, you shouldn't need to modify your gulpfile at all. ionic info?

imhoffd avatar Jul 10 '17 22:07 imhoffd

@dwieeb - I just had to change:

gulp.task('serve:before', ['default', 'watch'])

to

gulp.task('ionic:watch:before', ['default', 'watch']).

The main thing was that the previous cli would specifically show you the gulp output, whereas now it does not print any output. So it wasn't immediately obvious that it was doing anything (although it was running them in the background)

jacquesdev avatar Jul 10 '17 22:07 jacquesdev

You shouldn't need to call the watch task if you use ionic serve.

imhoffd avatar Jul 10 '17 23:07 imhoffd

I'm a bit lost here. I also have a lot of gulp tasks in my Ionic v1 project (sass, copying config file, angular-templatecache, ng-annotate, useref) which I need to run before every ionic cordova run and also when any file changes. Worked well in CLI v1.

I tried changing

gulp.task('serve:before', ['default', 'watch'])

to

gulp.task('ionic:watch:before', ['default', 'watch'])

as suggested, but the gulp task doesn't seem to be executed when I do ionic cordova run android. It just runs ionic cordova prepare, which executes my cordova hooks, then it runs cordova run android (which executes my cordova hooks again) and then it starts to build.

The Ionic CLI Gulp integration seems to be in place:

ionic.config.json:

{
  "name": "Tomato",
  "app_id": <removed>,
  "integrations": {
    "cordova": {},
    "gulp": {}
  },
  "type": "ionic1"
}

ionic info:

cli packages: (/home/arx/.npm-global/lib/node_modules)

    @ionic/cli-utils  : 1.9.1
    ionic (Ionic CLI) : 3.9.1

global packages:

    Cordova CLI : 7.0.1 
    Gulp CLI    : CLI version 3.9.1 Local version 3.9.1

local packages:

    Cordova Platforms : android 6.2.3
    Ionic Framework   : ionic1 1.3.2

System:

    Android SDK Tools : 25.2.5
    Node              : v6.11.1
    npm               : 3.10.10 
    OS                : Linux 4.10

My questions:

  • is there something special I need to do to tell Ionic CLI it needs to run gulp first?
  • do I need to have @ionic/app-scripts installed for this? Or any other packages?
  • do I need to have anything defined in the scripts section of my package.json?

Thank you!

Edit: I see now that when I run ionic serve, the gulp task ionic:watch:before gets executed, even though the gulp output is not shown, as mentioned by @jacquesdev earlier. But the same doesn't happen when running ionic cordova run android. Is there a way to tell Ionic CLI to run the gulp task in that case too?

jurajdurajka avatar Aug 17 '17 16:08 jurajdurajka

ionic cordova run and ionic cordova emulate do a build and then they deploy the build to the device. If you want to hook into ionic:watch:before, the watch process needs to run, which means you need to use --livereload.

imhoffd avatar Aug 17 '17 16:08 imhoffd

@dwieeb you are indeed correct, thank you! My apologies, I got confused by the docs: https://github.com/ionic-team/ionic-cli#cli-hooks

from the table it might seem that ionic:watch:before script/task is triggered by ionic cordova run without the need for the livereload option and ionic:build:before doesn't mention ionic cordova run at all.

It makes sense now. Thank you again for your time!

jurajdurajka avatar Aug 17 '17 16:08 jurajdurajka