0

I am newbie to VueJS and using VueJS 3 to build a basic portfolio website with backend as GoLang and VueJS as frontend. I am facing issue where local build when we run server saying "npm run serve" looks different and when we build production code which creates dist folder and to run it say "npm serve -s dist" and that gives a different look to website. How to avoid that and make local and production build look same. By looks I mean CSS doesn't load up properly.

My folder structure :

project_root
├── Dockerfile.backend
├── Dockerfile.frontend
├── README.md
├── backend
│   ├── config
│   ├── db
│   ├── handlers
│   ├── main.go
│   └── models
├── docker-compose.yaml
├── frontend
│   ├── README.md
│   ├── babel.config.js
│   ├── dist
│   ├── jsconfig.json
│   ├── nginx.conf
│   ├── node_modules
│   ├── package-lock.json
│   ├── package.json
│   ├── public
│   ├── src
│   ├── vite.config.js
│   └── vue.config.js
├── go.mod
├── go.sum
└── webapp.db

vue.config.js

const webpack = require('webpack');

module.exports = {
  configureWebpack: {
    plugins: [
      new webpack.DefinePlugin({
        '__VUE_OPTIONS_API__': JSON.stringify(true),
        '__VUE_PROD_DEVTOOLS__': JSON.stringify(false),
        '__VUE_PROD_HYDRATION_MISMATCH_DETAILS__': JSON.stringify(false) // Define the feature flag here
      })
    ]
  },
  publicPath: './',
};

vite.config.js

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

export default defineConfig({
  plugins: [vue()],
  define: {
    '__VUE_OPTIONS_API__': true,
    '__VUE_PROD_DEVTOOLS__': false,
    '__VUE_PROD_HYDRATION_MISMATCH_DETAILS__': false // Define the feature flag here
  }
});

Attaching screenshots of the website

Local Development Served

Dist Build Production

I used vite.config.js which was not present earlier in my codebase, but that too did not help. I observed that my main.css hasnt loaded in dist build folder.

4
  • npm serve runs in memory and does not create anything in the dist folder. css is better connected via import in the js file. in this case, webpack will include it normally. Commented Jul 21 at 15:51
  • so what do you suggest here @AlexeyObukhov can you please elaborate
    – akash24
    Commented Jul 21 at 16:04
  • Why do you have both vue.config.js and vite.config.js?
    – huan feng
    Commented Jul 22 at 2:14
  • I dont have idea, I probably read a suggestion to include vite config so I added it. As said I am new to VueJS, am not sure where to head out.
    – akash24
    Commented Jul 22 at 4:13

0

Browse other questions tagged or ask your own question.