Skip to content

Commit

Permalink
[vite] Trigger backend server start from vite serve command
Browse files Browse the repository at this point in the history
  • Loading branch information
m4heshd committed Jan 21, 2024
1 parent c9ed1c8 commit 011c24a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,9 @@ That's it. Now you're ready to go.

1. Set `VITE_WS_URI=http://localhost:8383/` in `.env` file

2. Run `npm run start` to start the backend
2. Run `npm run dev` to start the front-end and back-end with Vue HMR support

3. Run `npm run dev` to start the front end with Vue HMR support

4. Open the browser and visit `http://localhost:8384/`
3. Open the browser and visit `http://localhost:8384/`

**To package the application for production,**

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"private": true,
"scripts": {
"start": "node server.js",
"start-server": "node server.js",
"dev": "vite",
"build": "vite build",
"docker:up": "docker compose up --detach --build",
Expand Down
20 changes: 18 additions & 2 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
import path from 'node:path';
import {spawn} from 'node:child_process';
import {platform} from 'node:os';
import {defineConfig} from 'vite';
import vue from '@vitejs/plugin-vue';

// https://vitejs.dev/config/
export default defineConfig(async () => ({
plugins: [vue()],
export default defineConfig(async ({command}) => ({
plugins: [
vue(),
{
name: 'server-trigger',
async buildStart() {
if (command === 'serve') {
spawn(
platform() === 'win32' ? 'npm.cmd' : 'npm',
['run', 'start-server'],
{stdio: 'inherit'}
);
}
},
}
],
resolve: {
alias: {
'@': path.resolve(__dirname, './src')
Expand Down

0 comments on commit 011c24a

Please sign in to comment.