How to use the @svgr/core.getComponentName function in @svgr/core

To help you get started, we’ve selected a few @svgr/core 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 ant-design / ant-design-icons / build / index.js View on Github external
await Promise.all(outputDirs.map((dir) => rimraf(dir)));

  if (shouldGenerateReactComponent) {
    await mkdirp(OUTPUT_DIR);
  }

  console.log(chalk.green(`[Generate SVG Component] Icon Amount: ${svgFileNames.length}`));

  const componentNames = [];
  const metaData = {};
  const mirrorMetaData = {};

  for (const svgPath of svgFilePaths) {
    const svgCode = fs.readFileSync(svgPath);
    const svgName = `${getComponentName({ filePath: svgPath })}`;
    componentNames.push(svgName);
    const kebabcaseName = kebabcase(svgName);
    metaData[kebabcaseName] = svgName;
    mirrorMetaData[svgName] = kebabcaseName;

    if (shouldGenerateReactComponent) {
      const componentCode = await svgr(svgCode, svgrConfig, { filePath: svgPath });
      fs.writeFileSync(path.resolve(OUTPUT_DIR, `${svgName}.tsx`), componentCode);
    }
  }

  if (shouldGenerateReactComponent) {
    console.log(chalk.green(`[Generate SVG Component] Icon Components Generated!`));
  }