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.21k stars 867 forks source link

Is npm install necessary? #1008

Open peterkronenberg opened 2 years ago

peterkronenberg commented 2 years ago

In your sample project at https://github.com/eirslett/frontend-maven-plugin/blob/master/frontend-maven-plugin/src/it/example%20project/pom.xml, you have a step which does npm install. Is that really necessary? My project is usually going to be up-to-date with anything that it needs, right? This should only be necessary if you're doing a fresh install. I'm just wondering if I'm missing something

jjlharrison commented 2 years ago

It might be up-to-date on your machine, but what about you CI or other developers? Or for updating packages after switching branches?

peterkronenberg commented 2 years ago

Are there any options that I can specify on the Maven command line for allowing me to skip certain steps?

jjlharrison commented 2 years ago

It's documented in the README.

apwhitelaw commented 1 year ago

I know this is a year old now, but maybe it will still help someone.

It may depend on your use, I'm not sure, but I was able to use the <skip> configuration item to skip the executions that I didn't want/need:

<configuration>
    <skip>true</skip>
</configuration>

So in my case I have 3 goals: install-node-and-npm, npm-install, and scss-compile, like this:

<executions>
    <execution>
        <id>install-node-and-npm</id>
        <goals>
            <goal>install-node-and-npm</goal>
        </goals>
    </execution>
    <execution>
        <id>npm-install</id>
        <goals>
            <goal>npm</goal>
        </goals>
    </execution>
    <execution>
        <id>scss-compile</id>
        <goals>
            <goal>npm</goal>
        </goals>
        <configuration>
            <arguments>run scss</arguments>
        </configuration>
    </execution>
</executions>

The scss is to customize Bootstrap. But every time you change the scss, it requires you to run maven install, which runs all the goals. Well, I figured the first two goals probably only need to be run once since they are just to install node and npm. I just need to compile scss every time. So I added skips for the first two and it seems to work without issues.

And with the skips it looks like this:

<executions>
    <execution>
        <id>install-node-and-npm</id>
        <goals>
            <goal>install-node-and-npm</goal>
        </goals>
        <configuration>
            <skip>true</skip>
        </configuration>
    </execution>
    <execution>
        <id>npm-install</id>
        <goals>
            <goal>npm</goal>
        </goals>
        <configuration>
            <skip>true</skip>
        </configuration>
    </execution>
    <execution>
        <id>scss-compile</id>
        <goals>
            <goal>npm</goal>
        </goals>
        <configuration>
            <arguments>run scss</arguments>
        </configuration>
    </execution>
</executions>

Without the skips, the first goal actually recognizes that node is already installed, so that is automatically skipped, but the second goal still executes every time. Compiling scss still takes a sec but the install process is a bit smoother this way.

RiccardoManzan commented 1 year ago

I'd like to skip onli install execution but i would keep executing npm build step. Is there any way to do it with command-line arguments? The only one i found is -Dskip.npm but it skips the whole npm execution (download, install and build). Did i miss something?

RiccardoManzan commented 1 year ago

Basing on apwhitelaw's response i managed in this ez way: