3.0.1 • Published 6 years ago
gulp-my v3.0.1
gulp-my v3.0.1
今天改了gulp-my新的版本
优化点
'"{0}{1}?t={2}"'.replace('{0}', cdn).replace('{1}', tmpstr).replace('{2}', + new Date);
在每个资源后面添加了时间戳
gulp-my v2.0.0
今天修改了gulp-my的配置问题,因为v1.0.2还要添加configfile.json,每次打包还需要修改该文件配置,比较麻烦,升级后不再依赖该文件。
Installation
npm install gulp-my
Usage
var gulp = require('gulp');
var revmy = require('gulp-my');
gulp.task('revmy', function() {
return gulp.src('./txs/**/*.html')
.pipe(revmy({
//configfile: 'configfile.json' ---old
cdn:'https://m.txli.com' //now
}))
.pipe(gulp.dest('dest/'))
});
核心代码
var reg = /\"[\/e\/]*[^\"]*(?:\.css|\.js|\.png|\.jpg|\.gif|\.jpeg)[^\"]*\"/gi;
查找html或者css文件中所有引用资源的链接地址
gulp-my v1.0.2
a plugin for gulp.js to change assert url.
e.g
Installation
npm install gulp-my
Usage
var gulp = require('gulp');
var revmy = require('gulp-my');
gulp.task('revmy', function() {
return gulp.src('./txs/**/*.html')
.pipe(revmy({
configfile: 'configfile.json'
}))
.pipe(gulp.dest('dest/'))
});
configfile.json
{
"/e/20161118": "https://tm.example.com/e/20161118",
"\"/e/2016110901": "\"https://tm.example/e/2016110901"
}
Options
configfile: the config json Object you want to search and change.
Type: String
Example
var gulp = require('gulp');
var revmy = require('gulp-my');
gulp.task('revmy', function() {
return gulp.src('test.html')
.pipe(revmy({
configfile: 'configfile.json'
}))
.pipe(gulp.dest('dest/'))
});
configfile.json
{
"\"/e/2016110901": "\"https://tm.example/e/2016110901"
}
before: test.html
<html lang="en">
<head>
<meta charset="utf-8"/>
<title></title>
<link rel="stylesheet" href="/e/2016110901/styles/test.css" type="text/css" />
</head>
<body>
<div>
<img src="/e/2016110901/images/test.png" />
</div>
<script src="/e/2016110901/scripts/test.js" type="text/javascript"></script>
</body>
</html>
after: test.html
<html lang="en">
<head>
<meta charset="utf-8"/>
<title></title>
<link rel="stylesheet" href="https://tm.example/e/2016110901/styles/test.css" type="text/css" />
</head>
<body>
<div>
<img src="https://tm.example/e/2016110901/images/test.png" />
</div>
<script src="https://tm.example/e/2016110901/scripts/test.js" type="text/javascript"></script>
</body>
</html>