gulp-merge-asset
v1.0.25
Published
Used to merge image, video, audio files into one directory and meantime remove duplicate files. It supports both css files and html files.
Downloads
2
Maintainers
Readme
Used to merge image files into one directory without modifying any web code. It supports both css files and html files.
Usage
var gulp = require('gulp'),
gulpif = require('gulp-if'),
mergeAsset = require("gulp-merge-asset");
gulp.task('default', function () {
var fileStore = {};
return gulp.src('app/*.html')
.pipe(gulpif("*.html", mergeAsset({fileStore: fileStore, fileType: "html", deleteSrcAsset: true, targetDirAbsolutePath: "merged-assets"})))
.pipe(gulpif("*.css", mergeAsset({fileStore: fileStore, fileType: "css", deleteSrcAsset: true, targetDirAbsolutePath: "merged-assets"})));
});
The referred asset files(imgs, videos, audios, etc.) will be copied to folder: 'merged-assets' with name changed to "SHA1-XXXX"('XXXX' is the sha1 value of the referred asset) style. The source files will be deleted with deleteSrcAsset
set to true.
Options
options.fileStore
Type: Object
Default: null
File store is used to store the relationship between the original asset path and the expected calculated final path.
Set to {}
to satisfy use case: 'One asset is referred for more than one times'.
options.fileType
Type: String
Default: css
Currently only css
and html
are supported(case insensitive).
options.deleteSrcAsset
Type: Boolean
Default: false
Whether or not delete the source files when merging assets.
Be cautious when set as true
if the same file will be processed more than 1 times.
options.targetDirAbsolutePath
Type: String
Default: merged-assets
The target folder where asset files will be merged into.
options.resolveReferenceRelativeTo
Type: String
Default: path.dirname(currentVinylFilePath)
The base folder used to resolve new relative path to refer merged img.
License
MIT