{"id":587,"date":"2021-04-13T18:13:06","date_gmt":"2021-04-13T10:13:06","guid":{"rendered":"http:\/\/blog.viter.top\/?p=587"},"modified":"2021-04-14T18:17:09","modified_gmt":"2021-04-14T10:17:09","slug":"gulp-src","status":"publish","type":"post","link":"https:\/\/blog.viter.top\/index.php\/2021\/04\/13\/gulp-src\/","title":{"rendered":"gulp.src"},"content":{"rendered":"\n<p>\u5185\u90e8\u4f7f\u7528node-glob\u6a21\u5757\u5b9e\u73b0\u6587\u4ef6\u5339\u914d<\/p>\n\n\n\n<p><\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>node-glob\u6a21\u5757\u88ab\u4f17\u591a\u524d\u6bb5\u6784\u5efa\u5de5\u5177\u4f7f\u7528\uff1b\u5982fis,grunt,glup\uff1b\u5185\u90e8\u4f7f\u7528\u4e86minimatch\u6765\u5339\u914d\u6587\u4ef6<\/p><\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>\u5339\u914d\u89c4\u5219<\/p><\/blockquote>\n\n\n\n<ul><li>*\u5339\u914d0\u6216\u591a\u4e2a\u4e2a\u5b57\u7b26\uff0c\u4f46\u4e0d\u5305\u62ec'\/';<code> var glob = require('glob'); var pattern = '*.js'; glob(pattern, function(err, files){ console.log(files); }); \/\/--\u83b7\u53d6\u76ee\u5f55\u4e0b\u6240\u6709js\u6587\u4ef6\uff1b<\/code><\/li><li>\uff1f\u5339\u914d1\u4e2a\u5b57\u7b26\uff1b<code> var pattern = 'node_modules\/glo?.js'; glob(pattern, function(err, files){ console.log(files); });<\/code><\/li><li>**\u5339\u914d\u591a\u4e2a\u4efb\u610f\u5b57\u7b26\uff1b<code> var pattern = 'node_modules\/**.js'; \/\/--\u5339\u914dnode_modules\u76ee\u5f55\u4e0b\u7684js\u6587\u4ef6\uff0c\u4e0d\u5339\u914d\u5b50\u76ee\u5f55\u4e2d\u7684\u6587\u4ef6\uff0c \/\/--\u5f53\u8bbe\u7f6eoptions\u4e2d\u7684matchBase:true\u65f6\u5219\u5339\u914dnode_modules\u6240\u6709\u6587\u4ef6<\/code><\/li><li>[pattren|pattern] : \u5339\u914d\u5176\u4e2d\u7684\u4e00\u4e2a\uff1b<\/li><li>\uff1f(pattern|pattern) \u5339\u914d\u5176\u4e2d\u7684\u4e00\u4e2a\u62160\u4e2a\uff1b\u4e0d\u53ef\u4ee5\u7ec4\u5408\uff1b<code> var pattern = 'node_modules\/?(a|b).js'; \/\/--\u5339\u914da.js,b.js\uff1b\u4e0d\u5339\u914dab.js<\/code><\/li><li>+(pattern|pattern) \u5339\u914d\u5176\u4e2d\u4e00\u4e2a\u6216\u591a\u4e2a\uff1b\u53ef\u4efb\u610f\u7ec4\u5408<code> var pattern = 'node_modules\/+(a|b).js' \/\/--\u5339\u914da.js,b.js,ab.js,aab.js,abb.js\uff1b\u4e0d\u5339\u914dabc.js<\/code><\/li><li>*(pattern|pattern):\u5339\u914d\u5176\u4e2d\u76840\u4e2a\u6216\u591a\u4e2a\u3002\u53ef\u4ee5\u7ec4\u5408<code> var pattren = 'node_modules\/*(a|b).js'; \/\/--\u5339\u914da.js,b.js,ab.js,aab.js,abb.js\uff1b\u4e0d\u5339\u914dabc.js<\/code><\/li><li>@(pattern|pattern):\u5339\u914d\u5176\u4e2d\u7684\u4e00\u4e2a\uff0c\u4e0d\u80fd\u4e3a\u7a7a\uff1b\u4e0d\u53ef\u7ec4\u5408\uff1b<code> var pattren = 'node_modules\/@(a|b).js'; \/\/--\u4e0e\uff1f(pattern|pattern)\u76f8\u4f3c<\/code><\/li><\/ul>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>\u6ce8\u610f\u4e8b\u9879\uff1a<\/p><\/blockquote>\n\n\n\n<ul><li>\u9ed8\u8ba4\u4e0d\u5339\u914d'.'\u5f00\u5934\u547d\u540d\u7684\u6587\u4ef6\uff1b\u5728options\u4e2d\u8bbe\u7f6edot: true\u5219\u5339\u914d\uff1b<\/li><li>\u5982\u679cpattern\u6ca1\u6709\u5339\u914d\u4efb\u4f55\u6587\u4ef6\uff0c\u9ed8\u8ba4\u8fd4\u56de[];\u5982\u679c\u9700\u8981\u8fd4\u56depattern\u672c\u7701\uff0c\u5728options\u4e2d\u8bbe\u7f6enonull:true;<\/li><\/ul>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>\u6784\u9020\u51fd\u6570Glob:<\/p><\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>    var Glob = glob.Glob;\n    new Glob(pattern,options,function(err,matchs){\n        console.log(matchs);\n    });\n<\/code><\/pre>\n\n\n\n<ul><li>\u540c\u6b65\u6267\u884c\uff1a<code> var Glob = glob.Glob; var options = { sync:true }; var gl = new Glob(pattern,options); \/\/--\u6b64\u65f6matchs\u6302\u5728\u8f7d\u5b9e\u4f8b\u5bf9\u8c61\u7684found\u5c5e\u6027\u4e0a\uff1b console.log(gl.found);<\/code><\/li><li>\u4e8b\u4ef6<code> \/\/--\u56db\u4e2a\u4e8b\u4ef6end,error,abort,match;\u5f53\u8bbe\u7f6eoptions\u7684sync:true\u65f6\u4e8b\u4ef6\u65e0\u6548\uff0c\u56e0\u4e3a\u5b9e\u4f8b\u5316\u8fd4\u56de\u7684\u662f\u5176\u4ed6\u5bf9\u8c61\uff0c\u800c\u4e0d\u662f\u5b9e\u4f8b\u5bf9\u8c61 end: \u7ed3\u675f\u4e8b\u4ef6\uff0c\u63d0\u4f9bmatchs\u53c2\u6570 error: \u9519\u8bef\u4e8b\u4ef6\uff0c\u63d0\u4f9b\u9519\u8bef\u4fe1\u606f\uff1b abort:\u7ec8\u6b62\u4e8b\u4ef6\uff0c\u5f53abort()\u65b9\u6cd5\u8c03\u7528\u65f6\u89e6\u53d1 match:\u5339\u914d\u5230\u6587\u4ef6\u65f6\u89e6\u53d1 var Glob = require('glob').Glob; var path = require('path') var src = path.resolve(__dirname,'.\/node_modules'); var pattern = '**\/*.js'; var options = { dot:true, cwd:src }; var gl = new Glob(pattern,options); gl.on('match',function (file){ console.log('match',file) }); gl.on('end',function (files){ console.log(files) }) gl.on('error',function (err){ console.log(err.stack) })<\/code><\/li><li>\u65b9\u6cd5\uff1a<code> \/\/--\u4e09\u4e2a\u65b9\u6cd5abort,pause,resume var Glob = require('glob').Glob; var path = require('path') var src = path.resolve(__dirname,'.\/node_modules'); var pattern = '**\/*.js'; var options = { dot:true, cwd:src }; var gl = new Glob(pattern,options); var index = 0; gl.on('match',function (file){ console.log('match',file,index) gl.pause() setTimeout(function (){ index&gt;=5 &amp;&amp; gl.abort() gl.resume(); index++; },1000) }); gl.on('abort',function (){ console.log('abort') });<\/code><\/li><\/ul>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>glob\u9759\u6001\u65b9\u6cd5\uff1b<\/p><\/blockquote>\n\n\n\n<ul><li>glob.sync(pattern,options):\u8fd4\u56de\u5339\u914d\u7684matchs\uff1b<code> var glob = require('glob'); var path = require('path') var src = path.resolve(__dirname,'.\/node_modules'); var pattern = '**.js'; var options = { dot:true, cwd:src, matchBase:true, }; var matchs = glob.sync(pattern,options); console.log(matchs)<\/code><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u5185\u90e8\u4f7f\u7528node-glob\u6a21\u5757\u5b9e\u73b0\u6587\u4ef6\u5339\u914d node-glob\u6a21\u5757\u88ab\u4f17\u591a\u524d\u6bb5\u6784\u5efa\u5de5\u5177\u4f7f\u7528\uff1b\u5982fis,grunt,glup\uff1b\u5185\u90e8\u4f7f\u7528 &#8230;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[15],"_links":{"self":[{"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/posts\/587"}],"collection":[{"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/comments?post=587"}],"version-history":[{"count":1,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/posts\/587\/revisions"}],"predecessor-version":[{"id":588,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/posts\/587\/revisions\/588"}],"wp:attachment":[{"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/media?parent=587"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/categories?post=587"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/tags?post=587"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}