Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to disable loading of existing source maps for the source #2409

Open
stof opened this issue Jan 16, 2020 · 2 comments
Open

Option to disable loading of existing source maps for the source #2409

stof opened this issue Jan 16, 2020 · 2 comments

Comments

@stof
Copy link

stof commented Jan 16, 2020

The old gulp-sourcemaps had a loadMaps setting to control whether existing maps should be loaded. Gulp 4 has a single setting in gulp.src which controls both enabling sourcemaps and loading existing ones.

This cause issues for me when npm packages ship their bundle files with a sourcemap while they don't ship their original source code at the same time (and so they have sourcemaps pointing to non-existent files). For such cases, I'd rather have my own source maps point me to their bundle file (that I know about) rather than to their source code (that I don't know about).
I would be great if this feature could be available again.

What version of gulp are you using?
4.0.2

What versions of npm and node are you using?
node 12.14.1
yarn 1.21.1

@stof
Copy link
Author

stof commented Jan 16, 2020

I found a workaround for that in the meantime, by resetting the sourceMap of the file after adding them but before processing them. It will still spend time loading existing source maps for nothing though so an option could still make sense:

const gulp = require('gulp')
const through2 = require('through2')
const normalizePath = require('normalize-path')
const concat = require('gulp-concat')

gulp.src('src/*.css', { sourceMaps: true})
  .pipe(through2.obj(function (file, _, cb) {
    if ('sourceMap' in file && file.isBuffer()) {
      file.sourceMap = {
        version: 3,
        names: [],
        mappings: '',
        sources: [normalizePath(file.relative)],
        sourcesContent: [file.contents.toString()]
      }
    }

    cb(null, file)
  }))
  .pipe(concat('output.css')) // Or any other processing
  .pipe(gulp.dest('css', { sourceMaps: '.' }))

@phated
Copy link
Member

phated commented Jan 20, 2020

The goal of sourcemaps being included into core is to remove all configuration options and make each option from gulp-sourcemaps into a transform stream/plugin.

Can you provide an example repo of the problem you are describing?

@phated phated added this to To do in v5 Oct 21, 2020
@phated phated moved this from To do to Nice to Have in v5 Oct 21, 2020
@phated phated removed this from Nice to Have in v5 Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

2 participants