Gulp symlink()

🌙
手机阅读
本文目录结构
axihe

创建一个流(stream),用于连接 Vinyl 对象到文件系统。

用法

const { src, symlink } = require('gulp');

function link() {
  return src('input/*.js')
    .pipe(symlink('output/'));
}

exports.link = link;

函数原型

symlink(directory, [options])

参数

参数类型描述
directory
(required)
string

function
将在其中创建符号链接的输出目录的路径。 如果使用一个函数,则每个 Vinyl 对象将调用该函数,并且必须返回字符串目录路径。
optionsobject详细介绍参考下面的选项

返回值

A stream that can be used in the middle or at the end of a pipeline to create symbolic links on the file system. Whenever a Vinyl object is passed through the stream, it creates a symbolic link to the original file on the file system at the given directory.

可以在管道的中间或末端使用流在文件系统上创建符号链接的流。 每当 Vinyl 对象通过流时,它都会在给定目录中的文件系统上创建指向原始文件的符号链接。

Whenever a symbolic link is created on the file system, the Vinyl object will be modified.

每当在文件系统上创建符号链接时,都会修改 Vinyl 对象。

  • The cwd, base, and path properties will be updated to match the created symbolic link.
  • The stat property will be updated to match the symbolic link on the file system.
  • The contents property will be set to null.
  • The symlink property will be added or replaced with original path.

Note: On Windows, directory links are created using junctions by default. The useJunctions option disables this behavior.

可能出现的错误

When directory is an empty string, throws an error with the message, “Invalid symlink() folder argument. Please specify a non-empty string or a function.”

When directory is not a string or function, throws an error with the message, “Invalid symlink() folder argument. Please specify a non-empty string or a function.”

When directory is a function that returns an empty string or undefined, emits an error with the message, “Invalid output folder”.

选项

对于接受函数的选项,传递的函数将与每个 Vinyl 对象一起调用,并且必须返回另一个列出类型的值。

nametypedefaultnote
cwdstring
functionprocess.cwd()The directory that will be combined with any relative path to form an absolute path. Is ignored for absolute paths. Use to avoid combining directory with path.join().
dirModenumber
functionThe mode used when creating directories. If not set, the process’ mode will be used.
overwriteboolean
functiontrueWhen true, overwrites existing files with the same path.
relativeSymlinksboolean
functionfalseWhen false, any symbolic links created will be absolute.
Note: Ignored if a junction is being created, as they must be absolute.
useJunctionsboolean
functiontrueThis option is only relevant on Windows and ignored elsewhere. When true, creates directory symbolic link as a junction. Detailed in Symbolic links on Windows below.

When creating symbolic links on Windows, a type argument is passed to Node’s fs.symlink() method which specifies the type of target being linked. The link type is set to:

  • 'file' when the target is a regular file
  • 'junction' when the target is a directory
  • 'dir' when the target is a directory and the user disables the useJunctions option

If you try to create a dangling (pointing to a non-existent target) link, the link type can’t be determined automatically. In these cases, behavior will vary depending on whether the dangling link is being created via symlink() or via dest().

For dangling links created via symlink(), the incoming Vinyl object represents the target, so its stats will determine the desired link type. If isDirectory() returns false then a 'file' link is created, otherwise a 'junction' or 'dir' link is created depending on the value of the useJunctions option.

For dangling links created via dest(), the incoming Vinyl object represents the link - typically loaded from disk via src(..., { resolveSymlinks: false }). In this case, the link type can’t be reasonably determined and defaults to using 'file'. This may cause unexpected behavior when creating a dangling link to a directory. Avoid this scenario.


AXIHE / 精选资源

浏览全部教程

面试题

学习网站

前端培训
自己甄别

前端书籍

关于朱安邦

我叫 朱安邦,阿西河的站长,在杭州。

以前是一名平面设计师,后来开始接接触前端开发,主要研究前端技术中的JS方向。

业余时间我喜欢分享和交流自己的技术,欢迎大家关注我的 Bilibili 和抖音。

关注我: Github / 知乎

如果你加我的私人微信,麻烦写上您的 称呼,所在地区,职业,方便我备注,谢谢


本站的微信公众号

阿西河前端教程

Anbang

安邦的私人微信

微信号: yaolushan

Anbang

Bilibili(B站)

朱安邦

Anbang