I am trying to run npm as part of my maven build. I am using exec-maven-plugin and here is my plugin section from pom.xml
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>exec-npm-install</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>npm</executable>
<arguments>
<argument>build</argument>
</arguments>
<workingDirectory>${basedir}/src/main/webapp</workingDirectory>
</configuration>
</execution>
</executions>
</plugin>
How ever when i run mvn clean package or mvn generate-sources npm is not running.
In my package.json i have the following scripts.
"scripts": {
"start": "npm run build && serve .",
"build": "npm run build-js && npm run build-css",
"watch": "npm run watch-js & npm run watch-css & serve .",
"watch-build": "npm run watch-js && npm run watch-css && npm run build-js && npm run build-css && serve .",
"test": "npm run lint -s && npm run build",
"build-css": "rework-npm index.css | cleancss -o build/build.css",
"build-js": "browserify --extension=.jsx --extension=.js src/app.jsx > build/build.js",
"watch-js": "watchify --extension=.jsx --extension=.js src/app.jsx -o build/build.js --debug --verbose",
"watch-css": "nodemon -e css --ignore build/build.css --exec 'rework-npm index.css -o build/build.css'",
"lint-eslint": "eslint .",
"lint-jscs": "jscs .",
"lint": "npm run lint-eslint && npm run lint-jscs"
}
And hence i am calling build.
Earlier when i used npm install i did see the npm packages being installed.
Also how do i specify the working directory for npm ??
I am passing using and that's where the package.json is located.
<workingDirectory>${basedir}/src/main/webapp</workingDirectory>
Thanks
You need to execute npm run build
to run an npm script, but you are executing npm build
, which is an npm lifecycle event.
<execution>
<id>npm run build</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>npm</executable>
<arguments>
<argument>run</argument>
<argument>build</argument>
</arguments>
</configuration>
</execution>