搜索
javascript - gulp-useref的作用是什么?
怪我咯
怪我咯 2017-04-10 16:30:14
[JavaScript讨论组]

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'));
    });
怪我咯
怪我咯

走同样的路,发现不同的人生

全部回复(2)
大家讲道理

它可以把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>
PHP中文网

这个插件创建的文档,要注意文档编码格式。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号