gulp-assign
Installation
npm i -D gulp-assign
Usage
└── src/
├── css/
│ ├── lib/
│ │ ├── a.css
│ │ └── b.css
│ ├── a.css
│ └── b.css
├── js/
│ ├── lib/
│ │ ├── a.js
│ │ └── b.js
│ ├── a.js
│ └── b.js
└── index.html
<link rel="stylesheet" href="css/a.css" />
<link rel="stylesheet" href="css/b.css" />
<script src="js/lib/a.js"></script>
<script src="js/lib/b.js"></script>
<script src="js/a.js"></script>
<script src="js/b.js"></script>
var assign = require('gulp-assign');
var streamAssignee = function(inputs, output) {
return gulp.src(inputs, {base: 'src'})
.pipe(concat(output.relative))
.pipe(gulp.dest('dist'));
};
var callbackAssignee = function(inputs, output, callback) {
gulp.src(inputs, {base: 'src'})
.pipe(concat(output.relative))
.pipe(gulp.dest('dist'))
.on('error', callback)
.on('end', callback);
};
var assignees = {
css: streamAssignee,
js: {
default: streamAssignee,
lib: callbackAssignee
}
};
gulp.task('pack', function() {
return gulp.src('src/**/*.html')
.pipe(assign(assignees))
.pipe(gulp.dest('dist'));
});
Results
└── dist/
├── css/
│ └── main.css
├── js/
│ ├── main.js
│ └── main.lib.js
└── index.html
<link rel="stylesheet" href="/css/main.css" />
<script src="./js/main.lib.js"></script>
<script src="./js/main.js"></script>