首页 > gulp-useref的作用是什么?

gulp-useref的作用是什么?

The following example will parse the build blocks in the HTML, replace them and pass those files through. Assets inside the build blocks will be concatenated and passed through in a stream as well.


    var gulp = require('gulp'),
        useref = require('gulp-useref');
    
    gulp.task('default', function () {
        return gulp.src('app/*.html')
            .pipe(useref()) //有没有这句话似乎没什么影响
            .pipe(gulp.dest('dist'));
    });

它可以把html里零碎的这些引入合并成一个文件,但是它不负责代码压缩。

var gulp = require('gulp'),
        useref = require('gulp-useref');
    
    gulp.task('default', function () {
        return gulp.src('app/*.html')
            .pipe(useref()) // 建议题主好好熟悉一下gulp,这句话有没有不影响gulp执行,但是如果你要用gulp-useref就肯定没效果了。
            .pipe(gulp.dest('dist'));
    });

An example of this in completed form can be seen below:

<html>
<head>
    <!-- build:css css/combined.css -->
    <link href="css/one.css" rel="stylesheet">
    <link href="css/two.css" rel="stylesheet">
    <!-- endbuild -->
</head>
<body>
    <!-- build:js scripts/combined.js -->
    <script type="text/javascript" src="scripts/one.js"></script> 
    <script type="text/javascript" src="scripts/two.js"></script> 
    <!-- endbuild -->
</body>
</html>

The resulting HTML would be:

<html>
<head>
    <link rel="stylesheet" href="css/combined.css"/>
</head>
<body>
    <script src="scripts/combined.js"></script> 
</body>
</html>
【热门文章】
【热门文章】