How to use the urlToRequest function from loader-utils

Find comprehensive JavaScript loader-utils.urlToRequest code examples handpicked from public code repositorys.

170
171
172
173
174
175
176
177
178
179
  preprocessPlugins = rootPlugins.slice(0, oursPluginIndex);
}

const definitionCache = new Map();
async function walkFile(from, dir, requiredDefinitions) {
  const request = importsAsModuleRequests ? urlToRequest(from) : from;
  const resolvedFrom = await resolve(concordContext, dir, request, resolveContext);

  const cached = definitionCache.get(resolvedFrom);
  if (cached) {
fork icon8
star icon20
watch icon1

+ 4 other calls in file

157
158
159
160
161
162
163
164
165
166

		if(!url.replace(/\s/g, '').length || !loaderUtils.isUrlRequest(url)) {
			return url;
		}
		if(global) {
			return loaderUtils.urlToRequest(url);
		}
	}
	return url;
}
fork icon0
star icon1
watch icon0

74
75
76
77
78
79
80
81
82
83
WebpackFileManager.prototype.supportsSync = function (filename, currentDirectory, options, environment) {
    return false;
};

WebpackFileManager.prototype.loadFile = function (filename, currentDirectory, options, environment, callback) {
    const moduleRequest = loaderUtils.urlToRequest(filename, query.root);
    // Less is giving us trailing slashes, but the context should have no trailing slash
    const context = currentDirectory.replace(trailingSlash, "");

    loaderContext.resolve(context, moduleRequest, (err, filename) => {
fork icon2
star icon0
watch icon0

150
151
152
153
154
155
156
157
158
159
	var urlToRequest;

	if (config.interpolate === 'require') {
		urlToRequest = data[match];
	} else {
		urlToRequest = loaderUtils.urlToRequest(data[match], root);
	}
	
	return '" + require(' + JSON.stringify(urlToRequest) + ') + "';
}) + ";";
fork icon1
star icon0
watch icon0

99
100
101
102
103
104
105
106
107
108
	}

	return;
}

var moduleRequest = loaderUtils.urlToRequest(filename, query.root);
// Less is giving us trailing slashes, but the context should have no trailing slash
var context = currentDirectory.replace(trailingSlash, "");

loaderContext.resolve(context, moduleRequest, function(err, filename) {
fork icon1
star icon0
watch icon0

81
82
83
84
85
86
87
88
89
    url = filename;
  }
} else {
  url = filename.replace(matchMalformedModuleFilename, '$1');
}
var moduleRequest = loaderUtils.urlToRequest(url, url.charAt(0) === '/' ? '' : null);
// Less is giving us trailing slashes, but the context should have no trailing slash
var context = currentDirectory.replace(trailingSlash, '');
var resolvedFilename = void 0;
fork icon1
star icon0
watch icon0

99
100
101
102
103
104
105
106
107
108
      done(new sass.types.String(`url(${err ? '#' : sprite.getUrl()})`))
    })
  }
}
compilation.options.sassLoader.importer = function (url, prev, done) {
  const request = utils.urlToRequest(url, this.root)
  const dirContext = Path.dirname(Path.normalize(prev))
  if (!self.resolvePatternUrl(request, dirContext, compilation, (err, pattern, name) => {
    if (!err) {
      done({contents: `$${name}:sprite-map("${pattern}");$${name}-names:sprite-names($${name});`})
fork icon0
star icon0
watch icon2

+ 5 other calls in file

44
45
46
47
48
49
50
51
52
53
54
module.exports = function inject(src) {
  if (this.cacheable) {
    this.cacheable();
  }
  const regex = createRequireStringRegex(
    loaderUtils.urlToRequest(this.resourcePath) || {}
  );


  return `module.exports = function inject(injections) {
  var module = {exports: {}};
fork icon0
star icon0
watch icon0

23
24
25
26
27
28
29
30
31
32
 * @returns {boolean|string} False where unmatched else the decoded path
 */
function decode(uri) {
  /* jshint validthis:true */
  if (/~/.test(uri)) {
    var relative = loaderUtils.urlToRequest(uri),
        base     = getContextDirectory.call(this),
        absFile  = path.normalize(path.join(base, 'node_modules', relative)),
        isValid  = !!absFile && fs.existsSync(absFile) && fs.statSync(absFile).isFile();
    return isValid && absFile;
fork icon0
star icon0
watch icon0