在exec-maven-plugin中将工作目录传递给npm [英] Passing Working Directory to npm in exec-maven-plugin

查看:710
本文介绍了在exec-maven-plugin中将工作目录传递给npm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将npm作为我的Maven构建的一部分运行.我正在使用exec-maven-plugin,这是来自pom.xml的插件部分

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>

但是,当我运行mvn clean package或mvn generate-sources npm时,却没有运行.

How ever when i run mvn clean package or mvn generate-sources npm is not running.

在我的package.json中,我有以下脚本.

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.

当我使用npm install时,我确实看到正在安装npm软件包.

Earlier when i used npm install i did see the npm packages being installed.

我如何为npm指定工作目录?

Also how do i specify the working directory for npm ??

我正在使用,这是package.json所在的地方.

I am passing using and that's where the package.json is located.

<workingDirectory>${basedir}/src/main/webapp</workingDirectory>

谢谢

推荐答案

您需要执行npm run build来运行npm脚本,但是您正在执行npm build,这是npm生命周期事件.

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>

这篇关于在exec-maven-plugin中将工作目录传递给npm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆