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.

Prevent minified version of source maps?

See original GitHub issue

How do I prevent this plug-in from compiling a minified version of the source map? Example:

image

This is what I have in my gulpfile for this task:

// Compile Our Sass
gulp.task('sass', function() {
    return gulp.src('*.scss')
        .pipe(sourcemaps.init())
        .pipe(sass(sassOptions).on('error', sass.logError))
        .pipe(autoprefixer())
        .pipe(gulpIf('*.css', minifyCss()))
        .pipe(rename({
            suffix: '.min'
        }))
        .pipe(sourcemaps.write('./'))
        .pipe(gulp.dest('./'));
});

If I just do: .pipe(minifyCss()) it doesn’t create a .min version of oneweb.css, it just creates compressed/minified css in that file. 😦

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:31

github_iconTop GitHub Comments

2reactions
anzorbcommented, Mar 28, 2016

@jaminroe this should do it for you. This clones the source, allowing you to get to the source stream BEFORE it became the sourcemap.

var $ = require('gulp-load-plugins')();
var gulp = require('gulp');
var merge = require('merge-stream');

gulp.task('sass', function() {
    var source = gulp.src('./src/scss/index.scss')
        .pipe($.sourcemaps.init())
        // compile sass into css
        .pipe($.sass({ includePaths: './src' }).on('error', $.sass.logError))
        // autoprefix css
        .pipe($.autoprefixer(autoprefixerOptions));

    var compile = source
        .pipe($.clone())
        .pipe($.rename(packageName + '.css'))
        .pipe(gulp.dest(outputDir))
        .pipe($.sourcemaps.write('.'))
        .pipe(gulp.dest(outputDir));

    var minify = source
        .pipe($.clone())
        .pipe($.rename(packageName + '.min.css'))
        // minify
        .pipe($.cssnano())
        .pipe(gulp.dest(outputDir))

    return merge(compile, minify);
});

BTW, if you’re deploying code to production, and want to log what kind of errors your customers/users are getting (with a tool like Sentry/Raven for examples), sourcemaps of minified code will show you the real error and not a cryptic minified file one. They’re actually very useful.

2reactions
jonhurrellcommented, Jan 6, 2016

Hello. I may be able to offer some advice on this issue. FYI gulp-minify-css is deprecated, advising to use gulp-cssnano. I got around the minifying of sourcemaps by using gulp-ignore and excluding the map pattern before running nano:

gulp.task('styles', function() {

    var outputDirectory = publicDirectory + 'css/';

    return gulp.src(config.files.styles)
        .pipe(plumber({errorHandler: errorAlert}))
        .pipe(sourcemaps.init())
        .pipe(scsslint({
            'config': '.scss-lint.yml'
        }))
        .pipe(sass({
            style : 'expanded',
            includePaths: [config.files.nodeModules]
        }))
        .pipe(autoprefixer('last 2 versions'))
        .pipe(sourcemaps.write(config.files.stylesMap))
        .pipe(gulp.dest(outputDirectory))
        .pipe(ignore.exclude('*.map'))
        .pipe(rename({ suffix : '.min' }))
        .pipe(nano())
        .pipe(gulp.dest(outputDirectory))

});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Prevent minified version of source maps? · Issue #716 - GitHub
This is what I have in my gulpfile for this task: // Compile Our Sass gulp.task('sass', function() { return gulp.src('*.scss') .pipe(sourcemaps.
Read more >
Disable source maps in Chrome DevTools - Stack Overflow
Open Developer Tools, go to "Settings" for Developer Tools, then uncheck Enable JavaScript Sourcemaps under the "Sources" settings.
Read more >
How to Not Minify Source with webpack - David Walsh Blog
To prevent webpack from minifying the source, add the following to ... use devtool: 'source-map' to enable high-resolution source maps for ...
Read more >
Should I Use Source Maps in Production? | CSS-Tricks
A “source map” is a special file that connects a minified/uglified version of an asset (CSS or JavaScript) to the original authored version....
Read more >
Don't be shady, deploy your JavaScript source maps - Ctrl blog
Source code minification is beneficial, but the resulting obfuscation reduces trust and transparency. Source maps can help restore these and ...
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