How to use the loader-utils.parseQuery 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 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 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 didi / chameleon / packages / chameleon-weex-vue-loader / lib / loader.js View on Github external
return loader.replace(/((?:^|!)css(?:-loader)?)(\?[^!]*)?/, function (m, $1, $2) {
      // $1: !css-loader
      // $2: ?a=b
      var query = loaderUtils.parseQuery($2)
      Object.assign(query, OPTIONS, option, DEFAULT_OPTIONS)
      if (index !== -1) {
        // Note:
        //   Class name is generated according to its filename.
        //   Different <style> tags in the same .vue file may generate same names.
        //   Append `_[index]` to class name to avoid this.
        query.localIdentName += '_' + index
      }
      return $1 + '?' + JSON.stringify(query)
    })
  }</style>
github benjycui / bisheng / packages / bisheng-core / lib / loaders / bisheng-data-loader.js View on Github external
module.exports = function bishengDataLoader(/* content */) {
  if (this.cacheable) {
    this.cacheable();
  }

  const query = loaderUtils.parseQuery(this.query);
  const config = getConfig(query.config);

  const markdown = markdownData.generate(config.source);
  const plugins = resolvePlugins(config.plugins, 'browser');
  const pluginsString = plugins.map(
    (plugin) =>
      `require('${plugin[0]}')(${JSON.stringify(plugin[1])})`
  ).join(',\n');

  return 'module.exports = {' +
    `\n  markdown: ${markdownData.stringify(markdown, config.lazyLoad)},` +
    `\n  plugins: [\n${pluginsString}\n],` +
    `\n};`;
};
github jhamlet / svg-react-loader / index.js View on Github external
module.exports = function (source) {
    // read our template
    var tmplPath = path.join(__dirname, 'utility', 'template.txt');

    // let webpack know about us, and get our callback
    var callback = this.async();
    this.addDependency(tmplPath);
    this.cacheable();

    // parameters to the loader
    var query     = lutils.parseQuery(this.query);
    var rsrcPath  = this.resourcePath;
    var rsrcQuery = lutils.parseQuery(this.resourceQuery);

    // resource parameters override loader parameters
    var params = assign({}, query, rsrcQuery);

    var displayName = params.name || getName(rsrcPath);
    var tag         = params.tag || null;
    var reactDom    = params.reactDom || 'react-dom';
    var attrs       = assign({}, params.attrs || {});

    var opts = {
        reactDom:    reactDom,
        tagName:     tag,
        attrs:       attrs,
        displayName: displayName
    };
github skozin / webpack-path-rewriter / es6 / index.js View on Github external
static loader(content) // loader entry point, called by Webpack; see PathRewriterEntry
  {
    this.cacheable && this.cacheable()

    var rewriter = this[ __dirname ]
    if (rewriter == undefined) {
      throw new Error(
        'webpack-path-rewriter loader is used without the corresponding plugin;\n  ' +
        'add `new PathRewriter()` to the list of plugins in the Webpack config'
      )
    }

    var query = loaderUtils.parseQuery(this.query && this.query.replace(/:BANG:/g, '!')),
        topLevelContext = this.options.context,
        publicPath = query.publicPath || this.options.output.publicPath || ''

    if (publicPath.length && publicPath[ publicPath.length - 1 ] != '/') {
      publicPath = publicPath + '/'
    }

    var url = loaderUtils.interpolateName(this, query.name || '[path][name].[ext]', {
      content: content,
      context: query.context || topLevelContext,
      regExp: query.nameRegExp
    })

    var moduleData = {url, content, publicPath, topLevelContext,
      request: this.request,
      context: this.context,
github liangklfangl / bisheng-sourceCode-plugin / src / loaders / markdown-loader.js View on Github external
module.exports = function markdownLoader(content) {
  if (this.cacheable) {
    this.cacheable();
  }
  const webpackRemainingChain = loaderUtils.getRemainingRequest(this).split('!');
  const fullPath = webpackRemainingChain[webpackRemainingChain.length - 1];
  const filename = path.relative(process.cwd(), fullPath);
  //从cwd开始查找我们的这个模块的路径
  const query = loaderUtils.parseQuery(this.query);
  const plugins = resolvePlugins(getConfig(query.config).plugins, 'node');
  //获取site/bisheng.cfg.js文件下的plugins插件,经过process处理后返回的plugins是如下的格式:
  const parsedMarkdown = markdownData.process(filename, content, plugins, query.isBuild);
  //这里得到已经解析后的markdown数据
  return `module.exports = ${stringify(parsedMarkdown)};`;
};
github visamz / art-template-loader / index.js View on Github external
module.exports = function(source) {
    this.cacheable &amp;&amp; this.cacheable()

    var options = _.extend({}, this.options.artTemplateLoader, loaderUtils.parseQuery(this.query))
    var format = options.format &amp;&amp; (options.format == 'native') ? 'template-native' : 'template'
    var template = require('art-template/dist/' + format)
    var ANONYMOUS_RE = /^function\s+anonymous/
    var UTILS_RE = /\$utils=this/
    var _oldOnError = template.onerror
    var render

    template.onerror = function(e) {
        var message = 'art Template Error\n\n'
        for (var name in e) {
            if (_.includes(['name', 'message', 'source'], name)) {
                message += '&lt;' + name + '&gt;\n' + e[name] + '\n\n'
            }
        }

        throw new SyntaxError(message)
github apache / incubator-weex-loader / src / index.js View on Github external
function loader (source) {
  this.cacheable && this.cacheable()

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

  promise.then(result => {
    if (type === 'style' || type === 'css' ||
      type === 'html' || type === 'tpl' || type === 'template') {
      result = 'module.exports=' + result
    }
    callback(null, result)
  }).catch(err => {
    this.emitError(err.toString())
    callback(err.toString(), '')
  })