gulpfile.babel.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import gulp from 'gulp'
  2. import del from 'del'
  3. import fs from 'fs'
  4. import path from 'path'
  5. import request from 'request'
  6. const iconUrl = [
  7. '//at.alicdn.com/t/font_587370_tp7x8hrg53lerk9.css',
  8. '//at.alicdn.com/t/font_587370_tp7x8hrg53lerk9.js',
  9. ];
  10. function path__dime(expath) {
  11. return path.join(__dirname, expath)
  12. }
  13. /**
  14. * 清理编译目录
  15. */
  16. gulp.task('clean', function () {
  17. return del.sync(['../dist'], {force: true});
  18. });
  19. /**
  20. * 更新图标库
  21. */
  22. gulp.task('updateIcon', ['clean:icon', 'down:icon'], function () {
  23. fs.readFile(path__dime('../src/assets/icon/iconfont.css'), 'utf8', function (err, data) {
  24. const regexp = /url\(('\/\/at.alicdn.com\/(\S+)'\))/g;
  25. console.log(data.toString().match(regexp));
  26. });
  27. });
  28. /**
  29. * 清空图标
  30. */
  31. gulp.task('clean:icon', function () {
  32. return del.sync(['../src/assets/icon/**.{js,css}'], {force: true});
  33. });
  34. /**
  35. * 下载图标
  36. */
  37. gulp.task('down:icon', function () {
  38. for (let i = 0; i < iconUrl.length; i++) {
  39. const fileUrl = `http:${iconUrl[i]}`;
  40. const filename = path__dime(`../src/assets/icon/iconfont${fileUrl.match(/\.(css|js)/)[0]}`);
  41. request(fileUrl).pipe(fs.createWriteStream(filename)).on('close', function () {
  42. console.log('更新完毕')
  43. });
  44. }
  45. });