frontend-maven-plugin icon indicating copy to clipboard operation
frontend-maven-plugin copied to clipboard

Is npm install necessary?

Open peterkronenberg opened this issue 2 years ago • 6 comments

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

peterkronenberg avatar Nov 02 '21 17:11 peterkronenberg

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

jjlharrison avatar Nov 02 '21 17:11 jjlharrison

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

peterkronenberg avatar Nov 02 '21 17:11 peterkronenberg

It's documented in the README.

jjlharrison avatar Nov 02 '21 18:11 jjlharrison

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.

apwhitelaw avatar Jan 03 '23 09:01 apwhitelaw

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 avatar Jan 10 '23 09:01 RiccardoManzan

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

  • Add in project>properties tag this two nodes:
          <skip.npm>false</skip.npm>
          <skip.npm.install>${skip.npm}</skip.npm.install>
    
  • Use those properties to skip certain plugin executions:
               <executions>
                      <execution>
                          <id>install node and npm</id>
                          <!- ... ->
                          <configuration>
                              <skip>${skip.npm.install}</skip>
                          </configuration>
                      </execution>
                      <execution>
                          <id>npm install</id>
                          <goals>
                              <goal>npm</goal>
                          </goals>
                          <configuration>
                              <!- ... ->
                              <skip>${skip.npm.install}</skip>
                          </configuration>
                      </execution>
                      <execution>
                          <id>npm build</id>
                          <goals>
                              <goal>npm</goal>
                          </goals>
                          <configuration>
                              <!- ... ->
                              <!- no skip needed here, as 'skip.npm' is already managed by the plugin ->
                          </configuration>
                      </execution>
                  </executions>
    

With this particular configuration:

  • when -Dskip.npm option is used, no npm operation is executed.
  • when -Dskip.npm.install option is used, only npm build is executed by this plugin.

RiccardoManzan avatar Jan 11 '23 14:01 RiccardoManzan