0

I'm developing a mini board game with Vue.js frontend and Django backend. Currently, I use Django to serve the static files under a /static directory, and I configured vite.config.js to output the build result to that directory under Django's base directory.

Now I want to use DevTools to debug the frontend. I've got the frontend to run successfully with npm run dev. However, now I want to test the interoperability with backend, and due to the Same-Origin Policy, it needs to be served by the source as the api endpoints. So I made the following configurations:

import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueDevTools(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
  build: {
    define: {
      '__VUE_PROD_DEVTOOLS__': true, // Force Vue DevTools to be available
    },
    sourcemap: true,
    watch: true,
    minify: false,
    rollupOptions: {
      output: {
        entryFileNames: 'src/[name].js',
        chunkFileNames: 'chunks/[name].js',
        assetFileNames: 'assets/[name].[ext]'
      }
    },
    outDir: '../backend/static'
  }
})
import './assets/main.css'

import { createApp } from 'vue'
import { createRouter, createWebHistory } from 'vue-router'
import App from './App.vue'
import Game from './Game.vue'
import Login from './Login.vue'
import Register from './Register.vue'

const routes = [
    { path: '/', component: Game },
    { path: '/loginpage', component: Login },
    { path: '/registerpage', component: Register },
];

const router = createRouter({
    history: createWebHistory(),
    routes: routes
});


const app = createApp(App);

app.config.devtools = true;

app.use(router);
app.mount('#app');

But the devtools extension for firefox complains about Vue.js is detected on this page. Devtools inspection is not available because it's in production mode or explicitly disabled by the author.

How can I fix it? Thanks!

4
  • You should not need any kind of crazy configuration to have the devtools to be available (the force part is probably overkill). Meanwhile, it's weird that your app is seen as a bundle for production because it should be running just fine with a dev mode. You could maybe give a look to this one, it's using PHP and Vue but some pieces of the Vite config might be helpful to you maybe? I had a nicely working Vue inside of a PHP app with Vue devtools working with nothing extra. Maybe double-check that you're using the latest version of them?
    – kissu
    Commented Jan 25 at 10:37
  • @kissu In dev mode, do you mean using npm run dev? In that mode the Django server won't be running on the same port, and I don't have api access on my backend. How should I fix it? Commented Jan 25 at 11:56
  • Yes, this is what I meant. I don't see how it is a problem overall: you could (and should actually) have your backend server running on some port, while your frontend is running on another port. If you build your app, how do you expect to work efficiently on it and have all the debugging tools? There's a reason there is a dev and a build mode. If you want to relax your SOP, you should use CORS. This is very common in modern setups to whitelist the entry point for your frontend port.
    – kissu
    Commented Jan 25 at 12:52
  • Even better, I would recommend you to simply use Django as an API on one port and have a VueJS alongside (as in another project in some other Git repo) on another port so that both your backend and frontend are properly separated. Might be easier to deploy both of them and you have a precise separation of concerns that way too. You could of course totally include VueJS inside of your Django app and workaround the Vite config with something like what I linked above, but I am not sure about the benefits that it will bring to the table as a whole besides the SOP/CORS minor details.
    – kissu
    Commented Jan 25 at 13:02

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.