How to use the loader-utils.getRemainingRequest 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 Graphite-Docs / graphite / node_modules / babel-loader / lib / index.js View on Github external
module.exports = function (source, inputSourceMap) {
  var _this = this;

  // Handle filenames (#106)
  var webpackRemainingChain = loaderUtils.getRemainingRequest(this).split("!");
  var filename = webpackRemainingChain[webpackRemainingChain.length - 1];

  // Handle options
  var loaderOptions = loaderUtils.getOptions(this) || {};
  var fileSystem = this.fs ? this.fs : fs;
  var babelrcPath = null;
  if (loaderOptions.babelrc !== false) {
    babelrcPath = typeof loaderOptions.babelrc === "string" && exists(fileSystem, loaderOptions.babelrc) ? loaderOptions.babelrc : resolveRc(fileSystem, path.dirname(filename));
  }

  if (babelrcPath) {
    this.addDependency(babelrcPath);
  }

  var defaultOptions = {
    metadataSubscribers: [],
github didi / mpx / packages / webpack-plugin / lib / wxss / loader.js View on Github external
if (map.sources) {
        map.sources = map.sources.map(function (source) {
          return source.replace(/\\/g, '/')
        })
        map.sourceRoot = ''
      }
    }
  } else {
    // Some loaders (example `"postcss-loader": "1.x.x"`) always generates source map, we should remove it
    map = null
  }

  processCss(content, map, {
    mode: moduleMode ? 'local' : 'global',
    from: loaderUtils.getRemainingRequest(this).split('!').pop(),
    to: loaderUtils.getCurrentRequest(this).split('!').pop(),
    query: query,
    resolve: resolve,
    minimize: this.minimize,
    loaderContext: this,
    sourceMap: sourceMap
  }, function (err, result) {
    if (err) return callback(err)

    var cssAsString = JSON.stringify(result.source)

    // for importing CSS
    var importUrlPrefix = getImportPrefix(this, query)

    var alreadyImported = {}
    var importJs = result.importItems.filter(function (imp) {
github AviVahl / ts-tools / packages / webpack-loader / src / typescript-loader.ts View on Github external
? transpileCached({
              ...transpileOptions,
              cacheDirectoryPath: optionsScopedCachePath,
              fileContents
          })
        : ts.transpileModule(fileContents, transpileOptions);

    if (diagnostics && diagnostics.length) {
        this.emitError(new Error(ts.formatDiagnostics(diagnostics, formatDiagnosticsHost)));
    }

    if (sourceMapText) {
        const rawSourceMap = JSON.parse(sourceMapText) as import('source-map').RawSourceMap;
        if (rawSourceMap.sources.length === 1) {
            // ensure source maps point to the correct target in a loader chain
            rawSourceMap.sources[0] = getRemainingRequest(this);
        }

        // find/remove inline comment linking to sourcemap
        const sourceMappingIdx = outputText.lastIndexOf(externalSourceMapPrefix);
        this.callback(null, sourceMappingIdx === -1 ? outputText : outputText.slice(0, sourceMappingIdx), rawSourceMap);
    } else {
        this.callback(null, outputText);
    }
};
github didi / mpx / packages / webpack-plugin / lib / helpers.js View on Github external
function getRawRequest ({ resource, loaderIndex, loaders }, excludedPreLoaders = /eslint-loader/) {
  return loaderUtils.getRemainingRequest({
    resource: resource,
    loaderIndex: loaderIndex,
    loaders: loaders.filter(loader => !excludedPreLoaders.test(loader.path))
  })
}
github retyui / group-css-media-queries-loader / src / index.js View on Github external
function GroupCssMediaQueriesLoader(inputSource, prevMap, meta) {
  const options = getOptions(this) || {};
  const sourceMap =
    options.sourceMap === undefined
      ? this.sourceMap
      : Boolean(options.sourceMap);
  const callback = this.async();

  pipeline
    .process(inputSource, {
      from: getRemainingRequest(this)
        .split("!")
        .pop(),
      to: getCurrentRequest(this)
        .split("!")
        .pop(),
      map: sourceMap
        ? {
            prev: prevMap,
            sourcesContent: true,
            inline: false,
            annotation: false
          }
        : null
    })
    .then(result => {
      callback(null, result.css, result.map && result.map.toJSON(), meta);
github vuejs / vue-loader / lib / helpers.js View on Github external
function getRawRequest (
  { resource, loaderIndex, loaders },
  excludedPreLoaders = /eslint-loader/
) {
  return loaderUtils.getRemainingRequest({
    resource: resource,
    loaderIndex: loaderIndex,
    loaders: loaders.filter(loader => !excludedPreLoaders.test(loader.path))
  })
}
github MoOx / cssnext-loader / index.js View on Github external
function defaultOptions(context, map){
  var options = {}
  options.from = loaderUtils.getRemainingRequest(context)
  options.to = loaderUtils.getRemainingRequest(context)
  if (context.sourceMap) {
    options.map = {
      inline: false,
      annotation: false,
      prev: map
    }
  }
  options.compress = context.minimize
  return options
}