简体   繁体   English

gulp-useref与几个html文件,以及如何获取包含在资产中的文件列表

[英]gulp-useref with couple of html files and how to get list of files which included to assets

If I use gulp-useref with couple of html files, it process each time with same bundles. 如果我将gulp-useref与几个html文件一起使用,则每次使用相同的包进行处理。

  1. Is there a way to process first incoming bundle and just replace string in other files? 有没有一种方法可以处理第一个传入的包,而只是替换其他文件中的字符串? For example, if you look to code below - gulp-useref create vendor.js twice (at second time it rewrite previous file). 例如,如果您看下面的代码-gulp-useref两次创建vendor.js(第二次重写以前的文件)。 If you have a lot of files and you use minification of css and js then it can take much time depending on how many files with the same bundles you use. 如果您有很多文件,并且使用css和js的最小化,那么这可能会花费很多时间,具体取决于您使用相同捆绑包的文件数量。

  2. How I can copy other files, which not included to bundles? 如何复制未包含在捆绑软件中的其他文件?

Structure: 结构体:

html-file-1.html HTML的文件1.HTML

<!-- build:js js/vendor.js -->
<script scr="js/script-1.js"></script>
<script scr="js/script-2.js"></script>
<!-- endbuild -->
<script scr="js/file-1-script.js"></script>

html-file-2.html HTML的文件2.HTML

<!-- build:js js/vendor.js -->
<script scr="js/script-1.js"></script>
<script scr="js/script-2.js"></script>
<!-- endbuild -->
<script scr="js/file-2-script.js"></script>

Task: 任务:

var files = [],
    getExcludedFiles = function() {
       var temp = files;
       for(var i = 0; i < temp.length; i++) {
          temp[i] = "!" + temp[i]
       }

       return temp;
    };

gulp.task("useref", function() {
   var assets = useref.assets();

   return gulp.src(path_to_htmls)
              .pipe(assests)
              .pipe(some_function_to_store_bundle_files_in_some_var)
              .pipe(gulpif('*.js', uglify()))
              .pipe(assets.restore())
              .pipe(useref())
              .pipe(gulp.dest(dets_path))
});


gulp.task("js", ["useref"], function() {
   return gulp.src([path_to_JS, getExcludedFiles()])
              .pipe(gulp.dest(JS_dets_path))
});

I think gulp-cached does what you need. 我认为gulp-cached您的需求。

https://github.com/contra/gulp-cached https://github.com/contra/gulp-cached

This keeps an in-memory cache of files (and their contents) that have passed >through it. 这将对已通过的文件(及其内容)进行内存缓存。 If a file has already passed through on the last run it will not be >passed downstream. 如果文件在上次运行时已经通过,则不会>向下传递。 This means you only process what you need and save time + resources. 这意味着您只需处理所需的内容,即可节省时间和资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM