question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add optional flag to disable sourcemaps

See original GitHub issue

We use environment specific builds, Please add optional disable flag to sourcemaps.init() to enable or disable sourcemaps generation.

global.env  = process.env.NODE_ENV  || 'DEV';

gulp.task('styles', function () {
    return gulp.src('app/styles/*.scss')
        .pipe($.plumber())
        .pipe($.rubySass({
            style: 'expanded',
            precision: 10,
            sourcemap: (env === 'DEV'), //Only enable sourcemap for DEV env.
            loadPath: ['bower_components/bourbon/dist','bower_components/compass-mixins/lib']
        }))
        .pipe($.autoprefixer('last 2 version')) 
        .pipe(gulp.dest('.tmp/styles'));
});

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
floridoocommented, Jul 25, 2014

Just use gulp-if:

[...]
.pipe(gulpif(env === 'DEV', sourcemaps.init()))
[...]
0reactions
illvartcommented, Dec 24, 2020

Without any external plugins, use Transform from node stream to return next(null, file) (whatever in development or production mode). This implementation use classes 😁

// my-project/sass-app/gulpfile.js

'use strict';

const {Transform} = require('stream');
const sourcemaps = require('gulp-sourcemaps');

class SourceMaps {
  constructor(mode = false) {
    this.mode = mode;
  }
  // private method
  #next() {
    return new Transform({objectMode: true, transform: (file, _, next) => next(null, file)});
  }
  init(...args) {
    if (this.mode) return this.#next();
    return sourcemaps.init(...args);
  }
  write(...args) {
    if (this.mode) return this.#next();
    return sourcemaps.write(...args);
  }
}

// ...

const gulp = require('gulp');
const sass = require('gulp-dart-sass');
const postcss = require('gulp-postcss');

const isProd = process.env.NODE_ENV === 'production';
const isDev = process.env.NODE_ENV === 'development' || process.env.NODE_ENV !== 'production';

function styles() {
  const sourcemapsTransform = new SourceMaps(!isProd /* or isDev */); // return next() in development

  return (
    gulp.src('./src/styles/app.scss')
      .pipe(sourcemapsTransform.init({largeFile: true}))
      .pipe(
        sass.sync({
          // [@use] resolved sass dependencies
          includePaths: ['./node_modules'],
        }).on('error', sass.logError),
      )
      .pipe(postcss([require('autoprefixer')]))
      .pipe(sourcemapsTransform.write('.', {addComment: false}))
      .pipe(gulp.dest('./dist')) // dist/app.css
  );
}

exports.styles = styles;

Then run:

$ NODE_ENV=development npx gulp styles
# or NODE_ENV=development yarn run gulp styles

You can also use SourceMaps around tasks by create/export SourceMaps as module. Example module.exports = SourceMaps and import it🔥

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there a command line flag to disable JavaScript source ...
Based on the Chromium flags list peter.sh/experiments/chromium-command-line-switches it seems there isn't any flags to disable the JavaScript Source map files ...
Read more >
Source Maps - SurviveJS
By disabling source maps, you are performing a sort of obfuscation. ... Inline source maps add the mapping data directly to the generated...
Read more >
Source Maps - Parcel
Parcel utilizes the @parcel/source-maps package for processing source maps to ensure ... Each function that adds mappings has optional offset arguments.
Read more >
Source Maps - Rollbar Docs
Getting started · 1. Raise descriptive errors from JavaScript · 2. Configure the rollbar.js SDK to support source maps · 3. Upload your...
Read more >
Source Maps | webpack surviveJS - GitHub Pages
It's possible you don't want to generate a source map for your production bundle as this makes it effortless to inspect your application....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found