Skip to content

Commit ed04b14

Browse files
committed
First Commit
0 parents  commit ed04b14

File tree

6 files changed

+129
-0
lines changed

6 files changed

+129
-0
lines changed

.editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
10+
[*.md]
11+
trim_trailing_whitespace = false
12+
13+
[*.json]
14+
indent_style = space
15+
indent_size = 2

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
npm-debug.log
2+
node_modules/

.npmignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.editorconfig
2+
.gitignore
3+
.npmignore
4+
.idea/
5+
.git/

README.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# gulp-css-rebase
2+
3+
## Install
4+
5+
```
6+
$ npm install --save-dev gulp-css-rebase
7+
```
8+
9+
## Usage
10+
11+
```js
12+
const gulp = require('gulp');
13+
const rebase = require('gulp-css-rebase');
14+
15+
var webPath = '.', outputPath = 'dest';
16+
17+
gulp.task('default', () =>
18+
gulp.src('src/*.css')
19+
.pipe(rebase(outputPath, webPath))
20+
.pipe(gulp.dest(outputPath))
21+
);
22+
```
23+

index.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
'use strict';
2+
3+
var path = require('path');
4+
var rework = require('rework');
5+
var url = require('rework-plugin-url');
6+
var through = require('through2');
7+
var mkpath = require('mkpath');
8+
var fs = require('fs');
9+
10+
module.exports = function(filePath, publicPrefix){
11+
return through.obj(function(file, enc, cb) {
12+
if (file.isNull()) {
13+
return;
14+
}
15+
16+
if (file.isStream()){
17+
return this.emit('error', PluginError('gulp-css-rebase', 'Streaming not supported'));
18+
}
19+
20+
var adjusted = adjust(file);
21+
file.contents = new Buffer(adjusted);
22+
23+
cb(null, file);
24+
});
25+
26+
function adjust(file){
27+
var css = file.contents.toString();
28+
29+
return rework(css)
30+
.use(url(function(url) {
31+
if(!/^(data|\/|\w+:\/\/)/.test(url)){
32+
var assetPath = path.join(path.dirname(file.path), url);
33+
var assetFolder = path.basename(path.dirname(assetPath))
34+
var newPath = path.join(filePath, assetFolder, path.basename(assetPath)).replace(/[\#|\?].*$/, '');
35+
36+
mkpath(path.dirname(newPath), function(err) {
37+
if (err) {
38+
throw err;
39+
}
40+
41+
fs.createReadStream(assetPath.replace(/[\#|\?].*$/, '')).pipe(fs.createWriteStream(newPath));
42+
});
43+
44+
url = path.normalize(path.join(publicPrefix, assetFolder, path.basename(assetPath))).replace(/\\/g, '/');
45+
}
46+
47+
return url;
48+
}))
49+
.toString();
50+
}
51+
};

package.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "gulp-css-rebase",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"dependencies": {
7+
"mkpath": "^1.0.0",
8+
"rework": "^1.0.1",
9+
"rework-plugin-url": "^1.1.0",
10+
"through2": "^0.6.5"
11+
},
12+
"devDependencies": {},
13+
"scripts": {
14+
"test": "echo \"Error: no test specified\" && exit 1"
15+
},
16+
"repository": {
17+
"type": "git",
18+
"url": "git+https://github.com/RobinCK/gulp-css-rebase.git"
19+
},
20+
"author": "Igor Ognichenko <ognichenko.igor@gmail.com>",
21+
"license": "ISC",
22+
"bugs": {
23+
"url": "https://github.com/RobinCK/gulp-css-rebase/issues"
24+
},
25+
"homepage": "https://github.com/RobinCK/gulp-css-rebase#readme"
26+
"keywords": [
27+
"url-rebase",
28+
"gulp",
29+
"css",
30+
"url",
31+
"rebase"
32+
]
33+
}

0 commit comments

Comments
 (0)