I have a small personal project which I'm developing in one single repo.
The backend is a Node.js server and the front is a Vue.js application.
I want both of them to share the same package.json
The only reason I want to do that is because I want to use the "scripts: {}" of that one common package.json to execute commands that refer to either backend or frontend modules.
Is this possible ?
Would this structure make sense and work:
- my-project
- front
- {Vue.js files & folders}
- back
- {files & folders for my server}
- package.json (containining dependencies and yarn scripts for both front and back)
But does that also mean that when e.g. Vite/Vue compiles the .js files for production it will also "accidentally" include irrelevant node_modules that were actually there only for the backend to use?
UPDATE: I tried it and it's pretty clean and straightforward and works fine. I'm posting this here in case anyone is interested:
- /root
- /back (contains server files & folders)
- /front (contains Vue.js files & folders)
- package.json
- .eslintrc.cjs
- .gitignore
- vite.config.js
- yarn.lock
// contents of package.json
{
......,
...,
"type": "module",
"scripts": {
"back:start": "nodemon --experimental-modules --es-module-specifier-resolution=node ./back/server.js",
"front:start": "vite",
"front:build": "vite build",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs --fix --ignore-path .gitignore",
"start": "yarn front:build && yarn back:start"
},
"dependencies": {
.....,
...
},
"nodemonConfig": {
"ignore": [...]
},
"engines": {
"node": "^16.14.0"
}
}
I'm deploying the above on Heroku as is and Heroku simply calls yarn start and the app is built and deployed. (You'll notice I have no "devDependencies" and that's because Heroku ignores everything under "devDependencies", including vite)