How to use the loader-utils.stringifyRequest function in loader-utils

To help you get started, we’ve selected a few loader-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github didi / chameleon / packages / chameleon-loader / src / helpers.js View on Github external
// get loader string for pre-processors
    getLoaderString(type, part, index, scoped);

    if (options.afterWxSelector) {
      loaderString += // 微信端在selector 拼接差异化代码后做replace
      stringifyLoaders(options.afterWxSelector) + '!' ;
    }

    loaderString +=
    // select the corresponding part from the vue file
    getSelectorString(type, index || 0) +
    // the url to the actual vue file, including remaining requests
    rawRequest;


    return loaderUtils.stringifyRequest(
      loaderContext,
      loaderString
    )
  }
github sx1989827 / DOClever / Desktop / node_modules / vue-style-loader / index.js View on Github external
module.exports.pitch = function (remainingRequest) {
  if (this.cacheable) this.cacheable()

  var isServer = this.target === 'node'
  var isProduction = this.minimize || process.env.NODE_ENV === 'production'
  var addStylesClientPath = loaderUtils.stringifyRequest(this, '!' + path.join(__dirname, 'lib/addStylesClient.js'))
  var addStylesServerPath = loaderUtils.stringifyRequest(this, '!' + path.join(__dirname, 'lib/addStylesServer.js'))

  var request = loaderUtils.stringifyRequest(this, '!!' + remainingRequest)
  var id = JSON.stringify(hash(request))

  var shared = [
    '// style-loader: Adds some css to the DOM by adding a <style> tag',
    '',
    '// load the styles',
    'var content = require(' + request + ');',
    // content list format is [id, css, media, sourceMap]
    "if(typeof content === 'string') content = [[module.id, content, '']];",
    'if(content.locals) module.exports = content.locals;'
  ]

  if (!isServer) {
</style>
github alibaba / rax / packages / mp-loader / src / template.js View on Github external
hasJS = true;
      }

      const qs = new QueryString({
        type,
        stylePath: hasStyle ? stylePath : null,
        jsPath: hasJS ? jsPath : null,
      });

      const componentReq = stringifyRequest(this, `!!${__filename}?${qs}!${tplPath}`);
      tplRegisters += `require(${componentReq})(__tpls__, Rax);`;
    }
  }

  // prepare requirements
  const vdomHelperReq = createRequireDefault(stringifyRequest(this, paths.vdomHelper));
  const styleReq = stylePath && stylePath !== 'undefined'
    ? createRequire(stringifyRequest(this, `${stylesheetLoaderPath}?disableLog=true!${stylePath}`))
    : '{}';
  const globalStyleReq = globalStylePath
    ? createRequire(stringifyRequest(this, `${stylesheetLoaderPath}?disableLog=true!${globalStylePath}`))
    : '{}';

  const renderFnScopeVariables = withScope(
    renderFn,
    prerveredVars,
    'data'
  );

  return `;(function(globalStyle, pageStyle, __vdom_helpers__){
    ${vdomHelperVars}
    module.exports = function renderFactory(__parent_tpls__, Rax) {
github vuetifyjs / vuetify-loader / lib / loader.js View on Github external
function install (install, content, imports) {
  if (imports.length) {
    let newContent = '/* vuetify-loader */\n'
    newContent += `import ${install} from ${loaderUtils.stringifyRequest(this, '!' + runtimePaths[install])}\n`
    newContent += imports.map(i => i[1]).join('\n') + '\n'
    newContent += `${install}(component, {${imports.map(i => i[0]).join(',')}})\n`

    // Insert our modification before the HMR code
    const hotReload = content.indexOf('/* hot reload */')
    if (hotReload > -1) {
      content = content.slice(0, hotReload) + newContent + '\n\n' + content.slice(hotReload)
    } else {
      content += '\n\n' + newContent
    }
  }

  return content
}
github riot / webpack-loader / src / index.js View on Github external
acc[key.replace('?', '')] = query[key]
    return acc
  }, {})

  // compile and generate sourcemaps
  const {code, map} = compile(
    source,
    {
      ...opts,
      file: this.resourcePath
    }
  )

  // generate the output code
  // convert webpack's absolute path to a script-friendly string for hotReload
  const escapedPath = stringifyRequest(this, this.resourcePath)
  const output = `${code}${opts.hot ? hotReload(escapedPath) : ''}`

  // cache this module
  if (this.cacheable) this.cacheable()

  // return code and sourcemap
  this.callback(null, output, map)
}
github JetBrains / svg-sprite-loader / lib / runtime-generator.js View on Github external
const path = stringify(publicPath) || '__webpack_public_path__';
    const data = `{
      id: ${stringify(symbol.useId)},
      viewBox: ${stringify(symbol.viewBox)},
      url: ${path} + ${stringify(spritePlaceholder)},
      toString: function () {
        return this.url;
      }
    }`;
    runtime = generateExport(data, esModule);
  } else {
    const spriteModuleAbsPath = isAbsolute(spriteModule) ? spriteModule : join(context, spriteModule);
    const symbolModuleAbsPath = isAbsolute(symbolModule) ? symbolModule : join(context, symbolModule);

    const spriteModuleImport = stringifyRequest(loaderContext, spriteModuleAbsPath);
    const symbolModuleImport = stringifyRequest(loaderContext, symbolModuleAbsPath);

    runtime = [
      generateImport('SpriteSymbol', symbolModuleImport, esModule),
      generateImport('sprite', spriteModuleImport, esModule),

      `var symbol = new SpriteSymbol(${stringifySymbol(symbol)})`,
      'var result = sprite.add(symbol)',

      generateExport(runtimeCompat ? '"#" + symbol.id' : 'symbol', esModule)
    ].join(';\n');
  }

  return runtime;
}
github mediamonks / muban / build-tools / hbs-style-loader.js View on Github external
${requires.map(style => 
	`require(${loaderUtils.stringifyRequest(loaderContext, style)});`
).join("\n")}
github dflemstr / rust-native-wasm-loader / src / index.js View on Github external
return `module.exports.wasmBooted = import(${jsRequest}).then(wasmModule => {
      const keys = Object.keys(wasmModule);
      for (let key of keys) module.exports[key] = wasmModule[key];
    })`;
  } else {
    const jsRequest = loaderUtils.stringifyRequest(self, suffixlessPath + '.js');
    let contents = '';
    if (wasmBindgen.nodejs) {
      contents += `module.exports = require(${jsRequest});\n`;
    } else {
      contents += `export * from ${jsRequest};\n`;
    }
    if (wasmBindgen.wasm2es6js) {
      const wasmImport = suffixlessPath + '_bg';
      const wasmRequest = loaderUtils.stringifyRequest(self, wasmImport);
      if (wasmBindgen.nodejs) {
        contents += `module.exports.wasmBooted = require(${wasmRequest}).booted\n`;
      } else {
        contents += `export {booted as wasmBooted} from ${wasmRequest};\n`;
      }
    }
    return contents;
  }
};
github zubairghori / Ultimate_todo_list / node_modules / style-loader / useable.js View on Github external
"		if(dispose) {",
		"			dispose();",
		"		}",
		"	});",
		"}"
	].join("\n");

	return [
		"var refs = 0;",
		"var dispose;",
		"var content = require(" + loaderUtils.stringifyRequest(this, "!!" + request) + ");",
		"if(typeof content === 'string') content = [[module.id, content, '']];",
		"if(content.locals) exports.locals = content.locals;",
		"exports.use = exports.ref = function() {",
		"	if(!(refs++)) {",
		"		dispose = require(" + loaderUtils.stringifyRequest(this, "!" + path.join(__dirname, "lib", "addStyles.js")) + ")(content, " + JSON.stringify(options) + ");",
		"	}",
		"	return exports;",
		"};",
		"exports.unuse = exports.unref = function() {",
		"       if(refs > 0 && !(--refs)) {",
		"		dispose();",
		"		dispose = null;",
		"	}",
		"};",
		options.hmr ? hmrCode : ""
	].join("\n");
};
github enigmampc / secret-contracts / node_modules / style-loader / useable.js View on Github external
module.exports.pitch = function (request) {
	if (this.cacheable) this.cacheable();

	var options = loaderUtils.getOptions(this) || {};

	validateOptions(require('./options.json'), options, 'Style Loader (Useable)');

	return [
		"var refs = 0;",
		"var dispose;",
		"var content = require(" + loaderUtils.stringifyRequest(this, "!!" + request) + ");",
		"if(typeof content === 'string') content = [[module.id, content, '']];",
		"if(content.locals) exports.locals = content.locals;",
		"exports.use = exports.ref = function() {",
		"	if(!(refs++)) {",
		"		dispose = require(" + loaderUtils.stringifyRequest(this, "!" + path.join(__dirname, "lib", "addStyles.js")) + ")(content, " + JSON.stringify(options) + ");",
		"	}",
		"	return exports;",
		"};",
		"exports.unuse = exports.unref = function() {",
		"       if(refs > 0 && !(--refs)) {",
		"		dispose();",
		"		dispose = null;",
		"	}",
		"};",
		"if(module.hot) {",
		"	var lastRefs = module.hot.data && module.hot.data.refs || 0;",