Giter Site home page Giter Site logo

ryanmcgrath / react-iconpack Goto Github PK

View Code? Open in Web Editor NEW
25.0 3.0 2.0 997 KB

A React Component for handling SVG icons, coupled with Babel and Browserify plugins to only bundle the icons you use.

License: MIT License

JavaScript 99.97% HTML 0.03%

react-iconpack's Issues

Call for Input re: caching

This approach is pretty much 90% of the way there, but that last naggling 10% is the caching integration with regards to Webpack/Babel/etc. I'd love to hear input from others on this. Insofar as my understanding goes:

  • babel-loader's cacheDirectory option essentially stores the outputted code into a gzip'd temp file. When re-using the cache it won't re-run babel transformers, which is the big crux of the problem here. I've poured over documentation and such but I'm unsure as to whether there's a way to force a transform to always run (I'm guessing there's not, as it'd make little sense). For reference, this is all re: Babel 6.
  • Webpack's cache: true config parameter actually half-works. It winds up accruing SVGs to inject, and when one is removed from the source code it's not actually evicted from the cache. At the moment I can't tell whether this is a bug with Webpack or not, because deleted entries are still winding up in the source code. Documentation on Webpack's internals is admittedly sketchy at best.
  • I believe watchify has the same issue as Webpack's cache, but I've not delved into it as of yet. I don't use Browserify these days but I know enough people/teams that do and would like to continue supporting it, so should probably determine the full scope of it here at some point.

A quick rundown of how the project works (and I should put this on the wiki at some point) is as follows:

  • The Babel transform runs on compile, basically accruing unique <Icon ... /> calls. It doesn't actually transform anything because it doesn't need to. This is stored in a shared packer variable, basically relying on require() semantics to use a global store - each call to require a module returns the cached output. Yes, I'm aware globals are frowned upon, but I find this works A-OK here and reduces the need for any extra 3rd party library integrations for simple storage.
  • Depending on whether the user is a Browserify or Webpack setup, they get a specific plugin - the configuration of each is pretty straightforward and shown in the gulpfile.js and webpack.config.js examples.
  • index.js is a bit of magic, but it's liberally commented and understandable. Depending on how the module is imported the return value changes - if 'browserify' or 'webpack' is passed to the require() returned function, it will return the corresponding plugin. If it's loaded by babel as a transform, it will return the necessary Babel transformer. If none of the above is happening, it returns a Webpack loader, which is happening because Webpack's internals are nigh undecipherable at a glance and it's a cheap way to inject the icon module source code. This module is shoved in during the compilation process via the Webpack plugin.

Just figured having an open issue where anyone can comment or throw input up would be helpful. Feel free to dump questions here as well.

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.