当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript loader-utils.getOptions函数代码示例

本文整理汇总了TypeScript中loader-utils.getOptions函数的典型用法代码示例。如果您正苦于以下问题:TypeScript getOptions函数的具体用法?TypeScript getOptions怎么用?TypeScript getOptions使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了getOptions函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: svgSimplifyLoader

function svgSimplifyLoader(this: any, content: string) {
  if (this.cacheable) {
    this.cacheable();
  }

  const callback = this.async();

  let options = loaderUtils.getOptions(this);

  if (options.useConfig) {
    const configName = options.useConfig;
    options = this.options[configName];
    if (options === undefined) {
      callback(
        new Error(
          `You specified "useConfig=${configName}" for simplify-svg-loader
        but there is no property named "${configName}" in your main webpack configuration.`,
        ),
      );
      return;
    }
  }

  const res = simplifySvg(content, options.plugins);

  callback(null, res);
}
开发者ID:morlay,项目名称:simplify-svg,代码行数:27,代码来源:index.ts

示例2: normalizeOptions

function normalizeOptions(this: LoaderContext): StyleResourcesLoaderNormalizedOptions {
    const options = getOptions(this) || {};

    /* istanbul ignore if: not possible to test */
    if (!validateOptions(options)) {
        throw new TypeError(
            '[style-resources-loader] This error is caused by a bug in options validator. '
             + 'Please file an issue: https://github.com/yenshih/style-resources-loader/issues.',
        );
    }

    const {
        patterns,
        injector,
        globOptions = {},
        resolveUrl = true,
    } = options;

    return {
        patterns: normalizePatterns(patterns),
        injector: normalizeInjector(injector),
        globOptions,
        resolveUrl,
    };
}
开发者ID:aldCom,项目名称:aldCom.github.io,代码行数:25,代码来源:normalizeOptions.ts

示例3: function

// 专门用于解析 ant-icons 图标的加载器
export default async function(this: any) {
    const options = getOptions(this) || {};
    const icons = (options.inclues || []).map(createIconData);

    // 源码中的所有文件
    const files = await readFiles(resolve('src'));

    // 枚举所有文件
    for (const file of files) {
        // 跳过非 vue 文件
        if (extname(file) !== '.vue') {
            continue;
        }

        const content = (await fs.readFile(file)).toString();

        icons.push(...constantIcon(content));
        icons.push(...iconInButton(content));
        icons.push(...iconInComponent(content));
    }

    // 去除重复图标
    const result = uniqueIcon(icons);

    // 按照 es 的标准格式导出
    return result.map(({ type, theme }) => {
        const iconType = `${camelize(type)}${camelize(theme)}`;
        return `export { default as ${iconType} } from './${theme}/${iconType}';`;
    }).join('\n');
}
开发者ID:rectification,项目名称:circuitlab,代码行数:31,代码来源:ant-icons-loader.ts

示例4: getLoaderOptions

/**
 * either retrieves loader options from the cache
 * or creates them, adds them to the cache and returns
 */
function getLoaderOptions(loaderContext: Webpack) {
  // differentiate the TypeScript instance based on the webpack instance
  let webpackIndex = webpackInstances.indexOf(loaderContext._compiler);
  if (webpackIndex === -1) {
    webpackIndex = webpackInstances.push(loaderContext._compiler) - 1;
  }

  const loaderOptions =
    loaderUtils.getOptions<LoaderOptions>(loaderContext) ||
    ({} as LoaderOptions);

  const instanceName =
    webpackIndex + '_' + (loaderOptions.instance || 'default');

  if (!loaderOptionsCache.hasOwnProperty(instanceName)) {
    loaderOptionsCache[instanceName] = new WeakMap();
  }

  const cache = loaderOptionsCache[instanceName];

  if (cache.has(loaderOptions)) {
    return cache.get(loaderOptions) as LoaderOptions;
  }

  validateLoaderOptions(loaderOptions);

  const options = makeLoaderOptions(instanceName, loaderOptions);

  cache.set(loaderOptions, options);

  return options;
}
开发者ID:johnnyreilly,项目名称:ts-loader,代码行数:36,代码来源:index.ts

示例5: function

export = function(source: string, map) {
   this.cacheable && this.cacheable();

   const options = loaderUtils.getOptions(this);
   const originalData = options.json || options;

   const data = { ...originalData };

   const verboseFlag = "ifdef-verbose";
   const verbose = data[verboseFlag];
   if(verbose !== undefined) {
      delete data[verboseFlag];
   }

   const tripleSlashFlag = "ifdef-triple-slash";
   const tripleSlash = data[tripleSlashFlag];
   if(tripleSlash !== undefined) {
      delete data[tripleSlashFlag];
   }

   try {
      source = parse(source, data, verbose, tripleSlash);
      this.callback(null, source, map);
   } catch(err) {
      const errorMessage = `ifdef-loader error: ${err}`;
      this.callback(new Error(errorMessage));
   }
};
开发者ID:nippur72,项目名称:ifdef-loader,代码行数:28,代码来源:ifdef-loader.ts

示例6: function

module.exports = function (source: string): void {
  if (this.cacheable) {
    this.cacheable();
  }

  const callback: (
    error: Error | null,
    content: string | Buffer,
  ) => void = this.async();

  const { schema, typeMap, options }: IOptions = loaderUtils.getOptions(this) as IOptions;

  if (!schema) {
    return callback(new Error('Schema must be provided'), source);
  }

  const declaration: string = gqlRun(schema, source, typeMap, options)
    .map(({ result }) => result)
    .join('\n');

  fs.writeFile(
    `${this.resourcePath}.d.ts`,
    buildDeclaration(declaration),
    err => callback(err, source),
  );
};
开发者ID:avantcredit,项目名称:gql2ts,代码行数:26,代码来源:index.ts

示例7: getNormalizedOptions

export function getNormalizedOptions(this: loader.LoaderContext): StyleResourcesLoaderOptions {
    const defaultInjector = 'prepend';

    const defaultGlobOptions = {};

    const defaultResolveUrl = true;

    const {
        patterns,
        injector = defaultInjector,
        globOptions = defaultGlobOptions,
        resolveUrl = defaultResolveUrl,
    }: StyleResourcesLoaderOriginalOptions = getOptions(this) || {};

    if (!isString(patterns) && !(Array.isArray(patterns) && patterns.every(isString))) {
        throw new TypeError(
            '[style-resources-loader] Expected options.patterns to be a string or an array of string. '
            + `Instead received ${typeof patterns}.`,
        );
    }

    if (typeof injector !== 'function' && !Object.keys(internalInjectors).includes(injector)) {
        throw new TypeError(
            '[style-resources-loader] Expected options.injector to be a function or `prepend`, `append`. '
            + `Instead received ${typeof injector}.`,
        );
    }

    if (typeof globOptions !== 'object') {
        throw new TypeError(
            '[style-resources-loader] Expected options.globOptions to be an object. '
            + `Instead received ${typeof globOptions}.`,
        );
    }

    if (typeof resolveUrl !== 'boolean') {
        throw new TypeError(
            '[style-resources-loader] Expected options.resolveUrl to be a boolean. '
            + `Instead received ${typeof resolveUrl}.`,
        );
    }

    return {
        patterns,
        injector: getNormalizedInjector(injector),
        globOptions,
        resolveUrl,
    };
}
开发者ID:CAIJIN1002,项目名称:Front-end__Questions,代码行数:49,代码来源:getNormalizedOptions.ts

示例8: function

module.exports.pitch = function(remainingRequest: string, precedingRequest: string): string {
  const options = loaderUtils.getOptions(this) || {};
  const moduleRequest = `!!${remainingRequest}`;
  const normalizedRequest = loaderUtils.stringifyRequest(this, moduleRequest);
  const moduleName = path.basename(normalizedRequest).replace(/\..*$/, '');
  const request = loaderUtils.stringifyRequest(this, moduleRequest);

  return [
    "import Loadable from 'react-loadable';",
    `export var ${moduleName} = Loadable({`,
    `  loader: function() { return import(${getMagicComments(options)} ${request}).then(function(m) { return m.${moduleName}; }); },`,
    `  loading: function() { return null; }`,
    `});`
  ].join('\n');
};
开发者ID:OfficeDev,项目名称:office-ui-fabric-react,代码行数:15,代码来源:fabricAsyncLoader.ts

示例9: getLoaderOptions

/**
 * either retrieves loader options from the cache
 * or creates them, adds them to the cache and returns
 */
function getLoaderOptions(loader: Webpack) {
    // differentiate the TypeScript instance based on the webpack instance
    let webpackIndex = webpackInstances.indexOf(loader._compiler);
    if (webpackIndex === -1) {
        webpackIndex = webpackInstances.push(loader._compiler) - 1;
    }

    const loaderOptions = loaderUtils.getOptions<LoaderOptions>(loader) || {} as LoaderOptions;

    const instanceName = webpackIndex + '_' + (loaderOptions.instance || 'default');

    if (loaderOptionsCache.hasOwnProperty(instanceName)) {
        return loaderOptionsCache[instanceName];
    }

    validateLoaderOptions(loaderOptions);

    const options = makeLoaderOptions(instanceName, loaderOptions);

    loaderOptionsCache[instanceName] = options;

    return options;
}
开发者ID:bjohnso5,项目名称:ts-loader,代码行数:27,代码来源:index.ts

示例10: loader

function loader(code: string): string {
  const webpackRemainingChain = getRemainingRequest(this).split("!");
  const filePath = webpackRemainingChain[webpackRemainingChain.length - 1];
  const options: Options = getOptions(this) as Options;
  return transform(code, {filePath, ...options}).code;
}
开发者ID:alangpierce,项目名称:sucrase,代码行数:6,代码来源:index.ts


注:本文中的loader-utils.getOptions函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。