Installations
npm install gulp-replace-src
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>=0.10.0
Node Version
5.4.0
NPM Version
3.3.12
Score
68.8
Supply Chain
93
Quality
68.9
Maintenance
50
Vulnerability
94.6
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (62.22%)
HTML (30.61%)
CSS (7.17%)
Developer
git-lt
Download Statistics
Total Downloads
1,336
Last Day
1
Last Week
4
Last Month
15
Last Year
103
GitHub Statistics
2 Stars
3 Commits
3 Watching
1 Branches
1 Contributors
Bundle Size
260.90 kB
Minified
69.47 kB
Minified + Gzipped
Package Meta Information
Latest Version
0.0.1
Package Id
gulp-replace-src@0.0.1
Size
11.18 kB
NPM Version
3.3.12
Node Version
5.4.0
Total Downloads
Cumulative downloads
Total Downloads
1,336
Last day
0%
1
Compared to previous day
Last week
33.3%
4
Compared to previous week
Last month
200%
15
Compared to previous month
Last year
-39.4%
103
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
功能
将页面中css或js的路径,替换成 gulp-rev
生成的文件路径,或者将css或js内容嵌入到页面
Install
1npm install --save-dev gulp-replace-src
Usage
假如初始目录结构如下:
.
└── src
├── index.css
├── index.html
└── index.js
构建后
.
├── src
│ ├── index.css
│ ├── index.html
│ └── index.js
├── dist
│ ├── index-2e878f392c.css
│ ├── index-46c50a1b39.js
│ ├── index.css
│ ├── index.js
│ └── rev-manifest.json
├── gulpfile.js
├── index.html
└── package.json
部分代码示例,详情看 example
目录下的例子
1var DEBUG = false; 2 3gulp.task("build:css", function() { 4 return gulp.src('src/index.css') 5 .pipe(autoprefixer({ 6 browsers: ['last 2 Chrome versions', 'safari 5', 'ios 7', 'android 4'], 7 cascade: false 8 })) 9 .pipe(postcss([px2rem({remUnit: 75})])) 10 .pipe(gulpif(!DEBUG, csso())) 11 .pipe(gulp.dest("dist/")); 12}); 13 14gulp.task("build:js", function() { 15 return gulp.src('src/index.js') 16 .pipe(gulpif(!DEBUG, uglify())) 17 .pipe(gulp.dest('dist/')); 18}); 19 20gulp.task("version", function() { 21 return gulp.src(['dist/*.css','dist/*.js']) 22 .pipe(rev()) 23 .pipe(gulp.dest('dist/')) 24 .pipe(rev.manifest()) 25 .pipe(gulp.dest('dist/')); 26}); 27 28gulp.task('clean', function(){ 29 return gulp.src(['dist/*.*',], {read: false}) 30 .pipe(clean()); 31}) 32 33gulp.task("replace", function() { 34 var manifest = JSON.parse(fs.readFileSync('dist/rev-manifest.json').toString("utf-8")); 35 36 gulp.src('src/index.html') 37 .pipe(srcReplace({ 38 manifest: manifest, 39 rootPath: 'dist/', 40 basePath: 'dist/', 41 hash: false, 42 inline: !DEBUG 43 })) 44 .pipe(gulp.dest('./')); 45}); 46 47gulp.task('default',['clean'],function(done){ 48 gulpSequence('build:css', 'build:js', 'version', 'replace', done); 49})
这里如果 DEBUG=true
, 路径不会被inline,hash=true
替换成新的文件名
1<!DOCTYPE html> 2<html> 3 <head> 4 <meta charset="utf-8"> 5 <title>示例</title> 6 <link rel="stylesheet" href="dist/index-10017c60ef.css" inline charset="utf-8"> 7 </head> 8 <body> 9 <div class="demo"> 10 示例 11 </div> 12 <div class="img size60"></div> 13 <script src="dist/index-512b43116a.js" charset="utf-8" inline></script> 14 </body> 15</html> 16
hash=false
, 添加时间戳参数
1<!DOCTYPE html> 2<html> 3 <head> 4 <meta charset="utf-8"> 5 <title>示例</title> 6 <link rel="stylesheet" href="dist/index.css?v=20160826000229" inline="" charset="utf-8"> 7 </head> 8 <body> 9 <div class="demo"> 10 示例 11 </div> 12 <div class="img size60"></div> 13 <script src="dist/index.js?v=20160826000229" charset="utf-8"></script> 14 </body> 15</html> 16
DEBUG=false
时, inline=true,此时直接将构建好的源文件inline到页面中
1<!DOCTYPE html> 2<html> 3 <head> 4 <meta charset="utf-8"> 5 <title>示例</title> 6 <style> 7body{background:#f4f4f4;color:#333;font-family:"Helvetica Neue",Helvetica,Microsoft YaHei,Arial,sans-serif;font-size:.186667rem;line-height:1.27;-webkit-text-size-adjust:100%!important;-webkit-user-select:none;user-select:none;-webkit-font-smoothing:antialiased} 8</style> 9 </head> 10 <body> 11 <div class="demo"> 12 示例 13 </div> 14 <div class="img size60"></div> 15 <script> 16function onDisplay(e){"none"==document.getElementById(e).style.display?$show(e):$hide(e)}function onLabelTxt(e,t,n,o){"none"==document.getElementById(e).style.display?($show(e),document.getElementById(t).value=o):($hide(e),document.getElementById(t).value=n)} 17</script> 18 </body> 19</html> 20
options
1{ 2 manifest:{}, 3 hash:false, //如果为true,文件名将会替换成添加md5后缀的新文件名,如果不设置,将给地址添加query参数 时间戳?v=20170422112122 4 basePath:'', //替换之后文件的根路径,如果设置此项,css与js最终发布的根路径都将使用此配置,如果不设置,将使用原来的路径或下面独立的配置 5 basePathCSS:'', //用于生成的css发布路径 6 basePathJS:'', //用于生成的js发布路径 7 8 inline:true, //是否要嵌入到页面,些配置为true时,标签必须携带 inline 属性,方便针对个别资源inline 9 rootPath:'', //【必填】替换文件的根路径,如果设置此项,那么css与js的替换文件查找将使用此配置 10 rootPathCSS:'', //css替换文件的根路径,用于查找css的替换文件 11 rootPathJS:'', //js替换文件的根路径,用于查找js的替换文件 12}
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 0/3 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
3
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to gulp-replace-src
gulp-replace-image-src
replace the "src" attribute with specific path of "img" tags in HTML files
gulp-replace-image-src-from-data-attr
replace the "src" attribute with specific path of "img" in "data-local-src" attribute of HTML files (or any attribute you specify)
gulp-rewrite-image-path
Convert and replace src attrs within your data. Based on catindev/gulp-inline-image-path.
gulp-datasrc-html
Replace src, srcset to data-src, data-srcset supports lazzyloading