Webpack for customized white label sass/css styling

My goal is to produce multiple CSS files using webpack for a customizable application.

I aim to execute the webpack CSS/SASS loaders once for each unique 'brand' and have it saved into individual files. This approach is necessary because I maintain a distinct variable file for each brand and need the SASS to compile a separate CSS file for each one.

While I am aware that grunt/gulp could achieve this, I prefer not to include them in this specific project.

Answer №1

Lately, I have been dedicating time to solving this particular issue. After exploring the i18n example config on GitHub, I discovered a method that showcases how it is achievable. Essentially, the webpack configuration can be structured as an array, allowing for operations like the following:

import webpack from 'webpack';

export default [
  {
    entry: {
      'brand-1': ['path/to/vars-1.scss', 'path/to/my.scss'],
    }
    // ...
  },
  {
    entry: {
      'brand-2': ['path/to/vars-2.scss', 'path/to/my.scss'],
    }
    // ...
  },
];

In practice, you may choose to generate this list programmatically, but I opted to write it out explicitly for better comprehension. Due to our dynamic SCSS variables, I conceived a script responsible for crafting the webpack configuration and subsequently injecting the variables utilizing the sassLoader.data feature.

To streamline the process, incorporating webpack-merge is advisable to compartmentalize the configurations effectively.

const common = {
  module: {
    loaders: {
      // ...
    },
  },
};

export default BRANDS.map((brand) => (
  merge(
    common,
    {
      entry: {
        [brand.name]: [brand.variableFile, 'path/to/my.scss'],
      },
      // Additional customization if needed.
      plugins: [
        webpack.DefinePlugin({
          BRAND_NAME: brand.name,
        }),
      ],
    },
  )
));

Personally, I employ the ExtractTextPlugin approach by instantiating one for each individual brand. While uncertain of its correctness, I continue to explore how it intertwines with the CommonChunksPlugin for potential solutions.

As the journey progresses, I remain optimistic in unlocking further insights and resolving any outstanding concerns along the way.

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

The secrets of z-index: Ensuring nested elements stay behind their parent element

Check out this demo to see the problem: http://jsfiddle.net/5sqxQ/2/ I am trying to make the sub menu appear below the main menu. I also want to use JavaScript to slide the menu from underneath when hovering over the parent li element. I don't real ...

Distinct headings break up two-columned lists

Is there a way to ensure that the h2 header always stays with its list items, even if the number of list items varies? Currently, the header appears in one column and the lists appear in another column, causing them to be separated when the list count chan ...

Is there a way to organize an array of elements into three columns using PHP?

My array of menu items is being displayed on the screen in 3 columns, but I want them to appear differently without altering the HTML structure. Currently, they are listed like this: 1 2 3 4 5 6 7 8 9 I would like them to display as follows: 1 4 7 ...

Styling drop-down menus for navigation items in CSS

Recently, I created a navigation bar with various links using unordered lists and anchor tags. However, I encountered an issue with implementing dropdown functionality for specific links. Despite following the dropdown example from w3schools, my links seem ...

:selected element malfunctioning

I've been struggling to make the following code work: html <div class = "col-md-4 video text-center wrapper-q1"> <p class = "no-padding"> <input class="question1" id = "vraag1" type="radio" name="q1" value="Moon"> < ...

After the animation finishes, the CSS3 :hover effect ceases to function

There seems to be an issue with my DIV element. When hovering, the background color changes to blue. However, when a button is clicked, a class is added which animates the background color to green. After this animation, the hover effect no longer works an ...

A blank screen of errors pops up when attempting to update through a form

Encountering a white error screen when attempting to add an item using a form in Python / Django. I'm currently debugging the issue but lacking information. Any guidance on where to look next would be greatly appreciated.https://i.sstatic.net/daavn.pn ...

All pictures aligned with overflow

The first container is working fine, displaying 2 images vertically, but when there are 6 images, it overflows. The problem lies with container 2, where I want to create a horizontal list of images with overflow (only horizontal). This is the current sta ...

Creating a Dropdown Filter using Vanilla JavaScript

I am currently working on a project for one of my college courses, which involves creating a dropdown list filter using pure JavaScript to filter a grid of images in HTML/CSS. The main challenge I am facing is that this filter needs to be able to work with ...

Add a <span> element to the header element in the CSS using jQuery

Struggling to add this unique element after a specific css-class on my website powered by Wordpress: <span class="blink">_</span> I'm unable to alter the file structure, but I have the liberty to utilize CSS and jQuery. The chunk of code ...

What could be causing my Squarespace animation to function properly in Chrome but not in Safari?

I successfully implemented a typewriter animation on my Squarespace website using a Code Block and HTML code. It seems to be functioning well on Google Chrome but is not working on Safari. I recall reading that 'transform' may require additional ...

Enigmatic void appears above row upon removal of content from a single item

When I click on an item in my grid, the content of that item is moved to a modal. The modal functions properly, but I noticed that when the content is removed from the item, a space appears above it. I have found that using flexbox could solve this issue, ...

Unleash the potential of a never-ending expansion for grid cells on Canvas

ts: templateStyle = { display: 'grid', 'grid-template-columns': 'calc(25%-10px) calc(25%-10px) calc(25%-10px) calc(25%-10px)', 'grid-template-rows': '150px auto auto', 'grid-gap ...

Fix the positioning of a div in BootStrap and CSS code

Hey there, I'm relatively new to CSS/Bootstrap and currently in the process of learning. I might need to incorporate some CSS into the "chat_funcs" div, but unsure about what code to input to achieve my desired outcome. The issue at hand: What I am ...

Simple user interface height to occupy the entire browser window

Adding Tabs Dynamically ... I am attempting to design a layout using this example ... however, the issue is that the page does not utilize the full height and width of the available space... I have attempted adjusting the width and height to 100% of the ...

Centering Images Using CSS Floats

I've got this HTML code featuring images and titles: <div class="container"> <div class="box"><a href="#" class="catname"><img src="image1.jpg" class="thumb"><p>Title 1</p></a></div> <div class="box" ...

The collapsing z-index menu in Bootstrap 4 is experiencing CSS issues and is not functioning correctly

I have a bootstrap 4 menu with a slide effect that is functioning correctly, but there seems to be an issue with the z-index value I have set for it. Specifically, there is some content within a parallax jumbotron that is overlapping the menu links. I need ...

Customizing Material UI: Adjusting the visibility of slider thumb upon user interaction and value changes in the slider

In my application, I have implemented a Material UI Slider and I am looking to keep the thumb invisible until the user interacts with it. Once the user changes the slider value, I want the thumb to remain visible at that specific value. By using the CSS pr ...

Achieving a smooth sliding motion with the help of jQuery animation

Here is the code snippet: In HTML: <div> <div id="div1">12345</div> <div id="div2">67890</div> <div id="div3"><a href="#" id="slide">abcde</a></div> <div id="pad" style="display:non ...

Switch out either even or odd divs within a container

I need help figuring out how to alternate the background colors of divs within a container. I want the first one to have a red background, the second to have blue, the third red again, and so on... Here is the code I currently have: <div>...</di ...