首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >来自Maven的参数化角CLI构建调用(Eirslett的插件)

来自Maven的参数化角CLI构建调用(Eirslett的插件)
EN

Stack Overflow用户
提问于 2018-03-13 12:20:06
回答 3查看 4.6K关注 0票数 4

我正在构建一个在WAR静态资源中打包的Java web应用程序。这些静态资源是通过角-CLI构建的。

Maven构建通过Eirslett的maven-frontend-plugin、npm脚本和npm触发ng构建。

问题是,我希望根据Maven构建参数使用自定义base href,并且我没有通过环境变量或参数将它传递给ng。

有人能告诉我如何从Maven?将参数传递给ng构建吗?

代码:

pom.xml

代码语言:javascript
复制
                 <plugin>
                    <groupId>com.github.eirslett</groupId>
                    <artifactId>frontend-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>node install</id>
                            <phase>generate-resources</phase>
                            <goals>
                                <goal>install-node-and-npm</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>npm install</id>
                            <phase>generate-resources</phase>
                            <goals>
                                <goal>npm</goal>
                            </goals>
                            <configuration>
                                <arguments>--registry=${npm.internal.registry} --userconfig ${basedir}/.jenkins-npmrc install</arguments>
                            </configuration>
                        </execution>
                        <execution>
                            <id>npm build</id>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>npm</goal>
                            </goals>
                            <configuration>
                                <arguments>--userconfig ${basedir}/.jenkins-npmrc run-script build</arguments>
                                <environmentVariables>
                                    <test>this-does-not-work</test>
                                </environmentVariables>
                            </configuration>
                        </execution>
                        <execution>
                            <id>npm test</id>
                            <phase>test</phase>
                            <goals>
                                <goal>npm</goal>
                            </goals>
                            <configuration>
                                <arguments>run-script test</arguments>
                            </configuration>
                        </execution>
                    </executions>
                    <configuration>
                        <nodeVersion>v8.6.0</nodeVersion>
                        <npmVersion>5.3.0</npmVersion>
                        <installDirectory>.</installDirectory>
                        <nodeDownloadRoot>${node.internal.repo}</nodeDownloadRoot>
                        <npmDownloadRoot>${npm.internal.registry}/npm/-/</npmDownloadRoot>
                        <installDirectory>.</installDirectory>
                        <workingDirectory>.</workingDirectory>
                    </configuration>
                </plugin>

package.json

代码语言:javascript
复制
"scripts": {
    (...)
    "build": "ng build --prod --env=prod --bh=process.env.test --base-href=process.env.test",
    (...)
  }
EN

回答 3

Stack Overflow用户

发布于 2018-05-01 11:21:10

我正在解决类似的问题,方法是让in (假设在package.json中有正则的角-clipackage.json条目):

pom.xml

代码语言:javascript
复制
...
<execution>
  <id>build</id>
  <goals>
    <goal>npm</goal>
  </goals>
  <configuration>
    <arguments>run build -- --base-href ${context.root}/</arguments>
  </configuration>
</execution>
...

然后,您可以通过Maven配置文件控制<context.root>属性,并且在parents Maven模块<properties>部分中具有默认值。

票数 2
EN

Stack Overflow用户

发布于 2018-08-17 15:39:05

我需要将Maven项目版本传递给我的NPM脚本,下面的代码与exec-maven-plugin一起为我工作

pom.xml

代码语言:javascript
复制
<execution>
    <id>my-npm-build</id>
    <goals>
        <goal>exec</goal>
    </goals>
    <phase>compile</phase>
    <configuration>
        <executable>npm</executable>
        <arguments>
            <argument>run</argument>
            <argument>my-npm-script</argument>
        </arguments>
        <environmentVariables>
            <mvn_prj_vrsn>${project.version}</mvn_prj_vrsn>
        </environmentVariables>
    </configuration>
</execution>

在package.json中

代码语言:javascript
复制
"scripts": {
    "my-npm-script": "echo %mvn_prj_vrsn% &&[my other commands]
}

以上是用于windows的,如果使用Linux的话。

代码语言:javascript
复制
$mvn_prj_vrsn
票数 1
EN

Stack Overflow用户

发布于 2019-09-30 11:16:31

这个解决方案对我有效:在我的pom.xml :我调用我的脚本运行构建:prod

代码语言:javascript
复制
    <plugin>
        <groupId>com.github.eirslett</groupId>
        <artifactId>frontend-maven-plugin</artifactId>
        <version>1.7.5</version>

        <configuration>
            <nodeVersion>v11.8.0</nodeVersion>
            <npmVersion>6.5.0</npmVersion>
            <workingDirectory>src/main/webapp</workingDirectory>
        </configuration>

        <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>npm run build</id>
                <goals>
                    <goal>npm</goal>
                </goals>
                <phase>generate-resources</phase>
                <configuration>
                        <arguments>run build:prod</arguments>
                </configuration>
            </execution>

        </executions>
    </plugin>

在我的角应用程序( packaga.json )上:

代码语言:javascript
复制
"scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "build:prod": "ng build --prod --build-optimizer --base-href /myBaseUrl/"
}, 

您可以根据自己的喜好个性化脚本。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49256056

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档