Organizing Files with Identical Names in Separate Folders Using Gulp.js

I'm currently working on a forum and need to convert my CSS files to SASS. Here is the project hierarchy:

app/
         components/
                                     404/
                                             controllers/
                                                         404Ctrl.js
                                             sass/
                                                       404.scss
                                             css/
                                                       404.min.css
                                    home/

                                             controllers/
                                                         homeCtrl.js
                                             sass/
                                                  home.scss
                                             css/
                                                  home.min.css
                                  etc... many more

My goal is to minify the SCSS file and place it in the corresponding CSS folder whenever changes are made. However, I have multiple components like 404, home, authDesc, etc., and I want Gulp to process all these folders when running 'gulp sass' command.

This is what I've tried so far:

gulp.task('sass', function(done) {
  gulp.src('app/components/{COMPONENT_NAME}/sass/*.scss')
    .pipe(sass().on('error', sass.logError))
    .pipe(gulp.dest('assets/history/css'))
    .pipe(minifyCss({
      keepSpecialComments: 0
    }))
    .pipe(rename({ extname: '.min.css' }))
    .pipe(gulp.dest('app/components/{COMPONENT_NAME}/css'))
    .on('end', done);
});

However, I need to find a way to dynamically replace {COMONENT_NAME} with the desired component. Any help or suggestions would be appreciated.

EDIT

I discovered a workaround for this issue, but it's not error-free:

var PATHS_SASS = {
    scss_org : [
        'app/components/404/sass/_404.scss',
        'app/components/auth/sass/_auth.scss'
    ],  
    css_dest : [
        'app/components/404/css',
        'app/components/auth/css'
    ]

}
gulp.task('sass', function() {
  for(var i=0; i<2; i++) {
        gulp.src(PATHS_SASS.scss_org[i])
        .pipe(sass().on('error', sass.logError))
        .pipe(gulp.dest('assets/history/css'))
        .pipe(minifyCss({
          keepSpecialComments: 0
        }))
        .pipe(rename({ extname: '.min.css' }))
        .pipe(gulp.dest(PATHS_SASS.css_dest[i]))
  }

});

Answer №1

To streamline your Sass workflow, consider creating a main.scss file that acts as the central hub for importing all other Sass files. By compiling only this file, you can simplify your project structure. For a comprehensive code example, check out the repository here.

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

What is the most reliable method for converting a 32-bit unsigned integer to a big endian byte array?

Looking for a simple and reliable method to convert an unsigned integer into a four-byte-array in big endian format, with padding if necessary? Take a look at this example: Input value: 714 Output: Resulting byte array [ 0xca, 0x02, 0x00, 0x00 ]; By the ...

The useNavigate() function seems to be failing to redirect to the '/protected' route

The issue lies in the redirection process after receiving the token from the API. Although the token is successfully saved in local memory, the redirect to the intended page does not occur as expected. Instead, a manual window refresh is required to naviga ...

How can the table attribute "name" be obtained and added as the file name for DataTables in the export feature?

Having multiple tables on my page using JQuery DataTables, I find it to be a useful library. I am looking to modify the file name for exporting the data on these tables. I have several DataTables on this page This is how I initialize my tables: $(docume ...

Having difficulty locating the index of the column labeled `Clients` within a table; the result being -1

Having some trouble locating the index of the column name Customers within a table using jQuery/javascript. No matter what I try, it always returns -1 let tableDatacy = "Results_Table"; let columnName = "Customer"; let tableHeaders = [] ...

Displaying country-specific API details (such as capital and currency) in a card container when selecting a country from a dropdown menu

My objective is to display the card information for South Africa as the default value, even before entering any country's name into the search bar input field or selecting a specific country from the provided list. I am utilizing the restcountries API ...

Leveraging the powerful Google Maps API to enhance your mapping experience with

After making updates to my code, I managed to keep the Map intact while adding a script to place markers. Unfortunately, the step to add markers is not functioning properly. The data with coordinates is fetched from SQL, converted to JSON using C# and then ...

Utilizing Firebase objects across multiple files: A comprehensive guide

I apologize for my ignorance, but as I am teaching myself, I have not been able to find the answer in the available documentation. My current project involves developing a Vue application with Firebase as the backend. To utilize Firebase services, you mus ...

JavaScript : Retrieve attributes from a JSON object

Situation : I have a JSON object with multiple properties and need to send only selected properties as a JSON string to the server. Approach : To exclude certain properties from the JSON string, I utilized the Object.defineProperty() method to set enumera ...

Changing text array to field identifiers with JavaScript

Is there an elegant way in ECMAScript 6 to transform a string array generated from a map function into field names within a dynamically created object? For instance, if I receive the following output from my map function: ["checkbox1Value", "checkbox4Val ...

Eliminate border-radius property from Bootstrap 4 breadcrumb using Sass styling

Within Bootstrap 4, there exists a Sass variable known as $enable-rounded which "Enables predefined border-radius styles on various components." (https://getbootstrap.com/docs/4.1/getting-started/theming/#sass-options) I need to eliminate the rounded ...

Switching the children image source by hovering over the parent element

I have a React component that functions as a card containing a title and an image. I want the image to change upon hovering over the entire card, rather than just the img element itself. While CSS and the background property could achieve this, I prefer k ...

Directive in AngularJS fails to trigger upon form reset

I encountered an issue with a directive used within a form, specifically when clicking on a button with the type reset. The problem can be replicated on this stackblitz link. The directive I'm using is quite simple - it sets the input in an error stat ...

Step-by-step guide to swapping an element with a textarea element using javascript

My current project involves creating a user profile that includes a text box where users can describe themselves. I've already implemented a separate page for editing the profile, but now I want to add a feature where users can hover over their descri ...

The fundamental principle of starting with mobile design in Bootstrap

I'm struggling to understand the concept of "mobile first default behavior" in Bootstrap 3. If there is no breakpoint at 480px, how can Extra small devices be the default? I get that it applies to font sizes, but what about the grid system? How can I ...

Implementing conditional reduction in JavaScript arrays

I've encountered an issue with the filter and reduce methods. I am attempting to calculate the sum of "smc" values only when "A" equals 2020 from the given array below: arr = [{A:2020, smc:1},{A:2020, smc:2}, {A:2021, smc:3}] My attempted solution so ...

Changing colors on a canvas using CSS div style and JavaScript

Can anyone provide guidance on how to align these 3 divs horizontally? Also, I am wondering if it is feasible to change the color of my circle based on a variable value. If possible, could someone please demonstrate with an example function? <html& ...

Discover all NestJS elements sorted by category

I am currently working with an entity called BookEntity: @Entity() export class BookEntity { @PrimaryGeneratedColumn() @Generated("increment") public id: number @CreateDateColumn() public createdAt: Date @Column() publ ...

Unlock the capability to automatically swipe on a React Native TextInput Carousel while the user types

My challenge involves setting up a carousel with either Flatlist or ScrollView (I have tested both options). This Carousel consists of multiple TextInputs. The goal is to achieve the following: There are 4 TextInputs. When the user enters 6 digits in the ...

Modify array elements in JavaScript without the need to refresh the webpage

Upon loading the page, I am presented with a literal array as shown below: <script type="text/javascript"> var members = [ { name:"Alan Lim", id:"54700f06-a199-102c-8976-b1732b7ffc74", positions:[ { id ...

CSS: The search field's results are displayed in a width that is half of

There seems to be an issue with the search dropdown results on my website. When you click on the magnifying glass in the top menu and try to search, the results only appear as half the width of the search form. I would like to know how I can display it i ...