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

Error encountered when trying to connect Solidity contract with React Next.js, issue with fetching contract through NPM package

My goal is to create an NFT marketplace, but I've encountered a problem with npm run dev. It was working fine yesterday, but now it's not letting me fetch functions from NFTMarketPlace.sol after exiting VSCode. I tried deleting node_modules & ...

Web page saving fails to preserve images!

Currently working on a PHP-based website that is utilizing the Zend framework and hosted on an Apache server. The folder structure within my www directory looks like this: +www | |_+css | | | |_images | |_js | |_images The issue I'm ...

How can I retrieve the reference number of an item by clicking a button within a list item in an unordered

Presented here is a collection of data points and a button nested within an ul <ul> <li class="mix" category-1="" data-value="600.35" style="display:block;"> <figure> <figcaption> <h3> ...

Adjusting an image size using JQuery after resizing a canvas will only resize the image itself, not

How can I resize an image within a canvas using JQuery in a way that only the image is resized, not the entire canvas? function resizeImage(width, height){ var image = document.getElementById('resizeImage'), canvas = document.createEleme ...

What is the best way to create a responsive menu in code?

I am working on creating a responsive menu. Check out cuppcomputing For the desktop version, the whole panel will be displayed when it meets the max-width: 600px (tablet and mobile size). Initially, only the title is shown, and clicking on it will reveal ...

Tips for effectively communicating the functionality of npm scripts

Is there a simple method to display usage information for npm scripts? If I could run npm run and receive output similar to the following (with descriptions for each task): Lifecycle scripts included in product-discovery-service: start node server. ...

Running pre-commit eslint autofix but encountering errors that do not exist

Encountering an issue with committing changes to a file due to a failed pre-commit eslint --fix task, displaying the following errors: × eslint --fix: C:\Users\user\source\repos\project\project-frontend\src\compone ...

Error occurred during React npm module build due to failure in ./node_modules/babel-loader/lib/index.js

While setting up my React environment, I encountered two errors when running npm start in the command prompt. The first error states "module build failed (from ./node_modules/babel-loader/lib/index.js)" and the second error is "error plugin/preset files a ...

What could be causing Laravel Sail NPM to display the error message 'unsupported version of Node.js'?

In the midst of a Laravel 8 project using Docker, I find myself knee-deep in SCSS design. However, a hurdle arises when attempting to compile my SCSS files. NPM insists that my Node version is outdated at 12.x, even though within my container I am actually ...

Creating Tailored Breakpoints with Bootstrap for a Unique Design

Currently, I am delving into the world of front-end web design and taking advantage of Bootstrap for creating a responsive layout. However, I have noticed that Bootstrap only offers 5 predefined breakpoints. I am curious to know if there is a way to cust ...

The ng command seems to be malfunctioning when executed from a separate directory

After selecting a different folder for my new angular project, I encountered an error every time I tried to run an ng command: 'ng' is not recognized as an internal or external command, operable program or batch file. I attempted to resolve ...

Struggling to find the right method for inserting an element using a template in VueJS

Looking to incorporate Vue for updating my static HTML content. I want to modify certain elements by changing their inner HTML, icons, or specific parts of it, and also introduce a new element to the DOM. My preference is to utilize templates when adding a ...

npm's group registry does not impact the order that is set

Query I have set up a Nexus server for my npm registry with both private and proxy registries. Here is the configuration: Proxy: npmjs-org, remote repository: https://registry.npmjs.org Hosted: npm-hosted, manually uploaded module antd 3.20.0 to t ...

Utilize a button to apply styles to a Span element dynamically generated with JavaScript

I am attempting to spin a span generated using JavaScript when a button is clicked. The class is added to the span, but the spinning effect does not apply. <p>Click the button to create a SPAN element.</p> <button onclick="myFunction ...

vue-router: display distinct views for the same route depending on the specified condition

We are exploring options to dynamically display different views based on the authentication status of a user, leveraging vue-router I am considering two potential approaches, although I am currently unsure of how to successfully implement either: Utilize ...

Mismatched measurements: 'rem' vs 'px' - Bootstrap 4 integrated with Laravel Mix

I recently set up a new Laravel 5.4 installation with Bootstrap 4 alpha 6, but I'm encountering an issue where Laravel Mix is unable to compile SASS. Here's the specific error message: Module build failed: ModuleBuildError: Module build fail ...

Pause until the existence of document.body is confirmed

Recently, I developed a Chrome extension that runs before the page fully loads by setting the attribute "run_at": "document_start". One issue I encountered is that I need to insert a div tag into the body of the webpage as soon as it is created. However, a ...

Adjust the background of the page at regular intervals

I currently have: <script type='text/javascript'> var imageID=0; function changeimage(every_seconds){ //change the image if(!imageID){ document.getByTagName("body").src="icwXI.jpg"; imageID++; } else{if(imageID==1){ document.ge ...

Text overlaps when li element is nested inside another element

Seeking assistance in creating a CSS/HTML menu bar that triggers list elements on hover. Facing difficulty arranging the list in two columns. Code Sample:http://jsfiddle.net/Km922/1/ <!DOCTYPE html> <html lang="en"> <head> <meta ...

React's struggle with implementing flexbox functionality

Struggling to implement a calculator using React and flexbox, but running into issues with my flexbox layout. I've attempted to troubleshoot using the Chrome Dev Tools but haven't made any progress. import React, { Component } from "react"; imp ...