Is it possible for webpack to combine css/scss/less files without creating duplicate entries for required files?

Consider this scenario where I have two components that need the same utility css file directly.

Component one:

import component1Css from '/path/to/component1.scss'
import someOtherUtilityCss from './path/to/some-other-css.scss'
...
export default Component1;

Component two:

import component2Css from './path/to/component2.scss'
import someOtherUtilityCss from './path/to/some-other-css.scss'
...
export default Component2;

Including them in my app:

Main App:

import someLayoutCss from './path/to/some-layout.css';
import Component1 from './path/to/component1'
import Component2 from './path/to/component2'

...

export default App;

I want the bundling system to import some-other-css.scss only once. Is it handled by the style-loader + css-loader combination by default?

Moreover,

How are internal css imports managed?

If I import cssFile1 and cssFile2 in JavaScript like this:

import cssFile1 from 'path/to/file1.scss'
import cssFile2 from 'path/to/file2.scss'

And both cssFile1 and cssFile2 contain imports of cssFile3, will cssFile3 be duplicated in both cssFile1 and cssFile2? Or does the sass-loader handle this issue and include cssFile3 only once?

Answer №1

The official documentation mentions the process of deduplication:

Deduplication

When using libraries with complex dependency trees, it is possible for certain files to be identical. Webpack has the ability to detect these duplicate files and eliminate them. This ensures that duplicated code is not included in your bundle and instead a single copy of the function is used at runtime.

I have yet to test this feature myself.

Answer №2

In my opinion, the sass-loader is equipped to eliminate any duplicate entries that may arise.
However, if there is no CSS present in the project, duplicates can still occur.
One potential solution is to utilize the webpack configuration feature known as resolveLoader in order to address and prevent any duplications.

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 a div's border using JavaScript

I recently generated a div element dynamically through code. var Element; Element = document.createElement('div'); My goal now is to modify the right and bottom borders to "#CCCCCC 1px solid". I aim to achieve this without relying on any exte ...

having difficulties in separating the mat-table header

It may seem like a basic question, but I'm having trouble figuring it out. I'm not sure if this requires a CSS change or something else. I'm looking to add a divider between my table header similar to the one highlighted in the screenshot be ...

How can I activate the fancy box from a specific div element?

There are plenty of variations to this question, but none of them seem to help. I am looking for a way to trigger fancybox from a div. Here is the div in question: <div class="port web">Website</div> This particular div has some CSS styles ap ...

Picture remains unchanged in Chrome

I'm struggling to understand why my images do not resize when I shrink or resize my Chrome window. Can someone help me out with an explanation? I've been trying for some time now but still can't seem to crack it, and I haven't found the ...

Troubleshooting Alignment Problems within Bootstrap Containers

As I embark on my journey of constructing my inaugural website using Bootstrap 4, a wave of questions has flooded my mind. These queries either remain unanswered or beckon for further clarification. Shall we dive into them? Is it considered standard pr ...

Card flipping functionality is not functional on Internet Explorer browsers (versions 11, 10, and below)

After coming across a tutorial on CSS3 transform by David Desandro, I tried implementing the code but unfortunately, it does not work in Internet Explorer... I noticed that clicking "flip" only results in Card 1 being displayed while card 2 remains hidden ...

Incorporate personalized fonts onto your website

After downloading the Arimo font from Google Fonts, I decided to create a master page and a stylesheet for it. Here is the code I wrote: @font-face{ font-family:"Arimo"; src: url('../Fonts/Arimo/Arimo-Regular.ttf'),format('truetype& ...

Is there a way to eliminate the default bootstrap stylings?

Currently working on a project where I am utilizing bootstrap scripts to simplify things. However, upon adding everything along with the CSS, bootstrap ends up changing parts of my page that I did not intend for it to do. Is there a way to remove these u ...

Materialize CSS dropdown select arrow out of position

Here is a snapshot of the Materialize CSS, which can be viewed at: However, I am encountering an issue where the dropdown arrow appears below the list instead of on the side. I am currently using Django 3. How can I resolve this? https://i.sstatic.net/d ...

What is the CSS method for determining the distance from the top of a container to the edge of the window?

I am working on a basic HTML layout that contains a few elements, including a scrollable div container located below them. Since the height of unknown-height is uncertain due to dynamic element generation, I need a simple method to enable scrolling in the ...

Is my PHP code impacted by this CSS styling?

After applying the CSS styles below to my login form, I am encountering an issue where my POST variables are showing up as NULL upon form submission. What could be causing this? Below is the CSS code used: #wrapper #Box input[type=text], textarea, input[ ...

A guide on incorporating the CSS 'content' property with the 'option' tag

Is it possible to include CSS 'content' in the 'option' tag? For example, I want to display "Name: Volvo". <html> <head> <style> option:before { content: "Name: "; } </style> </head> <body> ...

Ensure that the width of the inner table matches the width of its contents within an overflowing div

I'm facing an issue with a table inside a div styled as table-wrapper: .table-wrapper { display: inline-block; overflow-x: scroll; width: 800px; } Although I want the div to display a horizontal scrollbar so that the table inside it can ...

CSS-only countdown animation

I've been experimenting with a pure HTML/CSS countdown animation, but I'm facing challenges in getting it to run smoothly. Currently, I'm focusing on minutes and seconds only. One issue I encountered is that the digit representing tens of mi ...

Revamp the website's design

I am looking to revamp the color theme of my website with just a click of a button. Can someone provide me with a link to a reference website where I can get some inspiration? ...

The drop-down menu appears to be falling behind the 'content' div element

Whenever I try to hover over the dropdown menu, it frustratingly appears behind the content div that I painstakingly created. Despite all my efforts with z-index adjustments, the issue still persists. Below you'll find all the code for my website, but ...

Troubleshooting issues with custom Bootstrap CSS implementation

I've been working on a website using Twitter Bootstrap and I wanted to add an interesting dynamic where an image starts off as grayscale and then transitions to full color when hovered over. Instead of modifying the Bootstrap.css, I decided to create ...

vue Delay loading the component content until it is requested

As a newcomer to Vue, I have come across a problem recently. Let's say I have numerous popups with heavy content that is only needed when requested. I realized that my initial approach was incorrect (using Vue Router to render the content, but it didn ...

Designing the Irish flag solely with HTML and CSS: a step-by-step guide

I have successfully created the Indian flag using HTML and CSS, with the exception of the Ashok Chakra. Now, I am looking to create the Irish flag which features a vertical tricolor design, unlike the horizontal tricolor layout of the Indian flag. Can anyo ...

Issue with the carousel feature displaying multiple images in Bootstrap 4.3

I attempted to create a Carousel using bootstrap that displays multiple images in a row and slides one image at a time, similar to this: https://i.sstatic.net/tw22R.png I followed this post. Instead of using bootstrap-3.3.6 and jquery-2.2.2, I used boots ...