GithubHelp home page GithubHelp logo

Comments (5)

NetanelBasal avatar NetanelBasal commented on July 18, 2024 1

Yes

from svg-icon.

NetanelBasal avatar NetanelBasal commented on July 18, 2024

You can use svg-to-ts.

from svg-icon.

elliottregan avatar elliottregan commented on July 18, 2024

@NetanelBasal Would you accept a PR that re-implements this functionality? I was also looking to add multiples paths for the same reason.

from svg-icon.

elliottregan avatar elliottregan commented on July 18, 2024

@criskrzysiu I was able to add multiple file paths using the Webpack plugin. Works out really nicely, and there's no extra build step.

// webpack.config.ts

import { Configuration } from 'webpack';
// @ts-ignore
import { SvgGeneratorWebpackPlugin } from '@ngneat/svg-generator/webpack-plugin';

export default {
  plugins: [
    new SvgGeneratorWebpackPlugin({
      srcPath: './node_modules/@fortawesome/fontawesome-pro/svgs',
      outputPath: './src/app/svg/fontawesome/brands',
      svgoConfig: {
        plugins: [
          "removeDimensions"
        ],
      },
    }),
    new SvgGeneratorWebpackPlugin({
      srcPath: './src/assets/custom-svgs',
      outputPath: './src/app/svg/custom',
      svgoConfig: {
        plugins: [
          "removeDimensions"
        ],
      },
    }),
  ],
} as Configuration;

You can achieve the same result (with even more control) with svg-to-ts, you just need to add a separate command to compile each icon set you need to use.

The only downside with the Webpack Plugin right now has to do with how Fontawesome's SVGs are organized (and probably other icon libraries that offer multiple weights/styles). @ngneat/svg-icon uses the filename as the name property of the generated TS objects. Since Fontawesome uses the same filenames across each icon set, I need to do some manual renaming in order to reference the correct icons.

import { acornIcon as faRegularAcorn } from './svg/fontawesome/regular/acorn'
import { acornIcon as faSolidAcorn } from './svg/fontawesome/solid/acorn'
faRegularAcorn.name = 'fa-regular-acorn'
faSolidAcorn.name = 'fa-solid-acorn'

In order to properly support multiple directories, we would need to add not only multiple paths, but multiple configurations for each path. Fontawesome has multiple directories for each icon set, and each icon set uses the same filenames. I would need to add custom name prefixes for each srcPath so I can refer to each icon set using a unique name. i.e. <svg-icon key="'fa-thin-checkmark'|'fa-regular-checkmark'"></svg-icon>.

This is certainly doable, but it would be a pretty big change to the configuration.

from svg-icon.

NetanelBasal avatar NetanelBasal commented on July 18, 2024

You can add a nameNormalizer function that returns a modified name if you want.

from svg-icon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.