The sourcemap generated by gulp is not functioning as expected

Custom Styling

custom-styles.less

@import "theme.less";
@import "layout.less";

theme.less

body { background:blue; }

layout.less

body { font-family: Arial, sans-serif; }

Build Process - Gulpfile.js

var gulp = require('gulp');
var less = require('gulp-less');
var sourcemaps = require('gulp-sourcemaps');

gulp.src('./src/assets/less/custom-styles.less')
  .pipe(less())
  .pipe(sourcemaps.init({loadMaps: true}))
  .pipe(sourcemaps.write('./'))
  .pipe(gulp.dest('./dist/css/'));

Issue: After compiling, styles.css + styles.map.css are generated but the map file fails to load on the webpage. In addition, when inspecting the page, only styles.css are visible.

Useful Tools
gulp less - https://github.com/plus3network/gulp-less
gulp-sourcemaps - https://github.com/floridoo/gulp-sourcemaps

Seeking assistance to resolve this frustrating issue. Any help would be greatly appreciated. Thank you.

Answer №1

Make sure you are not "piping" to less() without first initializing the sourcemap plugin correctly. Here is the correct way to do it:

const gulp = require('gulp');
const less = require('gulp-less');
const sourcemaps = require('gulp-sourcemaps');

gulp.src('./src/assets/less/styles.less')
  .pipe(sourcemaps.init({loadMaps: true}))
  .pipe(less()) // Ensure this line comes after init and before write
  .pipe(sourcemaps.write('./'))
  .pipe(gulp.dest('./dist/css/')); 

Answer №3

After spending some time troubleshooting, I finally figured out the solution for loading the map in my browser.

gulp.task('css-task',async function(){
    return gulp.src('project/public/sass/main.scss')
            .pipe(sourcemaps.init()) // init the source map
            .pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
            .pipe(prefix('last 2 versions'))
            .pipe(sourcemaps.write('.'))
            .pipe(gulp.dest('dist/public/css'))
            .pipe(livereload());
});

All I had to do was add loadMaps: true to my sourcemaps.init() function and everything started working perfectly again.

gulp.task('css-task',async function(){
    return gulp.src('project/public/sass/main.scss')
            .pipe(sourcemaps.init({loadMaps: true})) // init the source map 
            ...
            .pipe(sourcemaps.write('.'))
            .pipe(gulp.dest('dist/public/css'))
            .pipe(livereload());
});

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

Apply geometric principles to the physical world

In an attempt to accurately scale my geometry to match real-world dimensions in my 3D scene, I am facing some challenges. I extract the coordinates of the top left and top right corners of my map, convert them into points using Google Maps projection, an ...

Obtaining the blog slug dynamically upon clicking with ReactJS

Currently, I am developing a project using Reactjs and Nextjs. One of the tasks at hand is to obtain the "slug" value after clicking on a blog post. However, at this moment, the value returned is undefined despite trying the following code: <h4 onClic ...

Access the element generated by Bootstrap using JavaScript

When working with JS, I'm attempting to select an element created by Bootstrap, however, it consistently returns an undefined response. The element looks like this: <input class="form-control form-control-sm search-input" type="searc ...

What is the method for accessing State in a Class component using a concatenated String?

Looking to change up the typical method of using this.state, I am interested in utilizing a combined string instead. import React, { Component } from "react"; class Test extends Component { constructor(props) { super(props); this.sta ...

Shift every ng-repeat child element and display the updated outcome

I am looking to create an animation that will shift all items displayed using the ng-repeat directive to the left, hide the first item, and show a new element in place of the last one. The elements are being displayed using the ng-repeat directive from a ...

Seeking a solution for resolving the problem with HTML1402 when using jquery URL in Internet Explorer?

Why is it that only IE (and not any other browser) gives me the error HTML1402: Character reference is missing an ending semi-colon “;” with this code: <!DOCTYPE HTML> <html> <head> <script src="http://code ...

What is the best way to eliminate the ng-hide class dynamically in AngularJS?

https://i.sstatic.net/ShZ3n.pnghttps://i.sstatic.net/n7UsG.pngI need to implement the image upload feature and facing an issue <div class="container responsiveImageSet"> <div ng-show="imageLoader" style="text-align: center;"> <img cla ...

Omitting "a" elements with a designated ancestor from a jQuery scroll operation

I successfully added smooth scrolling to my webpage using the provided script. However, I also have a section with tabs where I do not want the smooth scrolling effect. Here is my jQuery code: $('a[href*="#"]') // Remove links that don&apos ...

The CSS background image in PNG format displays a white line at the beginning of the transparency

How can I remove the white border that appears on PNG images with transparency when used as a background with CSS on retina devices? .background { background: url('../image.png') no-repeat; } ...

What is the best method to send the HTML button ID to a Python file through Django?

I have the following HTML code snippet that generates dynamic buttons: {% for i in loop_times %} <button type="submit" class="'btn btn-lg" name="{{ i }}" id="{{ i }}" onclick="alert(this.id)" formmethod="post"><a href="{% url 'button ...

What is the best method for sending the primary key value to DynamoDB?

I am currently working on a nodejs app where I am using putItem() to insert data into DynamoDB. The table has a primary key named "id". My goal is to generate a UUID and assign it as the value for the primary key every time new data is inserted. However, w ...

Asynchronous execution of a MongoDB query using a loop iteration

My current code for updating multiple documents is not functioning properly because it contains multiple res.json calls. for (i = 0; i < dateArray.length; i ++ ) { Trucks.update({ 'data.date': dateArray[i] }, {'$set': update}, ...

javascript function not being invoked

Currently, I have incorporated the following HTML <html> <head> <Title>EBAY Search</title> </head> <script language="JavaScript" src="ajaxlib.js"></script> <body> Click here & ...

Trouble aligning items in a fieldset with Bootstrap

While working on a wire frame, I am attempting to create the HTML structure based on it. The required structure that needs to be built is outlined in this diagram: https://i.sstatic.net/ypp2f.png Progress has been made on aligning elements using a two-col ...

The internal browser scrollbar in IE 11 is proving to be impossible to remove, even with the use of simplebar

After facing severe performance problems when using perfect-scrollbar and ngx-perfect-scrollbar with Angular 2 in IE11, I had to make the difficult decision to move away from them. With a large project underway and numerous components being initialized sim ...

Ways to update the hidden field's value within a foreach loop when the change event occurs?

On my page, I have input fields and foreach conditions set up. <form action="process.php" name="employee" method="post"> <input type="text" name="name" class="onchangefield"> < ...

Modify the selected toggle buttons' color by utilizing the MUI ThemeProvider

I am currently working on customizing the color of selected toggle buttons within my React app using TypeScript and ThemeProvider from @mui/material 5.11.13. Despite my efforts, when a toggle button is selected, it still retains the default color #1976d2, ...

Track the number of HTML5 drag and drop operations by adding a counter to your HTML form

I've implemented a cool feature on my web page where users can drag list items into a dustbin, and the item gets eaten up by the dustbin. The interaction works perfectly thanks to the code I already have in place. Now, I'm looking to add a counte ...

At smaller desktop resolutions, the 1px border thickness for tables may fluctuate

The border thickness of my table is inconsistent at 1px. This issue only occurs in smaller desktop breakpoints and works fine on higher resolutions. Attached below is a screenshot for reference. https://i.sstatic.net/gPsaT.png Below is the code I used to ...

How can you style a two-item list in Material-UI React to display the items side by side?

I have a list that contains two items: 'label' and 'value'. This is the current layout: https://i.stack.imgur.com/HufX7.png How can I rearrange the items on the right to be positioned next to the label on the left? https://i.stack.im ...