The results of running 'npm run dev' and 'npm run build prod' are different from each other

Currently, I am in the process of developing a progressive web app using Vue.js.

During development, I utilize the command npm run dev to initiate the local server that serves the files over at http://localhost:8080/. When it comes time to build for production, I rely on npm run build prod, which produces the output files within the project\dist directory. From there, I transfer these files onto an ISS configuration designed for single-page applications. All seemed well and good up to this point.

Lately, however, I've noticed discrepancies in the appearance (specifically with the CSS) of the app between the development and production builds. Initially, I suspected it could be due to client-side caching. Yet even after multiple attempts at clearing the cache and trying no-cache loading, it has become apparent that caching is not the root cause of the issue. The differences are truly there.

Upon further reflection, apart from certain minor CSS elements, I am uncertain what other disparities exist between the two builds. As I ponder potential causes, one aspect that caught my attention was my use of single file components in Vue with scoped CSS (denoted by the *.scoped.vue.css file names). Could there possibly be an issue when consolidating these various files into a singular entity?

It's worth mentioning that I'm relatively new to npm, webpack, and the myriad of other technologies involved in this project. For those interested in examining my current branch's build configurations, feel free to check them out here.

Any insights or ideas as to what might be causing this discrepancy?

Answer №1

While working with single file components, I faced a similar issue. It appears that the problem arises when running npm run build resulting in a single CSS file being generated without ensuring that the styles will be applied consistently. This inconsistency may lead to certain property values being ignored. To address this, I addressed the issue by adding !important to properties that were not matching up in the final build. There may be a more effective solution out there, but as a relative newcomer, this was my approach.

Answer №2

The sequence in which styles are applied during the execution of npm run build is crucial, and unfortunately beyond our control. To prevent conflicts, it is recommended to apply style scoping when utilizing Vue.js.

For each *.vue file in your project, make sure to replace

<style>
...
</style>

With

<style scoped>
...
</style> 

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

Updating text color in JavaFX for a textarea

I'm having trouble getting this to work. After checking the CSS analyzer in the scene builder, it seems that changing the text color in a textarea requires something like this: .text-area .text { -fx-fill: #1e88e5; -fx-font-size: 32px; } How ...

Organizing grid elements within the popper component

I am struggling to align the labels of options in the AutoComplete component with their respective column headers in the popper component: https://i.stack.imgur.com/0VMLe.png const CustomPopper = function (props: PopperProps) { co ...

Distribute the file disregarding it from the gitignored list using

This is the current situation: An exclusion file named .gitignore contains: node_modules npm-debug.log /index.js # this is a build output, I don't want it in the repo Another essential file called package.json consists of (only relevant sections in ...

Tips for retrieving information from a Vuetify modal window

Is it possible to retrieve data from a dialog in the VueJS Vuetify framework? Specifically, how can I access the username or password entered in the NewUserPopup.vue dialog from app.vue? App.vue = main template NewUserPopup.vue = Dialog template imported ...

What is the best way to access the entire pinia state object?

I'm looking to create a getter in my pinia store that returns all state properties. export const useFilterStore = defineStore('filterStore', { state : () : FilterState => ({ variables:[] as string[], categories:[] as s ...

JavaScript code is functioning properly on Chrome and Internet Explorer, however, it may not be working on FireFox

Despite searching through the console, I am unable to find a solution to this issue. There are two images in play here - one is supposed to appear at specific coordinates while the other should follow the mouse cursor. However, the image intended to track ...

Using a Vue computed method to compare elements in two separate arrays

Presently, I am utilizing Vue v2.x.x and dealing with an array: sectionTitles = ['Technology', 'Data', 'Poverty and Research', ...] Additionally, I have jobsData structured like this: [{'title': 'Software Engin ...

Ways to style specific dates on a datepicker?

Is there a way to customize the appearance of the first and last selected days in my ui datepicker for booking, similar to the design shown in the image linked below? var dateFormat = "DD/MM/YY", from = $("#checkin,. ...

Feeling perplexed about the installation of npm dependencies

I have two different versions of node.js/npm installed - one is 1.4.28 and the other is 3.1.0 When deploying the same application with a package.json file that includes: { "name": "server", "version": "0.0.1", "description": "JS server", "dep ...

Setting up a personalized JSPM registry configuration

I have chosen to use Verdaccio as the platform for hosting a private package. In my current project, I am looking to incorporate this package locally. The package has been successfully published and is now hosted on Verdaccio running on localhost (http://l ...

Iview Table UI Cell

Is there a way to retrieve the cell data from a library iview table in Vue.js upon clicking? I am looking to capture both the value of the cell and the title of the column, and then modify the CSS of that particular cell. For instance, clicking on one ce ...

Troubleshooting: Why isn't External CSS Functioning Properly in Broadleaf

I have encountered a question regarding the use of a custom email template in broadleaf. It seems that I am unable to apply an external CSS file and can only use inline styles. Is this normal behavior, or am I missing something? Below is how I am attempti ...

ensuring that there is no wrapping and the children have a width of 100%

Would you like to have text inputs placed in a single line inside a div without manually setting their widths? <div> <input type="text" /> <input type="text" /> <input type="text" /> </div> div { width: 300px ...

What is the best way to implement horizontal content scrolling when an arrow is tapped in mobile view?

I recently created a JS Fiddle that seems to be working fine on desktop, but in mobile view, the square boxes have horizontal scrolling. Here are the CSS codes I used for this particular issue: @media only screen and (max-width: 767px) { .product-all-con ...

Vue.js does not support sorting columns

In this specific codepen example, I have created a Vue table that allows for sorting by clicking on the column name. Although I can successfully retrieve the column name in the function and log it to the console, the columns are not sorting as expected. Wh ...

Adjust the CSS of a dynamically generated jQuery checkbox button in real-time

I am working on a project where I am creating a series of jQuery checkboxes dynamically within a loop. Here is how I am doing it: var checkbox = $('<input>').attr({type: 'checkbox', id: checkbox_id); panel.append(checkbox); panel ...

The table element fails to display in IE11 due to a rendering issue, displaying the error message: "Render error - TypeError: Object does not support the property or method 'entries'"

As someone new to web app development, I am currently working on a project that involves using Vue cli and antd components, with the additional challenge of ensuring compatibility with IE11. However, I have encountered an issue where IE11 does not render ...

Is it possible to utilize Vue 3's watch feature with primitive data types?

When I retrieve data, I want to toggle a boolean value to display the <Loading /> component. I prefer not to base my condition on array length. Therefore, I have opted for this approach. However, the <Loading /> component does not respond to ch ...

When should the data in Vue.js be updated and re-rendered?

Just starting to dip my toes into Vue.js. I want to update the data in methods and dynamically change the view based on that data. // template <div v-if="currentGraphType.type === 'foo'"> <!-- Some other graphs --> </div> &l ...

Manipulate container (div) to reveal and conceal

My jQuery was working fine until I added some more divs to my HTML. I'm now trying to toggle the opening and closing of a discussion container named discussionContainer with a click on the button replyButton. Any assistance would be highly appreciated ...