Gen*_*ful 46 maven typescript bower angular
我是Angular2的新手.我的项目的技术堆栈是Angular2,其中包含typescript和spring作为后端.我不想按照指示使用节点服务器来编译我的前端,但我需要使用TOMCAT和Maven.我有几个问题.
任何人都可以给我一步一步的指导来创建一个Angular2 + Spring应用程序,使用'bower或任何其他工具进行前端任务管理,例如缩小文件,创建应用程序支架'和'Maven for backend task management'?我愿意接受任何建议.
Ste*_*ark 33
我在使用maven的Angular 2 + Spring Boot应用程序中使用typescript .ts文件.我运行npm install for dependencies和npm run tsc将.ts文件转换为.js由exec-maven-plugin.
下面是我的pom.xml中的插件部分.在我的应用程序中,pacakge.json,tsconfig.json和typings.json都在src/main/resources路径下,所以在路径下运行npm任务
的pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.5.RELEASE</version>
</parent>
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>exec-npm-install</id>
<phase>generate-sources</phase>
<configuration>
<workingDirectory>${project.basedir}/src/main/resources</workingDirectory>
<executable>npm</executable>
<arguments>
<argument>install</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
<execution>
<id>exec-npm-run-tsc</id>
<phase>generate-sources</phase>
<configuration>
<workingDirectory>${project.basedir}/src/main/resources</workingDirectory>
<executable>npm</executable>
<arguments>
<argument>run</argument>
<argument>tsc</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我的Angular2 + Spring Boot应用程序文件夹结构如下所示
src/main/resources
/app - .ts and converted .js
/css
/images
/js - systemjs.config.js is also placed here
/node_modules - generated by npm install and will include in war
/typings
application.properties
package.json
tsconfig.json
typings.json
src/main/webapp
/WEB-INF
/jsp - all .jsp files
Run Code Online (Sandbox Code Playgroud)
在.jsp文件头部分,包括systemjs.config.js
<script type="text/javascript" src="webjars/zone.js/0.6.12/dist/zone.js"></script>
<script type="text/javascript" src="webjars/reflect-metadata/0.1.3/Reflect.js"></script>
<script type="text/javascript" src="webjars/systemjs/0.19.27/dist/system.js"></script>
<script type="text/javascript" src="js/systemjs.config.js"></script>
Run Code Online (Sandbox Code Playgroud)
这里还有我的WebMvcConfigurerAdapter代码到映射路径
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.my.controller")
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
if (!registry.hasMappingForPattern("/webjars/**")) {
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
if (!registry.hasMappingForPattern("/images/**")) {
registry.addResourceHandler("/images/**").addResourceLocations("classpath:/images/");
}
if (!registry.hasMappingForPattern("/css/**")) {
registry.addResourceHandler("/css/**").addResourceLocations("classpath:/css/");
}
if (!registry.hasMappingForPattern("/js/**")) {
registry.addResourceHandler("/js/**").addResourceLocations("classpath:/js/");
}
if (!registry.hasMappingForPattern("/app/**")) {
registry.addResourceHandler("/app/**").addResourceLocations("classpath:/app/");
}
if (!registry.hasMappingForPattern("/node_modules/**")) {
registry.addResourceHandler("/node_modules/**").addResourceLocations("classpath:/node_modules/");
}
}
@Bean
public InternalResourceViewResolver internalViewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setPrefix("/WEB-INF/jsp/");
viewResolver.setSuffix(".jsp");
viewResolver.setOrder(1);
return viewResolver;
}
}
Run Code Online (Sandbox Code Playgroud)
有一点我想提一下,如果操作系统是Windows或Mac,那么在eclipse上运行exec-maven-plugin会有一些黑客攻击.Linux(Ubuntu)看起来没什么问题.当在Windows或Mac上从eclipse运行构建时,问题是它不理解npm命令并尝试找到这样的文件,即使maven构建在终端或命令窗口上完全没问题.
为了解决这个问题,我做了一些调整.对于Mac,在/ usr/bin路径下为节点和npm创建符号链接,如下所示.但是不允许修改/ usr/bin,所以我在恢复磁盘重启后完成了
lrwxr-xr-x 1 root wheel 17 May 22 03:01 node -> ../local/bin/node
lrwxr-xr-x 1 root wheel 44 May 22 02:50 npm -> ../local/lib/node_modules/npm/bin/npm-cli.js
Run Code Online (Sandbox Code Playgroud)
对于Windows,我在系统路径下创建了node.bat和npm.bat文件,如下所示.在Windows 10上,maven构建完全没有eclipse和命令窗口.
npm.bat
@echo off
set arg1=%1
set arg2=%2
set arg3=%3
set arg4=%4
C:\Progra~1\nodejs\npm.cmd %arg1% %arg2% %arg3% %arg4%
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
43007 次 |
| 最近记录: |