angular - Angular App out of the box on localhost?
问题描述
I want to build a new app and this time I want to try to use Angular CLI 6.
The app should just service the user on localhost. And it should be DAU safe.
Until now I always worked with SpringBoot, Spring MVC and Thymleaf+Bootstreap+JQuery.
The advantage:
- Compile a .JAR file including all dependencies via maven.
- User just executed the .jar and everything works out of the box
I am not that sure if this is possible with a Spring MVC Application combined with Angular.
If I am right, the users needs to install besides Java also npm right? And to make the application running the user has to install all dependencies of Angular as well he has to use more commands instead of only java -jar file.jar like ng serve.
Are there any toolkit to make this more easy for the DAU or is what I plan not appropriate with Angular+Spring for an userfriendly/easy localhost app?
解决方案
Angular is a front-end framework for SPA solutions. Spring MVC typically does not follow the SPA architecture, and renders its own HTML webpage on each load. That is where Thymeleaf comes in, filling the template engine role.
While you can use Angular as a simple rendering library that does not feature router capabilities, and let Spring do the routing/migrating, it is not what the framework was designed for, and you might be better off with a simpler rendering library like React.
If you still choose Angular-as-a-renderer approach, you'll have to basically start a different angular app on each page load. However you can still use a single ui library structure, with a single
node_modules
folder. The Spring-produced jar has to include the static assets provided by compiling each mini Angular app.If you follow the SPA architecture, Spring has to behave like a plain API, and not produce any HTML. All communication is done via AJAX requests. You can serve the produced static files using a cdn, static file server, or include them in your Spring-produced jar file so that it is deployed and served by your Spring server. Just don't forget to add base redirect or routing to the Angular's
index.html
file.
推荐阅读
- security - 如何禁用对 3DES 密码套件的 TLS/SSL 支持?
- pyspark - 在 python 代码中添加 spark 命令的位置
- mysql - Laravel 7 SQLSTATE[HY000] [2002] 没有这样的文件或目录
- javascript - 是否有应用程序脚本功能将活动仪表板中存在的查看器信息导出到单独的 GSheet 中?
- javascript - 浏览器不会使用 Fetch 自动为 FormData 设置请求内容类型标头
- html - 如何使用 react-pdf 库绘制图表
- laravel - laravel 从子关系中获取父数据
- c# - 只读取数据表中的一行
- sql - Oracle - 以描述性方式跟踪对行所做更改的工具
- scala - sbt.librarymanagement.ResolveException:使用 sbt 插件模块在 sbt 项目中下载时出错