When using Nodejs vinyl-fs to copy files, the output path is incorrect, or there will be the original relative path, because of the backslash "\", forward slash "/" No problem
Testing process
Node version: v9.3.0
System: WIN10
Steps:
Get two different paths
Test the path First P1,P1 is a backslash, the file output to the test folder, the result is more "bower_components\animate.css" This relative path
The following is the path P2,P2 is a forward slash, normal output
Code
1 var glob = require ("Glob" ) 2 var path = Require ("path" 3 var VFS = require (' Vinyl-fs ' ) 4 5 var p1= Path.join ("./", "/bower_components/animate.css/animate.css" 6 var p2=" Bower_components/animate.css/animate.css " Span style= "COLOR: #008080" >7 8 vfs.src (p1). Pipe (Vfs.dest ("Test" 9 vfs.src (p2). Pipe (Vfs.dest ("Test"))
View Code
Summarize
Positive and negative slashes may occur: Generally speaking, I manually write the path is to use the forward slash "/", sometimes in order to facilitate the stitching path will use the Path class library related functions, usually run out of Windows results are backslashes, usually in the file management address bar of win copy of the address is a backslash, C #
The Path class library handles the result with a backslash.
Unified approach: In a path at the same time contains a positive and negative slash, to see the user choose not to choose the format, if not required that is arbitrary, if required or in the processing, the reverse slash into a forward slash, to avoid the unknown problems. Also do not delve into, anyway with the forward slash is right.
Relevant information:
Nodejs Document PATH Related https://nodejs.org/dist/latest-v9.x/docs/api/path.html
Glob expression Https://www.npmjs.com/package/glob
Glob the document says (I just want to play a little bit, the documentation has not been read, who knows the pit): on the Windows platform, the GLOB expression uses only the forward slash. But I believe that there are still a lot of people have not seen, do not know, mostly copy and paste, the results may be in this is a small problem on the project to add another, and then bug serial. I have to spit it out here. Grunt of some plug-ins, the document is almost useless, the document points to other documents are not links, out of the problem is difficult to debug, wasted a lot of time. Later on with gulp, a little better, crossing network feel plug-in quality generally better, performance is better than grunt. These plug-ins are really a headache, use it and a variety of small problems, write it yourself and time is not necessarily written better than others, and later found NPM scripts. are based on Nodejs, have to engage in a variety of chaotic format, documents have no unified specification, plug-in quality is uneven. For beginners, the cost of learning is not generally high. Why must the user master so many basic to normal use, like to buy back the computer also to learn its operating principle, install system and so on to use, I just want to see the film Ah.
Rarely write something, and then chit chat when chit chat when. These two days to understand the previous only know the concept but not used NPM and Bower package management, from the sigh unexpectedly have grunt so magical thing, to throw away it use gulp, and then back to NPM scripts, how to say, like the return to the original. Not all is JS, but also make all kinds of mess, I just want to script copy files, results a few lines of code on their own things, I obstinately from Grunt, to gulp and NPM scripts stroll a circle, that I might as well directly with the T4 template, with their own control of the familiar language to alleviate their work. All kinds of AIDS are to alleviate a variety of repetitive boring work, the result is to increase the cost of learning is not necessarily able to do a good job. If the cost of making a wheel is lower than the cost of learning other wheels, why not build your own wheels and learn more about what you are doing. No matter how, still want to thank you big guy made so many good things, finally hope that the domestic can be a little more than a variety of good technology, technology comprehensive forward development.
Nodejs vinyl-fs Handling files when you enter a problem