webpack
Version:
Packs ECMAScript/CommonJs/AMD modules for the browser. Allows you to split your codebase into multiple bundles, which can be loaded on demand. Supports loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.
26 lines (21 loc) • 887 B
JavaScript
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Alexander Akait @alexander-akait
*/
;
const SLASH_CHAR_CODE = 47;
/**
* Whether a `resolve.alias` name applies to a request. Mirrors `AliasPlugin`:
* a name matches the whole request or a leading segment of it, and
* `onlyModule` restricts it to the former.
* @param {string} request the request as written
* @param {string} name the alias name, already normalized by enhanced-resolve
* @param {boolean=} onlyModule whether the alias only matches the whole request
* @returns {boolean} true when the alias applies to the request
*/
const matchAlias = (request, name, onlyModule) => {
if (!request.startsWith(name)) return false;
if (request.length === name.length) return true;
return !onlyModule && request.charCodeAt(name.length) === SLASH_CHAR_CODE;
};
module.exports = matchAlias;