I want to use vitejs over phoenix trough bun. The first thing I did was add watcher to config/dev.exs
config :my_app, MyAppWeb.Endpoint,
# Binding to loopback ipv4 address prevents access from other machines.
# Change to `ip: {0, 0, 0, 0}` to allow access from other machines.
http: [ip: {127, 0, 0, 1}, port: 4000],
check_origin: false,
code_reloader: true,
debug_errors: true,
secret_key_base: "",
watchers: [
bun: ~w(run dev)
]
and vite.config.js
import { fileURLToPath, URL } from "node:url";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
process.on("SIGINT", () => {
console.log("Received SIGINT, stopping watcher...");
process.exit(0);
});
process.on("SIGTERM", () => {
console.log("Received SIGTERM, stopping watcher...");
process.exit(0);
});
// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()],
resolve: {
alias: {
"~/": fileURLToPath(new URL("./", import.meta.url)),
},
},
server: {
host: "0.0.0.0",
port: 3001,
cors: true,
origin: "http://0.0.0.0:4000",
},
build: {
outDir: "../../priv/static",
emptyOutDir: true,
manifest: true,
rollupOptions: {
input: {
main: fileURLToPath(new URL("./assets/main.js", import.meta.url)),
},
},
},
});
and it works, but when phx server is stoped and terminal released, bun
is not stoped, and vite
still locking port 3001, and when i run again mix phx.server
, vite
starts on next available port 3001, and so on. Looks like bun does not receive SIGINT | SIGTERM.
So question is – how to stop automatically bun
and unlock port 3001.
And one thing more, when i run bun run dev
directly in terminal, i have pretty colorized output, it would be nice to have the same output trough mix phx.server
command, and usually i run server trough command iex -S mix phx.server
, to keep elixir shell input, i would like to keep this two things if it possible.