Skip to content

Instantly share code, notes, and snippets.

@souporserious
Created July 16, 2017 19:41
Show Gist options
  • Save souporserious/b9b53c5a3c1f5f0326d06a419493c08f to your computer and use it in GitHub Desktop.
Save souporserious/b9b53c5a3c1f5f0326d06a419493c08f to your computer and use it in GitHub Desktop.
Load React component documentation information in Webpack using react-docgen
// 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