Skip to content

Commit 06c1706

Browse files
committed
1 parent c575a8b commit 06c1706

File tree

10 files changed

+81
-4
lines changed

10 files changed

+81
-4
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
sandbox
44
node_modules
55
coverage
6-
test/**/*.generated.*
6+
test/**/*.generated.*
7+
test/**/*.min.css

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 2.3.0 (12/12/2016)
2+
3+
- bug fix #21 => https://github.com/scniro/gulp-clean-css/issues/21
4+
- adding back vinyl-sourcemaps-apply
5+
16
# 2.2.2 (12/12/2016)
27

38
- clean-css release update, 3.4.21 => 3.4.22

index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const applySourceMap = require('vinyl-sourcemaps-apply');
12
const CleanCSS = require('clean-css');
23
const objectAssign = require('object-assign');
34
const path = require('path');
@@ -53,6 +54,17 @@ module.exports = function gulpCleanCSS(options, callback) {
5354

5455
file.contents = new Buffer(css.styles);
5556

57+
if (css.sourceMap) {
58+
59+
var map = JSON.parse(css.sourceMap);
60+
map.file = path.relative(file.base, file.path);
61+
map.sources = map.sources.map(function (src) {
62+
return path.relative(file.base, file.path)
63+
});
64+
65+
applySourceMap(file, map);
66+
}
67+
5668
cb(null, file);
5769
});
5870
};

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "gulp-clean-css",
33
"description": "Minify css with clean-css.",
44
"homepage": "https://github.com/scniro/gulp-clean-css#readme",
5-
"version": "2.2.2",
5+
"version": "2.3.0",
66
"author": "scniro",
77
"license": "MIT",
88
"bugs": {
@@ -32,7 +32,8 @@
3232
"clean-css": "^3.4.22",
3333
"gulp-util": "^3.0.7",
3434
"object-assign": "^4.1.0",
35-
"through2": "^2.0.3"
35+
"through2": "^2.0.3",
36+
"vinyl-sourcemaps-apply": "^0.2.1"
3637
},
3738
"devDependencies": {
3839
"chai": "^3.5.0",
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>gulp-clean-css: source maps</title>
6+
7+
<link rel="stylesheet" href="min/test-sass.min.css"/>
8+
</head>
9+
<body>
10+
<p>source maps</p>
11+
</body>
12+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$color: red;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@import '../a/a';
2+
3+
span {
4+
color: $color
5+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@import 'a/a';
2+
@import 'b/b';
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var express = require('express');
2+
var app = express();
3+
4+
app.set('port', 2000);
5+
6+
app.use('/', express.static(__dirname))
7+
8+
app.get('/', function(req,res) {
9+
res.sendfile('index.html');
10+
});
11+
12+
var server = app.listen(app.get('port'), function() {
13+
var port = server.address().port;
14+
console.log(`Magic happens on port ${port}`);
15+
});

test/test.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('gulp-clean-css: base functionality', function () {
2525
it('should play nicely with other plugins: gulp-sass: before', function (done) {
2626
var i = 0;
2727

28-
gulp.src(['test/fixtures/**/*.scss', '!test/fixtures/empty/**'])
28+
gulp.src(['test/fixtures/**/*.scss', '!test/fixtures/empty/**', '!test/fixtures/sourcemaps-load/**'])
2929
.pipe(gulpSass())
3030
.pipe(cleanCSS())
3131
.pipe(rename({
@@ -188,6 +188,29 @@ describe('gulp-clean-css: base functionality', function () {
188188
});
189189
});
190190

191+
it('should write sourcemaps, worrectly map output', function (done) {
192+
193+
var i = 0;
194+
195+
gulp.src('test/fixtures/sourcemaps-load/scss/test-sass.scss')
196+
.pipe(sourcemaps.init())
197+
.pipe(gulpSass())
198+
.pipe(sourcemaps.init({loadMaps: true}))
199+
.pipe(cleanCSS({sourceMapInlineSources: true}))
200+
.on('data', function (file) {
201+
i += 1;
202+
})
203+
.pipe(rename({
204+
suffix: '.min'
205+
}))
206+
.pipe(sourcemaps.write())
207+
.pipe(gulp.dest('test/fixtures/sourcemaps-load/min'))
208+
.once('end', function () {
209+
i.should.equal(1); // todo inspect mapping here
210+
done();
211+
});
212+
});
213+
191214
it('should return a warning for improper syntax', function (done) {
192215

193216
var i = 0;

0 commit comments

Comments
 (0)