eirslett / frontend-maven-plugin

"Maven-node-grunt-gulp-npm-node-plugin to end all maven-node-grunt-gulp-npm-plugins." A Maven plugin that downloads/installs Node and NPM locally, runs NPM install, Grunt, Gulp and/or Karma.
Apache License 2.0
4.23k stars 867 forks source link

watching file changes using a non-standard phase #940

Closed strattonbrazil closed 3 years ago

strattonbrazil commented 3 years ago

This plugin as been extremely helpful setting up a npm build flow for my java app. One thing that's remained a challenge for me is rerunning specific steps on file changes. I had set up webpack to do this, which worked fine, but I didn't want to do this as part of the normal build process since it would prevent moving on to the next phase/goal.

Here's a snippet with two execution steps--the first is normal use and has been part of the build phase, and the second is what I was trying to do using a random phase:

          <execution>
            <id>npm run build</id>
            <goals>
                <goal>npm</goal>
            </goals>
            <configuration>
              <arguments>run build</arguments>
            </configuration>
          </execution>
          <execution>
            <id>npm-run-watch</id>
            <goals>
                <goal>npm</goal>
            </goals>
            <configuration>
              <arguments>run watch</arguments>
            </configuration>
            <phase>validate</phase>
          </execution>

The problem is this holds up the rest of the build/run process like starting the web server.

I was considering adding a custom phase I could put this in, but was also wondering if there were an easier way to do this. Is there a better way to accomplish this? Is there another workflow for running specific execution steps only some of the time?

eirslett commented 3 years ago

I usually just run Webpack in a separate terminal window, with watch mode on. And then in Maven the watch mode is off.

strattonbrazil commented 3 years ago

Thanks. I was considering something like that, but thought it might be handy to have maven do it so I'd be using the same node/npm version. Do you just reference the local installation in the second terminal to do that?

$ ./node/npm run webpack-watch
eirslett commented 3 years ago

It depends, I usually just use the global node.js installation for simplicity.