Add experimental Webpack support. Works fine when no cache is involved, but I need to figure out a better story for cache integration as most builds that teams use likely include a cache enabled.
This commit is contained in:
parent
f2040233d0
commit
3801044178
18 changed files with 40032 additions and 486 deletions
30
lib/BabelSVGTracker.js
Normal file
30
lib/BabelSVGTracker.js
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/**
|
||||
* A Babel "plugin/transformer" that just tracks unique <Icon.../>
|
||||
* JSX tags in your source code. Note that this does absolutely no
|
||||
* modifications - just accumulates the unique SVG uris for the mapping.
|
||||
*
|
||||
* @param {Object} babel This will be auto-passed, most likely, by Babel.
|
||||
* @returns {Object} babel.Transformer used for the babel'ing. You know the one.
|
||||
*/
|
||||
module.exports = function(babel) {
|
||||
var _packer = this;
|
||||
|
||||
return {
|
||||
visitor: {
|
||||
JSXElement: function JSXElement(node, parent, scope, file) {
|
||||
if(_packer.opts.JSXTagNames.indexOf(node.node.openingElement.name.name) < 0)
|
||||
return;
|
||||
|
||||
var attributes = node.node.openingElement.attributes,
|
||||
l = attributes.length,
|
||||
i = 0;
|
||||
|
||||
for(; i < l; i++) {
|
||||
if(attributes[i].name.name !== 'uri')
|
||||
continue;
|
||||
_packer.SVGS[attributes[i].value.value] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
Reference in a new issue