How to use the stringifyRequest function from loader-utils

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

69
70
71
72
73
74
75
76
77
78
function importItemMatcher(item) {
	var match = result.importItemRegExp.exec(item);
	var idx = +match[1];
	var importItem = result.importItems[idx];
	var importUrl = importUrlPrefix + importItem.url;
	return "\" + require(" + loaderUtils.stringifyRequest(this, importUrl) + ").locals" +
		"[" + JSON.stringify(importItem.export) + "] + \"";
}

cssAsString = cssAsString.replace(result.importItemRegExpG, importItemMatcher.bind(this));
fork icon0
star icon1
watch icon0

+ 9 other calls in file

38
39
40
41
42
43
44
45
46
47
48
  if (!this.options.__vueOptions__) {
    this.options.__vueOptions__ = Object.assign({}, this.vue, this.query)
  }


  return `require(${
    utils.stringifyRequest(this,
      // disable all configuration loaders
      `!!${getRawLoaderString(loader)}!${rawRequest}`)
  })`
}
fork icon0
star icon0
watch icon2

+ 5 other calls in file

66
67
68
69
70
71
72
73
74
75
// styles
let stylesCode = ''
if (descriptor.styles.length) {
  const isProduction = options.productionMode || minimize || process.env.NODE_ENV === 'production'

  const stringifyRequest = r => loaderUtils.stringifyRequest(loaderContext, r)

  // module id for scoped CSS & hot-reload
  const rawShortFilePath = path
    .relative(context, resourcePath)
fork icon0
star icon0
watch icon1

+ 4 other calls in file

76
77
78
79
80
81
82
83
84
85
}

// execute pre-entry code
// this is used by tui to set up the module store etc before we add to it below
if (config.preEntry) {
  source += 'require(' + stringifyRequest(this, config.preEntry) + ');\n';
}

// register bundle
source += `tui._bundle.register(${compStr})\n`;
fork icon0
star icon0
watch icon0

+ 9 other calls in file

18
19
20
21
22
23
24
25
26
27
options.hmr = typeof options.hmr === 'undefined' ? true : options.hmr;

var hmr = [
	// Hot Module Replacement
	"if(module.hot) {",
	"  module.hot.accept(" + loaderUtils.stringifyRequest(this, "!!" + request) + ", function() {",
	"    update(require(" + loaderUtils.stringifyRequest(this, "!!" + request) + "));",
	"  });",
	"",
	"  module.hot.dispose(function() { update(); });",
fork icon0
star icon0
watch icon1

+ 15 other calls in file

59
60
61
62
63
64
65
66
67
68
].join("\n");

return [
	"var refs = 0;",
	"var dispose;",
	"var content = require(" + loaderUtils.stringifyRequest(this, "!!" + request) + ");",
	"var options = " + JSON.stringify(options) + ";",
	"options.insertInto = " + insertInto + ";",
	"",
	"if(typeof content === 'string') content = [[module.id, content, '']];",
fork icon0
star icon0
watch icon1

+ 7 other calls in file

34
35
36
37
38
39
40
41
42
43

var hmr = [
	// Hot Module Replacement,
	"if(module.hot) {",
	// When the styles change, update the <style> tags
	"	module.hot.accept(" + loaderUtils.stringifyRequest(this, "!!" + request) + ", function() {",
	"		var newContent = require(" + loaderUtils.stringifyRequest(this, "!!" + request) + ");",
	"",
	"		if(typeof newContent === 'string') newContent = [[module.id, newContent, '']];",
	"",
fork icon0
star icon0
watch icon1

+ 19 other calls in file

259
260
261
262
263
264
265
266
267
268
//   scopeId,
//   moduleIdentifier (server only)
// )
output +=
  'var normalizeComponent = require(' +
  loaderUtils.stringifyRequest(loaderContext, '!' + componentNormalizerPath) +
  ')\n'

// <script>
output += '/* script */\n'
fork icon0
star icon0
watch icon0

+ 8 other calls in file

24
25
26
27
28
29
30
31
32
33
//
// Get templating options
const options = this.query !== '' ? loaderUtils.parseQuery(this.query) : {};
const template = _.template(source, _.defaults(options, { variable: 'data' }));
// Require !!lodash - using !! will disable all loaders (e.g. babel)
return 'var _ = require(' + loaderUtils.stringifyRequest(this, '!!' + require.resolve('lodash')) + ');' +
  'module.exports = function (templateParams) { with(templateParams) {' +
    // Execute the lodash template
    'return (' + template.source + ')();' +
  '}}';
fork icon0
star icon0
watch icon0

35
36
37
38
39
40
41
42
43
44
  'compilation',
  'webpack',
  'webpackConfig',
  'htmlWebpackPlugin'
];
return 'var _ = require(' + loaderUtils.stringifyRequest(this, require.resolve('lodash')) + ');' +
  'module.exports = function (templateParams) {' +
    // Declare the template variables in the outer scope of the
    // lodash template to unwrap them
    templateVariables.map(function (variableName) {
fork icon0
star icon0
watch icon0