Created
July 16, 2017 19:41
-
-
Save souporserious/b9b53c5a3c1f5f0326d06a419493c08f to your computer and use it in GitHub Desktop.
Load React component documentation information in Webpack using react-docgen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Adaptation from: https://github.com/styleguidist/react-styleguidist/blob/a010018f6672af81332018399fc0e595e81d4b24/scripts/schemas/config.js | |
var reactDocgen = require('react-docgen') | |
var createDisplayNameHandler = require('react-docgen-displayname-handler') | |
.createDisplayNameHandler | |
module.exports = function(content) { | |
this.cacheable && this.cacheable(true) | |
var callback = this.async() | |
var file = this.request.split('!').pop() | |
var docs = reactDocgen.parse( | |
content, | |
reactDocgen.resolver.findAllExportedComponentDefinitions, | |
reactDocgen.defaultHandlers.concat(createDisplayNameHandler(file)) | |
) | |
callback(null, `module.exports = ${JSON.stringify(docs)}`) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment