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

Sil*_*ier 5 maven angular-cli maven-frontend-plugin

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

Maven 构建通过 Eirslettmaven-frontend-plugin使用 npm 脚本和 npm mojo触发 ng 构建。

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

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

代码:

pom.xml

                 <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>
Run Code Online (Sandbox Code Playgroud)

包.json

"scripts": {
    (...)
    "build": "ng build --prod --env=prod --bh=process.env.test --base-href=process.env.test",
    (...)
  }
Run Code Online (Sandbox Code Playgroud)