-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
Stripping out inline source maps #1
Comments
Can you please confirm that the version you are using is the v1? |
Yes, I'm on
It seems like everything should work, but it's removing the css source map comment entirely. |
I just discovered an
This adds support for inline maps. Is this configuration exposed to users of |
As mentioned in the readme gulp-sourcemaps is the blessed way to do source maps in gulp. You shouldn't have to mess around with individual plugins source map settings. |
Hmmm, I'll give that another shot. I tried to setup source maps with gulp-sourcemaps but was not able to successfully do so. |
https://github.com/floridoo/gulp-sourcemaps does not support sass/scss at the moment. I opened an issue with them, but I still with the source maps configs were exposed via this plugin. |
My Solution
For the record, here is the final working task:
|
After upgrading to gulp-autoprefixer v1.0.0: var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
gulp.task('styles', function () {
return gulp.src('src/styles/bootstrap.less')
.pipe($.sourcemaps.init())
.pipe($.less())
.pipe($.autoprefixer())
.pipe($.sourcemaps.write())
.pipe(gulp.dest('./build/css'));
}); $ gulp styles
[09:58:04] Using gulpfile .\gulpfile.js
[09:58:04] Starting 'styles'...
events.js:72
throw er; // Unhandled 'error' event
^
Error: SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, or the source map's "file" property. Both were omitted.
at SourceMapGenerator_applySourceMap [as applySourceMap] (.\node_modules\gulp-autoprefixer\node_modules\vinyl-sourcemaps-apply\node_modules\source-map\lib\source-map\source-map-generator.js:171:17)
at applySourceMap (.\node_modules\gulp-autoprefixer\node_modules\vinyl-sourcemaps-apply\index.js:11:15)
at DestroyableTransform._transform (.\node_modules\gulp-autoprefixer\index.js:35:5)
at DestroyableTransform.Transform._read (.\node_modules\gulp-autoprefixer\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:184:10)
at DestroyableTransform.Transform._write (.\node_modules\gulp-autoprefixer\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:172:12)
at doWrite (.\node_modules\gulp-autoprefixer\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:237:10)
at writeOrBuffer (.\node_modules\gulp-autoprefixer\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:227:5)
at DestroyableTransform.Writable.write (.\node_modules\gulp-autoprefixer\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:194:11)
at write (.\node_modules\gulp-less\node_modules\through2\node_modules\readable-stream\lib\_stream_readable.js:605:24)
at flow (.\node_modules\gulp-less\node_modules\through2\node_modules\readable-stream\lib\_stream_readable.js:614:7) Any ideas on how to fix it? |
I'm having the same problems as @andrewjmead. When I run my SCSS files through
|
@antwan1986 Are you sure that |
If I've read the
My folder structure is as follows:
My sourcemapPath in this instance would be correct, no? from |
@antwan1986 Your sourcemapPath would be correct then. Can you try copying the rest of my task and seeing if that helps? Our look identical (and mine works) except for a few plugin options. |
I'm having the same problem as @antwan1986 - I would like to use the external sourcemap but autoprefixer keeps overwriting the /*# sourceMappingURL=css.map */ if I follow the docs for gulp-autoprefixer, gulp-ruby-sass and gulp-sourcemaps. @andrewjmead I tried your set up, but that gave me inline sourcemaps. This is the closest I've got to getting it right, but a second map called This is my gulpfile:
And this is what node has to say when I run
I've tried moving |
@MandyMadeThis I was unable to find a working combination aside from the one I posted 😦 |
Just retried your suggestions myself @andrewjmead, the sourcemap stays inline for me :( |
Yeah, you might have to use inline maps (I have to). Are they not working or is there some other reason why you need external source maps? |
I need them to be external for my production environments. I find them useful to have on production servers for easier debugging, however, the source map size can be considerable and there's no point in putting that extra weight onto the client / customer if they'll never use it themselves. |
@sindresorhus I agree. The issue is that the two main SASS gulp tasks, |
@antwan1986 Here is a good solution for external sourcemaps.
|
@andrewjmead - will this solution strip the inline sourcemap from the CSS file after the task runs? Or will you have both an external .map file and an inline soucemap? |
@MandyMadeThis I should have clarified 😄. This solution starts with an inline sourcemap (all In the end, you have a css file with a path reference to an external sourcemap 😄! |
@andrewjmead I am trying your solution but once Resulting in a
|
@jayzawrotny this is more complicated (as it includes prepending some vendor css) and working for me (pardon the coffee) gulp = require('gulp')
autoprefixer = require('gulp-autoprefixer')
sass = require('gulp-sass')
reload = require('browser-sync').reload
sourcemaps = require('gulp-sourcemaps')
filter = require('gulp-filter')
merge = require('merge-stream')
concat = require('gulp-concat')
gulp.task('css', ->
vendor = gulp.src([
'node_modules/normalize.css/normalize.css'
])
main = gulp.src(['app/assets/css/main.sass'])
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(sourcemaps.write())
.pipe(sourcemaps.init(loadMaps: true))
.pipe(autoprefixer())
.pipe(sourcemaps.write())
merge(vendor, main)
.pipe(sourcemaps.init(loadMaps: true))
.pipe(concat("main.css"))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('public/css'))
.pipe(filter('**/*.css'))
.pipe(reload(stream: true))
) |
I am having the same issue as @jayzawrotny, this works fine:
and as soon as I uncomment the @aaronjensen I think your solution only works if your src is a single file, not a glob |
@valdelama I did a quick write up of my solution (it's also posted above): http://www.devworkflows.com/posts/getting-scss-auto-prefixer-and-source-map-to-play-nice/ |
@andrewjmead Thanks, I tried your solution and it did create a .map file but it wasn't recognised in chrome dev tools, or at least I couldn't see the .scss source files. If I use my code from above (with autoprefixer commented out) then I have inline sourcemaps that are picked up by chrome automatically. Also from what I can tell from the documentation it is now recommended to not use the gulp-sass built in sourcemaps and instead use gulp-sourcemaps for all plugins. |
@valdelama I'm with you. The issue is that the gulp plugin (in this case gulp-sass) needs to explicitly support If the |
@andrewjmead gulp-sass does support it now, that's why if you check my code above you will see that this works fine (using gulp-sourcemaps):
but as soon as I uncomment the line calling gulp-autoprefixer then I get the |
@valdelama that does not work. This does: #1 (comment) |
I believe the problem is w/ autoprefixer, they either dont' support |
@andrewjmead you may consider updating your post now that gulp.task('sass:custom', function () {
return gulp.src('theme/scss/styles.scss')
.pipe(sourcemaps.init())
// Convert sass into css
.pipe(sass())
// Catch any SCSS errors and prevent them from crashing gulp
.on('error', function (error) {
console.error(error);
this.emit('end');
})
.pipe(sourcemaps.write())
// Load existing internal sourcemap
.pipe(sourcemaps.init({loadMaps: true}))
// Autoprefix properties
.pipe(autoprefixer({
browsers: ['last 2 versions']
}))
// Write final .map file
.pipe(sourcemaps.write('./'))
// Save the CSS
.pipe(gulp.dest('./theme/css'));
}); |
@aaronjensen I will 😄 |
@aaronjensen @andrewjmead I did try that method as well and I get a different kind of error, like this: |
Cool, maybe my method broke with the latest gulp-sass update. I'll check it out. |
@valdelama you've got latest gulp-autoprefixer and gulp-sass? could you paste the entire task? |
@aaronjensen Package versions:
Pasting the complete tasks is kind of difficult because it's broken up into multiple small reusable parts via lazy pipes but here's the relevant code:
It's part of a pretty large gulp file to replace the rails asset pipeline. Am I right in thinking that the way this should work in an ideal world is like this (simplified demo):
? |
@valdelama looks like it's the same as mine, more or less. The only difference is I'm only passing one file through, perhaps that makes a difference in this house of cards :/ I believe what you pasted is how it should work, but it sounds like the problem is not w/ |
I needed to use gulp-ruby-sass because my project is also using compass and gulp-sass does not support compass. So I came up with a solution and it's working beautifully. Here is what it looks like:
|
@aaronjensen I'm unable to get gulp-sass to work with gulp-sourcemaps. I'm getting bad map files and duplicate map files: http://cl.ly/image/312o373X432e The core.css.map file also does not work. |
@andrewjmead i'm not sure how the collabs feel about this becoming the sass/autoprefixer sourcemaps support thread, but maybe you could put your gulp task in here, it sounds like maybe you're writing to a file twice |
@aaronjensen Sorry, I just copied your example 😄. My old way still works, so I'm just going to keep using that. |
@aaronjensen @andrewjmead Just FYI, based on this comment I got it kind of working. Working as in I have sourcemaps and they lead me to the right file via dev tools however line numbers are wrong (as the original commentor mentions) and I still get the
|
Pretty sure the issue is related to libsass outputting an incorrect sourcemap, autoprefixer runs fine when provided a proper sourcemap. Check that without autoprefixer that your sourcemap in devtools maps to the correct line in .scss, in my case it was either null or the last line of the file. It'll be fixed with libsass 3.2, more info here |
@andrewjmead @aaronjensen @antwan1986 @valdelama There was an update to I've provided code examples that worked for me for inline and external sourcemaps with embedded or external sources. You can see them here. |
I though it was an issue with
gulp-sass
, but it turns out thatgulp-autoprefixer
was the culprit.Problematic Task
Issue
After the scss is compiled into css, it has inline source maps that look like the following
Once that file is run through autoprefixer, the source maps don't exist. I wasn't able to find any documenation
The text was updated successfully, but these errors were encountered: