我正在构建一个在WAR静态资源中打包的Java web应用程序。这些静态资源是通过角-CLI构建的。
Maven构建通过Eirslett的maven-frontend-plugin、npm脚本和npm触发ng构建。
问题是,我希望根据Maven构建参数使用自定义base href,并且我没有通过环境变量或参数将它传递给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>package.json
"scripts": {
(...)
"build": "ng build --prod --env=prod --bh=process.env.test --base-href=process.env.test",
(...)
}发布于 2018-05-01 11:21:10
我正在解决类似的问题,方法是让in (假设在package.json中有正则的角-clipackage.json条目):
pom.xml
...
<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>部分中具有默认值。
发布于 2018-08-17 15:39:05
我需要将Maven项目版本传递给我的NPM脚本,下面的代码与exec-maven-plugin一起为我工作
pom.xml
<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中
"scripts": {
"my-npm-script": "echo %mvn_prj_vrsn% &&[my other commands]
}以上是用于windows的,如果使用Linux的话。
$mvn_prj_vrsn发布于 2019-09-30 11:16:31
这个解决方案对我有效:在我的pom.xml :我调用我的脚本运行构建:prod
<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 )上:
"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/"
}, 您可以根据自己的喜好个性化脚本。
https://stackoverflow.com/questions/49256056
复制相似问题