本文最后更新于 625 天前,其中的信息可能已经有所发展或是发生改变。
随着现在前后端分离的开发模式逐渐兴起,Java Spring+Node.js逐渐成为主流搭配。前后端分离并不只是开发模式,而是web应用的一种架构模式。在开发阶段,前后端工程师约定好数据交互接口,实现并行开发和测试;在运行阶段前后端分离模式需要对web应用进行分离部署,前后端之前使用HTTP或者其他协议进行交互请求。
然而,前后端分离模式也给我们带来了新的难题,就是构建更加繁琐。因此我们使用Maven作为项目管理工具时,可以使用frontend-maven-plugin插件来自动构建前后端。
插件介绍
让我们来看看官方介绍。
英文原文
What is this plugin meant to do?
- Let you keep your frontend and backend builds as separate as possible, by reducing the amount of interaction between them to the bare minimum; using only 1 plugin.
- Let you use Node.js and its libraries in your build process without installing Node/NPM globally for your build system
- Let you ensure that the version of Node and NPM being run is the same in every build environment
What is this plugin not meant to do?
- Not meant to replace the developer version of Node – frontend developers will still install Node on their laptops, but backend developers can run a clean build without even installing Node on their computer.
- Not meant to install Node for production uses. The Node usage is intended as part of a frontend build, running common javascript tasks such as minification, obfuscation, compression, packaging, testing etc.
中文翻译
这个插件是用来干嘛的?
- 让你的前端和后端构建用一个插件就能尽可能分离,将前后端打交道的可能性降到最低。
- 不全局安装Node/NPM也能在构建过程中使用Node.js。
- 确保每次运行Node和NPM时的构建环境相同。
这个插件不是为了:
- 替代Node开发版本环境:前端开发仍然需要在电脑上安装Node,但是后端开发者可以在不全局安装Node的情况下构建前端。
- 生产环境使用:使用Node仅仅是为了参与前端的构建,运行像精简、混淆、压缩、打包、测试等JS任务。
也就是说,这个插件是用来在Maven构建后端时同时构建前端用的,用了它,我们就可以在Maven中一键构建前端和后端。
插件配置
文章持续更新中~
插件GitHub主页:https://github.com/eirslett/frontend-maven-plugin