gulp-sourcemaps / gulp-sourcemaps

Sourcemap support for gulpjs.
ISC License
1.1k stars 117 forks source link

sourceRoot dosn't work on 2nd write #368

Open puggan opened 5 years ago

puggan commented 5 years ago

When writing 2 mapfiles, for exemple when making both a normal-css and a minified-css from the same less file, the path gets wrong in the 2nd map-file.

In the exemple bellow the 2nd file refers to a the file c/a/pink.less, I expected it to refer to just c/pink.less. (in my real code, 'a/' and 'c/' is the same path, just decided to use 2 different in exemple)

b/pink.css.map:

{"version":3,"sources":["pink.less"],"names":[],"mappings":"AAAA;EAAM,WAAA","file":"pink.css","sourceRoot":"a/"}

d/pink.css.map

{"version":3,"sources":["a/pink.less","pink.css"],"names":[],"mappings":"AAAA,KAAM,UAAA,CCEL","file":"pink.css","sourceRoot":"c/"}

Exemple code / gulpfile.js:

const gulp = require("gulp");
const plug = require("gulp-load-plugins")();

gulp.task("default", () => gulp
    .src("pink.less")
    .pipe(plug.sourcemaps.init())
    .pipe(plug.less())
    .pipe(plug.sourcemaps.write("./", {includeContent: false, sourceRoot: "a/"}))
    .pipe(gulp.dest("b/"))
    .pipe(plug.ignore.exclude("*.map"))
    .pipe(plug.cssnano())
    .pipe(plug.sourcemaps.write("./", {includeContent: false, sourceRoot: "c/"}))
    .pipe(gulp.dest("d/"))
);

Test:

echo 'body {color: pink}' > pink.less
npm install --save gulp@3 gulp-load-plugins gulp-sourcemaps gulp-less gulp-ignore gulp-cssnano
gulp
phated commented 5 years ago

@puggan can you provide a minimal reproduction repository?

puggan commented 5 years ago

https://gist.github.com/puggan/580a74b90e3b897ead36ab8cb26bcee0