function resolveAsLib(
	{name, dest = 'lib', relative = true} = {},
	cwd = null,
	...paths
) {
	const
		url = paths.find((el) => isURL.test(el));

	if (url != null) {
		return url;
	}

	let
		resSrc;

	if (Object.isArray(cwd)) {
		for (let i = 0; i < cwd.length; i++) {
			resSrc = path.join(...[].concat(cwd[i] || [], paths));

			if (fs.existsSync(resSrc)) {
				break;
			}
		}

	} else {
		resSrc = path.join(...[].concat(cwd || [], paths));
	}

	const
		srcIsFolder = fs.lstatSync(resSrc).isDirectory();

	name = name ?
		name + path.extname(resSrc) :
		path.basename(resSrc);

	const
		needHash = Boolean(webpack.hashFunction()),
		cache = srcIsFolder ? folders : files;

	if (cache[name]) {
		return cache[name];
	}

	const
		libDest = src.clientOutput(webpack.output({name: dest}));

	let
		fileContent,
		newSrc;

	if (srcIsFolder) {
		const hash = needHash ? `${genHash(path.join(resSrc, '/**/*'))}_` : '';
		newSrc = path.join(libDest, hash + name);

	} else {
		fileContent = fs.readFileSync(resSrc);
		const hash = needHash ? `${genHash(fileContent)}_` : '';
		newSrc = path.join(libDest, hash + name);
	}

	const
		distPath = relative ? path.relative(src.clientOutput(), newSrc) : newSrc;

	if (!fs.existsSync(newSrc)) {
		if (srcIsFolder) {
			fs.mkdirpSync(newSrc);
			fs.copySync(resSrc, newSrc);

		} else {
			const
				clrfx = /\/\/# sourceMappingURL=.*/;

			fs.mkdirpSync(libDest);
			fs.writeFileSync(newSrc, fileContent.toString().replace(clrfx, ''));
		}
	}

	cache[name] = distPath;
	return distPath;
}
/**
 * Loads the specified file or directory as an external library to the output folder.
 * The function returns a path to the library from the output folder.
 *
 * @param {string=} [name] - name of the library
 *   (if not specified, the name will be taken from a basename of the source file)
 *
 * @param {boolean=} [dest='lib'] - where to store the library
 * @param {boolean=} [relative=true] - if false, the function will return an absolute path
 * @param {(Array<string>|string)=} cwd - active working directory (can be defined as an array to enable layers)
 * @param {...string} paths - string paths to join (also, can take URL-s)
 * @returns {string}
 *
 * @example
 * ```js
 * resolveAsLib({name: 'jquery'}, 'node_modules', 'jquery/dist/jquery.min.js');
 * resolveAsLib({name: 'images'}, 'assets', 'images/');
 * ```
 */
Loads the specified file or directory as an external library to the output folder.
The function returns a path to the library from the output folder.

@param {string=} [name] - name of the library
(if not specified, the name will be taken from a basename of the source file)




Loads the specified file or directory as an external library to the output folder . The function returns a path to the library from the output folder . @param { string = } [ name ] - name of the library ( if not specified the name will be taken from a basename of the source file )
function resolveAsLib(
	{name, dest = 'lib', relative = true} = {},
	cwd = null,
	...paths
) {
	const
		url = paths.find((el) => isURL.test(el));
	if (url != null) {
		return url;
	}
	let
		resSrc;
	if (Object.isArray(cwd)) {
		for (let i = 0; i < cwd.length; i++) {
			resSrc = path.join(...[].concat(cwd[i] || [], paths));
			if (fs.existsSync(resSrc)) {
				break;
			}
		}
	} else {
		resSrc = path.join(...[].concat(cwd || [], paths));
	}
	const
		srcIsFolder = fs.lstatSync(resSrc).isDirectory();
	name = name ?
		name + path.extname(resSrc) :
		path.basename(resSrc);
	const
		needHash = Boolean(webpack.hashFunction()),
		cache = srcIsFolder ? folders : files;
	if (cache[name]) {
		return cache[name];
	}
	const
		libDest = src.clientOutput(webpack.output({name: dest}));
	let
		fileContent,
		newSrc;
	if (srcIsFolder) {
		const hash = needHash ? `${genHash(path.join(resSrc, '/**/*'))}_` : '';
		newSrc = path.join(libDest, hash + name);
	} else {
		fileContent = fs.readFileSync(resSrc);
		const hash = needHash ? `${genHash(fileContent)}_` : '';
		newSrc = path.join(libDest, hash + name);
	}
	const
		distPath = relative ? path.relative(src.clientOutput(), newSrc) : newSrc;
	if (!fs.existsSync(newSrc)) {
		if (srcIsFolder) {
			fs.mkdirpSync(newSrc);
			fs.copySync(resSrc, newSrc);
		} else {
			const
				clrfx = /\/\/# sourceMappingURL=.*/;
			fs.mkdirpSync(libDest);
			fs.writeFileSync(newSrc, fileContent.toString().replace(clrfx, ''));
		}
	}
	cache[name] = distPath;
	return distPath;
}
function resolveAsLib ( { name , dest = 'lib' , relative = true } = { } , cwd = null , ... paths ) { const url = paths . find ( ( el ) => isURL . test ( el ) ) ; if ( url != null ) { return url ; } let resSrc ; if ( Object . isArray ( cwd ) ) { for ( let i = 0 ; i < cwd . length ; i ++ ) { resSrc = path . join ( ... [ ] . concat ( cwd [ i ] || [ ] , paths ) ) ; if ( fs . existsSync ( resSrc ) ) { break ; } } } else { resSrc = path . join ( ... [ ] . concat ( cwd || [ ] , paths ) ) ; } const srcIsFolder = fs . lstatSync ( resSrc ) . isDirectory ( ) ; name = name ? name + path . extname ( resSrc ) : path . basename ( resSrc ) ; const needHash = Boolean ( webpack . hashFunction ( ) ) , cache = srcIsFolder ? folders : files ; if ( cache [ name ] ) { return cache [ name ] ; } const libDest = src . clientOutput ( webpack . output ( { name : dest } ) ) ; let fileContent , newSrc ; if ( srcIsFolder ) { const hash = needHash ? ` ${ genHash ( path . join ( resSrc , '/**/*' ) ) } ` : '' ; newSrc = path . join ( libDest , hash + name ) ; } else { fileContent = fs . readFileSync ( resSrc ) ; const hash = needHash ? ` ${ genHash ( fileContent ) } ` : '' ; newSrc = path . join ( libDest , hash + name ) ; } const distPath = relative ? path . relative ( src . clientOutput ( ) , newSrc ) : newSrc ; if ( ! fs . existsSync ( newSrc ) ) { if ( srcIsFolder ) { fs . mkdirpSync ( newSrc ) ; fs . copySync ( resSrc , newSrc ) ; } else { const clrfx = / \/\/# sourceMappingURL=.* / ; fs . mkdirpSync ( libDest ) ; fs . writeFileSync ( newSrc , fileContent . toString ( ) . replace ( clrfx , '' ) ) ; } } cache [ name ] = distPath ; return distPath ; }
Loads the specified file or directory as an external library to the output folder.
Loads the specified file or directory as an external library to the output folder .