简体   繁体   English

如何使用SpringBoot和Angular2设置结构?

[英]How to setup structure with SpringBoot and Angular2?

I'm trying to use Angular2 with Springboot, but I can't set them together. 我正在尝试将Angular2与Springboot一起使用,但我无法将它们组合在一起。

I first started a springboot project, and then tried to follow the Angular 2 Tour of Heroes by johnpapa and run npm install . 我首先启动了一个springboot项目,然后尝试通过johnpapa跟随Angular 2 Tour of Heroes并运行npm install

The structure looks like below: 结构如下所示:

结构体

I have the /app folder, and the .js are compiled to resources/static/app/js . 我有/app文件夹,并且.js被编译为resources/static/app/js

Problems : 问题

1) The folder resources/static/node_modules/ has lots of files. 1)文件夹resources/static/node_modules/有很多文件。 So when running bootRun , it gets really slow and sometimes can't even refresh the files. 因此,当运行bootRun ,它变得非常慢,有时甚至无法刷新文件。 I believe I shouldn't put the node_modules there, but not sure.. 我相信我不应该把node_modules放在那里,但不确定..

2) npm install puts the files in ./node_modules so currently I copied them to static folder. 2) npm install将文件放在./node_modules所以目前我将它们复制到static文件夹。 Should I just build the node_modules to static ? 我应该将node_modules构建为static吗?

3) My structure looks hacky .. what is the best way to do it ? 3)我的结构看起来很糟糕 ..最好的方法是什么?

How to set this structure? 如何设置这个结构? Also, please let me know if I should start using grunt/gulp or some other tool to make this easier. 另外,如果我应该开始使用grunt / gulp或其他工具来让这更容易,请告诉我。

Ps.: In case anyone is interested in the johnpapa's guide: johnpapa's angular2 guide Ps。:如果有人对johnpapa的指南感兴趣: johnpapa的angular2指南

1) Remove node_modules from static folder. 1)从static文件夹中删除node_modules Your build process should bundle all the necessary modules. 您的构建过程应捆绑所有必需的模块。 node_modules is used only during build. node_modules仅在构建期间使用。

2) Do not copy node_modules into static folder 2)不要将node_modules复制到静态文件夹中

3) Remove sources from static folder. 3)从static文件夹中删除源。 That one is meant only for generated bundle + some static PROD files like index.html 那个仅用于生成的bundle +一些静态的PROD文件,比如index.html

尝试非常酷的项目建设者 Jhipster ;)

I shared on github a project that integrates Angular 2 with springboot. 我在github上分享了一个将Angular 2与springboot集成的项目。 you can check here Angular 2 with spring boot 你可以在这里查看带弹簧靴的Angular 2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM