在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):cgross/gulp-dom-src开源软件地址(OpenSource Url):https://github.com/cgross/gulp-dom-src开源编程语言(OpenSource Language):JavaScript 89.6%开源软件介绍(OpenSource Introduction):gulp-dom-src
Examplevar gulp = require('gulp');
var domSrc = require('gulp-dom-src');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
gulp.task('default', function () {
domSrc({ file: 'index.html', selector: 'script', attribute: 'src' })
.pipe(concat('app.full.min.js'))
.pipe(uglify())
.pipe(gulp.dest('dist/'));
}); APIdomSrc(config)config.fileType: The name of the HTML file to read the tags from. config.selectorType: Any valid CSS selector. You can use complex selectors to allow flexible include/exclude logic for your tags. For example, use a selector such as config.attributeType: The name of the attribute that contains the file path. Typically config.cwdType: The directory where the paths in your tags are relative to. By default, the files references in your script or link tags are assumed to be relative to the HTML file they're read from. config.optionsType: Options passed through to the underlying domSrc.duplex(config)Creates a stream that html files can be piped into -- html files in, script or style files out. config.selector, config.attribute, config.cwdSee above End-to-End Concatenation and MinificationCombine gulp-dom-src with gulp-cheerio for a full concat & min workflow. var gulp = require('gulp');
var domSrc = require('gulp-dom-src');
var concat = require('gulp-concat');
var cssmin = require('gulp-cssmin');
var uglify = require('gulp-uglify');
var cheerio = require('gulp-cheerio');
gulp.task('css', function() {
return domSrc({file:'index.html',selector:'link',attribute:'href'})
.pipe(concat('app.full.min.css'))
.pipe(cssmin())
.pipe(gulp.dest('dist/'));
});
gulp.task('js', function() {
return domSrc({file:'index.html',selector:'script',attribute:'src'})
.pipe(concat('app.full.min.js'))
.pipe(uglify())
.pipe(gulp.dest('dist/'));
});
gulp.task('indexHtml', function() {
return gulp.src('index.html')
.pipe(cheerio(function ($) {
$('script').remove();
$('link').remove();
$('body').append('<script src="app.full.min.js"></script>');
$('head').append('<link rel="stylesheet" href="app.full.min.css">');
}))
.pipe(gulp.dest('dist/'));
}); Release History
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论