javascript - What is the correct way of handling dependencies if back end and front end code is in the same repository?
问题描述
I have got a project where the back end Node.js and the front end Vue.js code is in the same repository.
They share dependencies via package.json
. There are common dependencies needed for both parts, and there dependencies specific either to the front end part or to the back end part.
How the project is built and run:
The front end part is built with:
npm install
npm run build
After this the front end part is compiled to dist
folder and then put into a docker image where the server would run it.
The server code and node_modules
are also put to the same image and then the server is run with:
npm run start
Problem:
Because of the shared dependencies the node_modules
folder (needed to run the server part) includes the front end dependencies which makes it ridiculously huge. I manged to decrease the size by excluding dev depnedencies via npm install --only=production
, but I would prefer not having to manage them at all.
Questions:
- How to split the server and the client dependencies and reduce the size of the resulting image?
- What is the best practice to run the back end code in such setup? I think it should not require
node_modules
and should include the dependencies just like the front end distribution does. How to achieve this? Is is a recommended way? - Are there any other concerns in using
node_modules
directly in production?
解决方案
推荐阅读
- excel - 需要了解 Row() 函数在 SUMPRODUCT 下是如何工作的
- reactjs - 如何使用下一个配置修复“冲突:多个资产发射到同一个块 css 文件名”?
- sql - 如何将多个表名作为参数传递给直线蜂巢查询
- sed - 用符号 ^ 测试 sed
- python - 出现无法导入“folium”错误,不知道该怎么做
- linux - 如何查找包含特定文件的所有子目录,然后在这些子目录中 grep 另一个文件?
- python - 删除其值中的对象时,Active Directory 中的 member 和 memberOf 字段是否会更新?
- reactjs - 仅当状态改变时才使用效果
- scala - 我正在尝试从 s3 存储桶加载数据,但我无法加载
- java - 在 Firebase 数据库 Android Java 中写入新的整数数据