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

Incorrect source map when "to" option passed #64

Closed
htanjo opened this issue Dec 14, 2015 · 13 comments
Closed

Incorrect source map when "to" option passed #64

htanjo opened this issue Dec 14, 2015 · 13 comments

Comments

@htanjo
Copy link

htanjo commented Dec 14, 2015

I'm using gulp-sass, gulp-postcss and gulp-sourcemaps in my project.
When I set to option in the postcss(), the source map content is incorrect.

gulp.src('app/styles/*.scss')
  .pipe($.sourcemaps.init({loadMaps: true}))
  .pipe($.sass().on('error', $.sass.logError))
  .pipe($.postcss(processors, {to: '.tmp/styles/main.css'}))
  .pipe($.sourcemaps.write('.'))
  .pipe(gulp.dest('.tmp/styles'))

postcss-sourcemaps

Without to option, I could get proper source map, but some postcss plugins need this option.
Am I overlooking something, or is this bug?

I created simple gulp tasks to reproduce this issue. I hope this helps.
https://github.com/htanjo/postcss-sourcemaps-test

@TrySound
Copy link
Member

@htanjo Which plugins need this option?

@htanjo
Copy link
Author

htanjo commented Dec 15, 2015

In my project, postcss-copy-assets requires it.
And I tried postcss-copy previously, it also depends on to option.

@w0rm
Copy link
Member

w0rm commented Dec 15, 2015

@htanjo sorry for the delay, I'm extremely busy this week, will be able to check it over the Weekend.

@htanjo
Copy link
Author

htanjo commented Dec 16, 2015

@w0rm That's ok! Thanks.

@w0rm
Copy link
Member

w0rm commented Dec 19, 2015

@htanjo I sent you a temporary fix that should work.

Sourcemaps are really complicated in gulp. The source map from the previous operation has to be combined with the sourcemap from the next operation. This only works when file from the previous map matches element from sources of the current map.

This is what was happening when the to='dist/main.css' option was set:

previousMap = {sources: [ 'main.scss' ], file: 'main.css'}
currentMap = {sources: [ '../src/main.css' ], file: 'main.css'}

Because main.css and ../src/main.css do not match, only the currentMap was output.

The additional complication comes from the base option of the gulp file, gulp source maps work relatively to the base directory, but postcss doesn't have this separation.

@w0rm
Copy link
Member

w0rm commented Dec 19, 2015

It seems that I can only properly fix this issue after this is implemented in postcss: postcss/postcss#240

@htanjo
Copy link
Author

htanjo commented Dec 21, 2015

@w0rm I see...! I understood the situation.
Your workaround is very helpful and I'll use it at the moment.
Thanks!

@alvint
Copy link

alvint commented Dec 28, 2015

I get the same issue regardless of the to option. In fact, even if I run postcss with an empty processor list and no options I have this problem. The issue is also affecting plugins which rely on postcss, such as gulp-autoprefixer.

@w0rm
Copy link
Member

w0rm commented Dec 28, 2015

@alvint hi, if it happens regardless of the to option then it's not related to this issue. Please open a separate issue and add a link to a minimal project that reproduces it. This way I will be able to help you.

Sometimes gulp-postcss is not even an issue. A previous gulp plugin may generate a wrong source map that cannot be merged, so I really need to see the code to figure out what went wrong!

@alexander-akait
Copy link

Some issue, I try to understand in detail what the problem is

@timkraut
Copy link

Any updates on that?

@w0rm
Copy link
Member

w0rm commented Sep 13, 2016

@timkraut nope and postcss/postcss#240 wasn't implemented.

@w0rm
Copy link
Member

w0rm commented Oct 23, 2016

Closing as wontfix because postcss/postcss#240 is closed.

@w0rm w0rm closed this as completed Oct 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants