douzao9845 2014-10-08 12:32 采纳率: 0%
浏览 40

扫描HTML以获取css和js链接,并在Gulp的任务中使用它们

Okay I am just throwing this out there. I have no knowlegde of PHP and little knowlegde of Javascript.

Is it possible to check an HTML file if header css/js links and body .js links exist?

And if yes: locate them and use them in a Gulp-task in the order they are added in the HTML file?

Example header:

<head>
<meta charset="utf-8">
<title>Website | Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="The Most Awesome" content="Website">
<link rel="stylesheet" type="text/css" href="css/normalize.css">
<link rel="stylesheet" type="text/css" href="css/barebone.css">
<link rel="stylesheet" type="text/css" href="css/custom.css"> 
</head>

Use those links in a Gulptask like:

gulp.task('css', function(){
 gulp.src("*links in html*")
.pipe(concat('main.css'))
.pipe(prefix())
.pipe(minifyCSS())
.pipe(gulp.dest('build/css'))
.pipe(connect.reload());
});

I could just declare the links in the Gulp-task but I want the Gulpfile to be as generic as possible. I want to be able to just dump my files anywhere in the folder.

  • 写回答

0条回答 默认 最新

      编辑
      预览

      报告相同问题?

      手机看
      程序员都在用的中文IT技术交流社区

      程序员都在用的中文IT技术交流社区

      专业的中文 IT 技术社区,与千万技术人共成长

      专业的中文 IT 技术社区,与千万技术人共成长

      关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

      关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

      客服 返回
      顶部