0.1.3 • Published 5 years ago

@isunkui/gulp-html-url-prefix-suffix v0.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

gulp-html-url-prefix

a plugin of gulp for cdn prefix or suffix version url

install

npm i @isunkui/gulp-html-url-prefix-suffix -D

options

  • options - type: object
    • prefix: String, default
    • suffix: Boolean, default false
    • attrdata: Array, default ["img:src", "img:srcset", "img:s-src", "img:data-src", "script:src", "link:href"]
urlPrefix({
  prefix: '//cdn.xxx.com'
})

example

index.html

<!DOCTYPE html>
<html>
  <head>
    <link href="./css/example.css" />
  </head>
  <body>
    <img src="./example.jpg" />
    <script type="text/javascript" src="./js/example.js"></script>
  </body>
</html>

gulpfile.js

var urlPrefix = require('gulp-html-url-prefix'),
  gulp = require('gulp');

gulp.task('url', function() {
  gulp.src(['index.html'])
    .pipe(urlPrefix({
      prefix: '//cdn.xxx.com',
      suffix: true, // url末尾追加 ?v=1545376218218
      attrdata: ["img:src", "img:srcset", "img:s-src", "img:data-src", "script:src", "link:href"]  //自定义标签属性
    }))
    .pipe(gulp.dest('./'));
});

and the result is:

<!DOCTYPE html>
<html>
  <head>
    <link href="//cdn.xxx.com/css/example.css?v=1545376218218" />
  </head>
  <body>
    <img src="//cdn.xxx.com/example.jpg?v=1545376218218" />
    <script type="text/javascript" src="//cdn.xxx.com/js/example.js?v=1545376218218"></script>
  </body>
</html>

License

MIT