How to use loader-utils - 10 common examples

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 xxxgitone / learningProcess / WebPack-Beginner / node_modules / webpack / bin / convert-argv.js View on Github external
function loadPlugin(name) {
			var loadUtils = require("loader-utils");
			var args;
			try {
				var p = name && name.indexOf("?");
				if(p > -1) {
					args = loadUtils.parseQuery(name.substring(p));
					name = name.substring(0, p);
				}
			} catch(e) {
				console.log("Invalid plugin arguments " + name + " (" + e + ").");
				process.exit(-1); // eslint-disable-line
			}

			var path;
			try {
				var resolve = require("enhanced-resolve");
				path = resolve.sync(process.cwd(), name);
			} catch(e) {
				console.log("Cannot resolve plugin " + name + ".");
				process.exit(-1); // eslint-disable-line
			}
			var Plugin;
github xxxgitone / learningProcess / WebPack-Beginner / 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: [],
    inputSourceMap: inputSourceMap,
    sourceRoot: process.cwd(),
    filename: filename,
    cacheIdentifier: JSON.stringify({
github apache / incubator-weex-cli / weex-loader / index.js View on Github external
function loader(source) {
    var self = this;
    this.cacheable && this.cacheable();

    var callback = this.async();
    var params = {
        loaderQuery: loaderUtils.parseQuery(this.query),
        resourceQuery: loaderUtils.parseQuery(this.resourceQuery),
        resourcePath: this.resourcePath
    };
    var type = params.loaderQuery.type || 'we';
    var promise = partedLoader(type, this, params, source);

    promise.then(function(result) {
        if (type === 'style' || type === 'css' ||
            type === 'html' || type === 'tpl' || type === 'template') {
            result = 'module.exports=' + result;
        }
        // console.log('\n[' + type + ', ' + params.resourcePath + ']\n', source, '\n=========>\n', result + '\n');
        callback(null, result);
    }).catch(function(err) {
        self.emitError(err.toString());
        callback(err.toString(), '');
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 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 sx1989827 / DOClever / Client / node_modules / css-loader / lib / processCss.js View on Github external
function processNode(item) {
			switch (item.type) {
				case "value":
					item.nodes.forEach(processNode);
					break;
				case "nested-item":
					item.nodes.forEach(processNode);
					break;
				case "item":
					var importIndex = imports["$" + item.name];
					if (typeof importIndex === "number") {
						item.name = "___CSS_LOADER_IMPORT___" + importIndex + "___";
					}
					break;
				case "url":
					if (options.url && item.url.replace(/\s/g, '').length && !/^#/.test(item.url) && (isAlias(item.url) || loaderUtils.isUrlRequest(item.url, options.root))) {
						// Don't remove quotes around url when contain space
						if (item.url.indexOf(" ") === -1) {
							item.stringType = "";
						}
						delete item.innerSpacingBefore;
						delete item.innerSpacingAfter;
						var url = item.url;
						item.url = "___CSS_LOADER_URL___" + urlItems.length + "___";
						urlItems.push({
							url: url
						});
					}
					break;
			}
		}
github xxxgitone / learningProcess / WebPack-Beginner / node_modules / css-loader / lib / processCss.js View on Github external
function processNode(item) {
			switch (item.type) {
				case "value":
					item.nodes.forEach(processNode);
					break;
				case "nested-item":
					item.nodes.forEach(processNode);
					break;
				case "item":
					var importIndex = imports["$" + item.name];
					if (typeof importIndex === "number") {
						item.name = "___CSS_LOADER_IMPORT___" + importIndex + "___";
					}
					break;
				case "url":
					if (options.url && item.url.replace(/\s/g, '').length && !/^#/.test(item.url) && (isAlias(item.url) || loaderUtils.isUrlRequest(item.url, options.root))) {
						// Don't remove quotes around url when contain space
						if (item.url.indexOf(" ") === -1) {
							item.stringType = "";
						}
						delete item.innerSpacingBefore;
						delete item.innerSpacingAfter;
						var url = item.url;
						item.url = "___CSS_LOADER_URL___" + urlItems.length + "___";
						urlItems.push({
							url: url
						});
					}
					break;
			}
		}
github zubairghori / Ultimate_todo_list / node_modules / css-loader / lib / processCss.js View on Github external
function processNode(item) {
			switch (item.type) {
				case "value":
					item.nodes.forEach(processNode);
					break;
				case "nested-item":
					item.nodes.forEach(processNode);
					break;
				case "item":
					var importIndex = imports["$" + item.name];
					if (typeof importIndex === "number") {
						item.name = "___CSS_LOADER_IMPORT___" + importIndex + "___";
					}
					break;
				case "url":
					if (options.url && item.url.replace(/\s/g, '').length && !/^#/.test(item.url) && (isAlias(item.url) || loaderUtils.isUrlRequest(item.url, options.root))) {
						// Don't remove quotes around url when contain space
						if (item.url.indexOf(" ") === -1) {
							item.stringType = "";
						}
						delete item.innerSpacingBefore;
						delete item.innerSpacingAfter;
						var url = item.url;
						item.url = "___CSS_LOADER_URL___" + urlItems.length + "___";
						urlItems.push({
							url: url
						});
					}
					break;
			}
		}
github uiwjs / uiw-admin / scripts / conf / webpack.config.prod.js View on Github external
getLocalIdent: (context, localIdentName, localName) => {
                    // 过滤 uiw 组件库,因为 modules=true 参数,会将 className替换成Hash,导致uiw样式无法加载
                    const hash = loaderUtils.getHashDigest(context.resourcePath + localIdentName, 'md5', 'base64', 5);
                    const uiwpath = path.join(process.cwd(), 'node_modules', 'uiw');
                    if ((new RegExp(`^${uiwpath}`)).test(context.resourcePath)) {
                      return localName;
                    }
                    return localName + hash;
                  },
                },