构建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.............
请指导。
答案 0 :(得分:0)
经过大量研究后,我想出了一种在Angular中包含外部依赖关系的方法。我们只需要更新this.setState({
basket: {
itemId: 0,
itemId2: 0
}
})
文件:
package.json
这会加载库。