{"action":"created","issue":{"url":"https://api.github.com/repos/jonathanepollack/gulp-minify-css/issues/89","labels_url":"https://api.github.com/repos/jonathanepollack/gulp-minify-css/issues/89/labels{/name}","comments_url":"https://api.github.com/repos/jonathanepollack/gulp-minify-css/issues/89/comments","events_url":"https://api.github.com/repos/jonathanepollack/gulp-minify-css/issues/89/events","html_url":"https://github.com/jonathanepollack/gulp-minify-css/issues/89","id":70448141,"number":89,"title":"Issue with sourcemap sources paths with relative files and base","user":{"login":"jayschab","id":1414862,"avatar_url":"https://avatars.githubusercontent.com/u/1414862?v=3","gravatar_id":"","url":"https://api.github.com/users/jayschab","html_url":"https://github.com/jayschab","followers_url":"https://api.github.com/users/jayschab/followers","following_url":"https://api.github.com/users/jayschab/following{/other_user}","gists_url":"https://api.github.com/users/jayschab/gists{/gist_id}","starred_url":"https://api.github.com/users/jayschab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jayschab/subscriptions","organizations_url":"https://api.github.com/users/jayschab/orgs","repos_url":"https://api.github.com/users/jayschab/repos","events_url":"https://api.github.com/users/jayschab/events{/privacy}","received_events_url":"https://api.github.com/users/jayschab/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/jonathanepollack/gulp-minify-css/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-04-23T16:00:46Z","updated_at":"2015-05-02T23:03:24Z","closed_at":null,"body":"Hi there.\r\n\r\nThere seem to be many doubts and issues related to `gulp-sass` and sourcemaps in longer pipelines. So let me preface by saying I hope I'm not adding to the confusion :smile: \r\n\r\nMy problem is getting sourcemaps to work with `gulp-sass` and this plugin. Here is my gulp file:\r\n\r\n````javascript\r\nvar gulp         = require('gulp');  //gulp@3.8.11\r\nvar config       = require('../config').sass;\r\nvar merge = require('merge');\r\nvar replace = require('gulp-replace');\r\nvar gIf = require('gulp-if');\r\n\r\n// Tools\r\nvar sass         = require('gulp-sass');  //gulp-sass@1.3.3\r\nvar sourcemaps   = require('gulp-sourcemaps'); //gulp-sourcemaps@1.5.2\r\nvar autoprefixer = require('gulp-autoprefixer'); //gulp-autoprefixer@2.1.0\r\nvar minifyCss = require('gulp-minify-css'); //gulp-minify-css@1.1.0\r\n\r\n// List of browser string syntax for autoprefixer: https://github.com/ai/browserslist#queries\r\nvar supportedBrowsers = ['Chrome >= 11', 'Firefox >= 6', 'Explorer >= 10', 'Opera >= 5', 'Safari >= 5'];\r\n\r\ngulp.task('sass', function () {\r\n  var bowerIncludePaths = config.bowerIncludes.map(function(path) { return config.bowerDir + \"/\" + path; });\r\n  var topLevelFiles = config.topLevelFiles.map(function(name) { return config.srcDirectory + name + \".scss\"; });\r\n\r\n  return gulp.src( topLevelFiles, {base: config.srcDirectory} )\r\n    .pipe(sourcemaps.init())\r\n    .pipe( sass( merge(config.settings, { includePaths: bowerIncludePaths })) )\r\n    .pipe( minifyCss( ) ) // now minify\r\n    .pipe(sourcemaps.write(\".\", {debug: true}))\r\n    .pipe(gulp.dest(config.dest))\r\n});\r\n````\r\n\r\nSo `base` ends up being `./gulp/assets/stylesheets` and `topLevelFiles` paths like `./gulp/assets/stylesheets/application.scss'` and bowerIncludePaths paths like `./bower_components/bootstrap-sass/vendor/assets/stylesheets`\r\n\r\nAfter running `gulp-sass` it stores sources relative to `base` so for example `/path/to/project/gulp/assets/stylesheets/vendor/example.scss` is stored under `vendor/example.scss` (the code for this is [here](https://github.com/dlmanning/gulp-sass/blob/v1.3.3/index.js#L53)).\r\n\r\nWhen running `gulp-minify-css` I get an issue that the paths are made relative to the root again. On [line 43](https://github.com/jonathanepollack/gulp-minify-css/blob/v1.1.0/index.js#L43) we have the code:\r\n\r\n````javascript\r\nreturn path.relative(file.base, src === '$stdin' ? file.path : src);\r\n````\r\n\r\nHere `file.base` is still `./gulp/assets/stylesheets`, `src` is the relative path from earlier (`vendor/example.scss` for example). So the call becomes:\r\n\r\n````javascript\r\nreturn path.relative('./gulp/assets/stylesheets', 'vendor/example.scss');\r\n=>  '../../../vendor/example.scss'\r\n````\r\n\r\nSo when `gulp-sourcemaps` tries to load the sources for writing I get the errors (with `debug: true`):\r\n\r\n````\r\ngulp-sourcemap-write: No source content for '../../../vendor/example.scss'\r\ngulp-sourcemap-write: source file not found: /path/to/project/vendor/example.scss\r\n````\r\n\r\nThe only way I was able to get it to work was to change line 43 to be more similar to `gulp-sass` \r\n````javascript\r\n   var absPath = src === '$stdin' ? file.path : path.resolve(file.base, src)\r\n   return path.relative(file.base, absPath);\r\n````\r\n\r\nIf it looks like this change makes sense I can make a PR. Does this looks like a reasonable solution? Or is this plugin doing the correct thing and the problem is in one of the other plugins?"},"comment":{"url":"https://api.github.com/repos/jonathanepollack/gulp-minify-css/issues/comments/98415831","html_url":"https://github.com/jonathanepollack/gulp-minify-css/issues/89#issuecomment-98415831","issue_url":"https://api.github.com/repos/jonathanepollack/gulp-minify-css/issues/89","id":98415831,"user":{"login":"clempat","id":2178406,"avatar_url":"https://avatars.githubusercontent.com/u/2178406?v=3","gravatar_id":"","url":"https://api.github.com/users/clempat","html_url":"https://github.com/clempat","followers_url":"https://api.github.com/users/clempat/followers","following_url":"https://api.github.com/users/clempat/following{/other_user}","gists_url":"https://api.github.com/users/clempat/gists{/gist_id}","starred_url":"https://api.github.com/users/clempat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/clempat/subscriptions","organizations_url":"https://api.github.com/users/clempat/orgs","repos_url":"https://api.github.com/users/clempat/repos","events_url":"https://api.github.com/users/clempat/events{/privacy}","received_events_url":"https://api.github.com/users/clempat/received_events","type":"User","site_admin":false},"created_at":"2015-05-02T23:03:24Z","updated_at":"2015-05-02T23:03:24Z","body":"I will take a look deeper tomorrow. I am wondering if it is connected to the root defined which give the relative path back... If u had the path of the css as root like `fileOptions.root = options.relativeTo || path.resolve(path.dirname(file.path));` Only one test fails... Concerning stylus but as I never use stylus I dont know why it triggers a problem..."}}