"Styling mysteriously disappears from Vue project when deployed to production

While running my docker image and routing the requests through nginx, I encounter issues with the styling.

Although I can see all the html-tags and locate the css and js files in the network tab of the browser, the styling is not being applied. Even though the css appears correct to me, there seems to be no styling visible. Essentially, all html-tags appear generic and bland.

During development, I do not face any problems with the styling and I can view the styling when simply executing npm run build.

The project has been developed using vue/cli, but I have tried other templates with earlier webpack versions which resulted in the same issue.

In .vue files, I utilize the single-file-component structure and specify lang="scss".

Here is a snippet from my nginx.conf:

load_module /usr/lib/nginx/modules/ngx_stream_module.so;

stream...

http {
    server {
        listen 80;
        charset utf-8;
        server_name vue-node;

        gzip                on;
        gzip_proxied        any;
        gzip_http_version   1.1;
        gzip_comp_level     5;
        gzip_min_length     256;
        gzip_vary           on;
        gzip_types text/css text/javascript text/xml text/plain application/javascript application/x-javascript application/json;

        root /opt/vue-node/dist;
        index index.html;

        location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
            access_log off;
            expires max;
            add_header Cache-Control "public, must-revalidate, proxy-revalidate";
        }

        location /api {
            proxy_pass http://vuenode:8000;
        }

        location / {
            try_files $uri $uri/ @rewrites;
        }
        location @rewrites {
            rewrite ^(.+)$ /index.html last;
        }
    }
}

This is how my Dockerfile looks:

FROM node:9-stretch

RUN apt-get update -y && apt-get install -y --no-install-recommends \
    vim \
    nginx

COPY . /opt/vue-node/
WORKDIR /opt/vue-node/

RUN rm -v /etc/nginx/nginx.conf
ADD packaging/nginx.conf /etc/nginx/
RUN echo "daemon off;" >> /etc/nginx/nginx.conf

RUN npm install -g npm \
 && npm install -g @vue/cli \
 && npm install \
 && npm run build

CMD [ "node", "server.js" ]
EXPOSE 80

I have set NODE_ENV=production in my docker-compose.yml file.

Most everything else remains unchanged from what was initially configured by vue/cli.

If you require additional information, please do not hesitate to ask. Any assistance provided would be greatly appreciated!

Answer №1

I have finally identified the solution to my issue. It turns out that my lack of knowledge about Nginx was causing the problem.

By modifying the /etc/nginx/nginx.conf file, I inadvertently removed some essential configurations from the default nginx settings. Although I am uncertain which specific settings were impacted, I learned that it is considered a Best Practice to include custom proxy locations in /etc/nginx/sites-enabled/, which are then imported by the /etc/nginx/nginx.conf file automatically. This led me to implement the following:

Dockerfile:

COPY packaging/default.conf /etc/nginx/sites-enabled/default
COPY packaging/mongo.conf /etc/nginx/streams/available/mongo

default.conf:

# no stream module..

server {
# a simple server module..
}

mongo.conf:

stream {
# the stream module, proxy to mongodb..
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Uncertain on how to ensure CSS box positioning remains relative during resize or zoom

I am new to the world of HTML and CSS and have been attempting to create a blog at . I managed to create a header image, but I wanted to make two specific areas of the image clickable. To achieve this, I decided to create two transparent boxes named box-li ...

Establishing a class for wp_nav_menu

Is there a way to transform the following code: <ul class="ulStyle"> <li class="liStyle"> <div class="first"> <div class="second"> menu1 </div> </div> </li> </ul> into wp_nav_menu? I'm struggling with ...

Nuxt frequently experiencing crashes at short intervals

Since updating to Nuxt version 2.12.2, I've been encountering this issue intermittently every few minutes. The timing seems sporadic, but it persists consistently. The only solution so far has been to restart the server. events.js:287 throw er; ...

Using Vue components in NativeScript-Vue popups: A comprehensive guide

To initiate the popup, I include the following code in a root component: import parentt from "./parentt.vue"; . . . this.$showModal(parentt, { fullscreen: true, }); The contents of parentt.vue are as follows: <template> <StackLayout> ...

Attempting to preserve the CSS transform effect as I switch between menu options

Whenever I stop hovering over my element, it reverts back to its original position. However, I want it to remain in place when I am navigating through the "sousmenu" menu and only return to its original position when I am not hovering over the "sousmenu". ...

Why isn't my HTML list showing up on Firefox mobile browsers?

I am using jQuery mobile version 1.4.2. Here is the code snippet from my page. HTML <ul data-role="listview" class="ui-nodisc-icon ui-alt-icon"> <li><a href="#" >Real Estate in San Jose</a></li> </ul> CSS .ui-list ...

Using SVG background images in Internet Explorer versions 7 and 8: a guide to HTML, CSS,

I have created a unique SVG image to use as a background, but it's not displaying in Internet Explorer 8 and earlier versions. I tried using tools like or http://code.google.com/p/svgweb/, but they only support SVG for IMG and Object elements, not ba ...

Error with the jQuery scrolling plugin

Currently, the script is set up this way: jQuery(document).ready(function(){ var windheight = jQuery(window).height(); var windTop = jQuery(window).scrollTop(); var windbottom = windheight + windTop ; jQuery.fn.revealOnScroll = function(){ return this.e ...

Using an object does not result in updated data, while data changes are typically observed when using a variable

In the process of developing a function to update a custom checkbox upon clicking (without resorting to using the native checkbox for specific reasons). Here's the code snippet for the checkbox: <div class="tick-box" :class="{ tick: isTicked }" @ ...

Circular center button in the footer UI

Struggling with aligning a button in the footer perfectly? I have two icons on each side and while the UI is almost there, something seems off with the center icon's padding and shadow. I'm currently working with material-ui. Take a look at the i ...

Developed a visually stunning image gallery using both Bootstrap Grid and Flexbox, though there are a few images that do not completely fill the flex container

I'm currently exploring web development and experimenting with creating a responsive image gallery using Bootstrap Grid and flexbox. However, I've encountered an issue where some of the images are not filling the entire height of the flex contain ...

Overlaying Div Concealed by Background Video Filter

Whenever we add a filter to our background video, the div overlay ends up moving behind the video and becoming hidden. To see an example of this issue, check out this fiddle showcasing the background video with the text overlay: https://jsfiddle.net/dyrepk ...

Utilizing AngularJS to Implement Gradient Effects Using the ng-style Directive

Having trouble setting gradients using the angular js ng-style directive. I can successfully set normal colors using the code below: <span ng-style="{'background-color': slidercolor}">works</span> However, when trying to set a gradi ...

The advice I received was to avoid using max-width and instead utilize min-width when styling with CSS

With @media screen and (max-width:700px) { Link to image 1 Whenever I use @media screen and (min-width: 700px) { it messes up. How can I adjust it for min-width without causing issues? Link to image 2 ...

Django and Pure CSS are used to create a unique radial timer

After successfully creating a 5-minute radial timer using pure CSS, I've begun my journey with Django. I'm eager to explore whether I can take this timer to the next level and make it functional for all users who visit my page. Is it possible for ...

How can I implement a thumbnail editing feature similar to Facebook's display image uploader in an Asp.net application using c#?

How can I upload an image and display a specific part of it in a thumbnail of a custom size? I also want to personalize the appearance of the thumbnail. ...

The Vue user object appears to be null in spite of being defined and clearly visible in the log output

There seems to be an issue with my function that utilizes a person's user name to retrieve the current User from the database. Initially, when I log the current user within the function, everything works perfectly. However, once I attempt to access it ...

What are some ways to maintain the aspect ratio of an image with two dimensions?

Issue: The image is taller than the img-box container https://i.stack.imgur.com/zDBLM.png I have identified two potential solutions, but I am not satisfied with them: Removing the img-box wrapper Applying max-height and max-width properties to the img t ...

Retrieve the username after making a call to this.$auth.fetchUser() in Nuxt

Hey there, I've been trying to retrieve the username after using the fetchUser method but it keeps showing as undefined. This is how I have been attempting: async loginUser() { this.$auth.setUserToken(`${this.token}`); this.$auth.setS ...

Place the h1 text inside of a div tag for organization

Here is an example of HTML code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <tit ...