ryanmcgrath / react-iconpack Goto Github PK
View Code? Open in Web Editor NEWA React Component for handling SVG icons, coupled with Babel and Browserify plugins to only bundle the icons you use.
License: MIT License
A React Component for handling SVG icons, coupled with Babel and Browserify plugins to only bundle the icons you use.
License: MIT License
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.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.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:
<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.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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.