正在构建一个 Angular2
SpringBoot
应用程序,我需要将其直接部署到 tomcat
等容器,就像 war
文件一样。我能够通过安装npm
插入maven来成功做到这一点,例如:
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<workingDirectory>${angular.project.location}</workingDirectory>
<installDirectory>${angular.project.nodeinstallation}</installDirectory>
</configuration>
<executions>
<!-- It will install nodejs and npm -->
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>v9.2.0</nodeVersion>
<npmVersion>5.6.0</npmVersion>
</configuration>
</execution>
<!-- It will execute command "npm install" inside "/e2e-angular2" directory -->
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<!-- It will execute command "npm build" inside "/e2e-angular2" directory
to clean and create "/dist" directory -->
<execution>
<id>npm build</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>
</executions>
</plugin>
现在,我也在使用Ng2Charts在 UI 上构建 highcharts
的库。我可以简单地运行 npm install ng2charts
就可以了,但我想在 mvn clean install
期间安装它们,因为我不想在生产中创建附加的 npm
依赖项。
有没有办法可以使用 Maven 安装这些库?
我尝试了一些方法:
<execution>
<id>ng2charts</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
但它给了我错误:
[ERROR] [0m[1m[31mERROR in src/app/app.module.ts(48,5): Error during template compile of 'AppModule'[39m[22m[0m
[ERROR] [0m[1m[31m Could not resolve ng2-charts relative to /Users/user/Documents/workspace/MyPortal/src/frontend/src/app/app.module.ts..[39m[22m[0m
[ERROR] [0m[1m[31msrc/app/chart/chart.component.ts(5,20): error TS2307: Cannot find module 'jquery'.[39m[22m[0m
[ERROR] [0m[1m[31msrc/app/app.module.ts(23,30): error TS2307: Cannot find module 'ng2-charts'.[39m[22m[0m
[ERROR] [0m[1m[31m[39m[22m[0m.............
请指导。
最佳答案
经过大量研究,我找到了一种在 Angular 中包含外部依赖项的方法。我们只需要更新 package.json
文件:
"dependencies": {
"ng2-charts": "^1.1.0",
"jquery": "^3.3.1"
}
这会加载库。
关于java - Angular 2 : Install external library using npm through Maven,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48679465/