angularjs – 如何配置Angular2应用程序使用Maven的打字稿?
我是Angular2.0的新手。我的项目技术栈是Angular 2.0 with typcript和spring作为后端。我不想使用节点服务器指示编译我的前端,但我需要使用TOMCAT和Maven。我有几个问题。
>我想,节点服务器为每个.ts文件生成.js和.js.map,因为浏览器只能理解.js文件。我的理解是正确的吗?如何使用Maven和Tomcat完成此任务? 任何人都可以有一步一步的指南创建AngularJS2 Spring应用程序使用’bower或一些其他工具前台任务管理,如文件缩小,创建应用程序支架’和’Maven的后端任务管理’?我欢迎任何建议。 我们的其他应用程序团队目前使用Angular 1.4与Spring,已经使用TOMCAT用于WAR部署和Maven用于所有其他任务。他们使用bower作为前端任务管理工具。如果任何人使用这样的任务管理工具设置他们的Angular2项目,任何建议将是有帮助的。任何设置指南将是伟大的。 提前致谢
我在使用maven的Angular 2 Spring Boot应用程序中使用typescript .ts文件。我运行npm安装依赖和npm运行tsc通过exec-maven插件将.ts文件转换为.js。
下面是我的pom.xml中的插件部分。在我的应用程序中,pacakge.json,tsconfig.json和typings.json都在src / main / resources路径下,因此在路径下运行npm tasks 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> 我的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 在.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> 这里也是我的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; } } 有一件事我要提到的是有一些黑客运行exec-maven-plugin在eclipse如果os是Windows或Mac。 Linux(Ubuntu)看起来没有问题。 为了解决这个问题,我做了一些调整。 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 对于Windows,我做了node.bat和npm.bat文件在系统路径下如下 npm.bat @echo off set arg1=%1 set arg2=%2 C:Progra~1nodejsnpm.cmd %arg1% %arg2% (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |