How to use the loader-utils.urlToRequest 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 aermin / ghChat / node_modules / sass-loader / lib / importsToResolve.js View on Github external
function importsToResolve(url) {
    const request = utils.urlToRequest(url);
    // Keep in mind: ext can also be something like '.datepicker' when the true extension is omitted and the filename contains a dot.
    // @see https://github.com/webpack-contrib/sass-loader/issues/167
    const ext = path.extname(request);

    if (matchModuleImport.test(url)) {
        return [request, url];
    }

    // libsass' import algorithm works like this:

    // In case there is a file extension...
    //   - If the file is a CSS-file, do not include it all, but just link it via @import url().
    //   - The exact file name must match (no auto-resolving of '_'-modules).
    if (ext === ".css") {
        return [];
    }
github yibn2008 / fast-sass-loader / lib / index.js View on Github external
err.file = entry

        throw err
      }

      let imports = getImportsToResolve(originalImport, includePaths, transformers)
      let resolvedImport

      for (let i = 0; i < imports.length; i++) {
        // if imports[i] is absolute path, then use it directly
        if (path.isAbsolute(imports[i]) && fs.existsSync(imports[i])) {
          resolvedImport = imports[i]
        } else {
          try {
            const reqFile = loaderUtils.urlToRequest(imports[i], opts.root)
            resolvedImport = yield resolve(entryDir, reqFile)
            break
          } catch (err) {
            // skip
          }
        }
      }

      if (!resolvedImport) {
        let err = new Error(`import file cannot be resolved: "${total}" @${entry}`)

        err.file = entry

        throw err
      }
github didi / mpx / packages / webpack-plugin / lib / web / processJSON.js View on Github external
async.forEach(pages, (page, callback) => {
        const rawPage = page
        if (resolveMode === 'native') {
          page = loaderUtils.urlToRequest(page, projectRoot)
        }
        const name = getPageName(tarRoot, rawPage)
        const pagePath = '/' + toPosix(name)
        resolve(path.join(context, srcRoot), page, (err, resource) => {
          if (err) return callback(err)
          const { resourcePath, queryObj } = parseRequest(resource)
          // 如果存在page命名冲突,return err
          for (let key in pagesMap) {
            if (pagesMap[key] === pagePath && key !== resourcePath) {
              return callback(new Error(`Resources in ${resourcePath} and ${key} are registered with same page path ${pagePath}, which is not allowed!`))
            }
          }
          if (pagesMap[resourcePath]) return callback()
          pagesMap[resourcePath] = pagePath
          localPagesMap[pagePath] = {
            resource: addQuery(resource, { page: true }),
github tinajs / mina-webpack / packages / mina-entry-webpack-plugin / src / index.ts View on Github external
// resolve symlink
    let realPath: string
    // mina or classic
    let isClassical: boolean
    try {
      ({ realPath, isClassical } = resolveRealPath(extensions, currentContext, resourceUrl))
    } catch (error) {
      // Do not throw an exception when the module does not exist.
      // Just mark it up and move on to the next module.
      errors.push(error)
      return
    }

    // relative path from rootContext, used to generate entry request or name
    const relativeRealPath = path.relative(rootContext, realPath)
    const relativeRealRequest = urlToRequest(relativeRealPath)

    // generte request
    let request: string
    if (isClassical) {
      request = `!${minaLoader}?${JSON.stringify(
        minaLoaderOptions
      )}!${virtualMinaLoader}?${JSON.stringify({
        extensions,
      })}!${relativeRealRequest}`
    } else {
      request = relativeRealRequest
    }

    // entry name for SingleEntryPlugin
    // `../../path/to/comp` => `_/_/path/to/comp`
    const name = compose(
github DynamoMTL / shopify-pipeline / lib / liquid-loader.js View on Github external
return `module.exports = ${JSON.stringify(keyedContent).replace(llRegex, (match) => {
    const request = utils.urlToRequest(replacements[match])
    const path = utils.stringifyRequest(this, request)

    // Ensure loader cache is busted when the image changes
    this.addDependency(path)

    // Double quotes are used to "escape" from the JSON.stringify()'ed content
    return `" + require(${path}) +"`
  })};`
}
github tinajs / mina-webpack / packages / mina-entry-webpack-plugin / src / index.ts View on Github external
const resolveRealPath = (
  extensions: Extensions,
  context: string,
  originalUrl: string
) => {
  const originalRequest = urlToRequest(originalUrl)
  try {
    let resourcePath: string
    let isClassical: boolean
    // mina component
    try {
      resourcePath = resolve.sync(originalRequest, {
        basedir: context,
        extensions: [],
      })
      isClassical = false
    } catch (error) {
      // classic component
      resourcePath = resolve.sync(originalRequest, {
        basedir: context,
        extensions: extensions.resolve,
      })
github blakeembrey / typescript-simple-loader / src / typescript-simple-loader.ts View on Github external
constructor (diagnostic: ts.Diagnostic, context: string, TS: typeof ts) {
    this.message = formatDiagnostic(diagnostic, TS)

    if (diagnostic.file) {
      this.file = urlToRequest(relative(context, diagnostic.file.fileName))
    }
  }
}
github zubairghori / Ultimate_todo_list / node_modules / css-loader / lib / processCss.js View on Github external
rewriteUrl: function(global, url) {
				if(parserOptions.url){
                    url = url.trim();

					if(!url.replace(/\s/g, '').length || !loaderUtils.isUrlRequest(url, root)) {
						return url;
					}
					if(global) {
						return loaderUtils.urlToRequest(url, root);
					}
				}
				return url;
			}
		}),
github sx1989827 / DOClever / node_modules / css-loader / lib / processCss.js View on Github external
rewriteUrl: function(global, url) {
				if(parserOptions.url){
                    url = url.trim();

					if(!url.replace(/\s/g, '').length || !loaderUtils.isUrlRequest(url, root)) {
						return url;
					}
					if(global) {
						return loaderUtils.urlToRequest(url, root);
					}
				}
				return url;
			}
		}),
github sx1989827 / DOClever / node_modules / css-loader / lib / processCss.js View on Github external
css.walkAtRules(/^import$/i, function(rule) {
				var values = Tokenizer.parseValues(rule.params);
				var url = values.nodes[0].nodes[0];
				if(url && url.type === "url") {
					url = url.url;
				} else if(url && url.type === "string") {
					url = url.value;
				} else throw rule.error("Unexpected format " + rule.params);
				if (!url.replace(/\s/g, '').length) {
					return;
				}
				values.nodes[0].nodes.shift();
				var mediaQuery = Tokenizer.stringifyValues(values);

				if(loaderUtils.isUrlRequest(url, options.root)) {
					url = loaderUtils.urlToRequest(url, options.root);
				}

				importItems.push({
					url: url,
					mediaQuery: mediaQuery
				});
				rule.remove();
			});
		}