babel-plugin-source-code

0.1.0 • Public • Published

babel-plugin-source-code

Import file contents into your JSX <code> blocks at build time. Great for syntax highlighting component examples.

Installation

Install Prism as per their guide.

Install yarn add -D babel-plugin-source-code or npm i -D babel-plugin-source-code.

Add it to your babel plugins config:

{
  "plugins": ["babel-plugin-source-code"]
}

Usage

Create your demos in separate files to the documentation:

import { ButtonDemo } from './ButtonDemo'

export default function ButtonDocs() {
  return (
    <DocLayout title="Buttons">
      <ButtonDemo />
      <pre className="language-tsx">
        <code className="language-tsx">
          <ins data-path="./ButtonDemo.tsx" />
        </code>
      </pre>
    </DocLayout>
  )
}

Only use relative paths in data-path.

Readme

Keywords

none

Package Sidebar

Install

npm i babel-plugin-source-code

Weekly Downloads

1

Version

0.1.0

License

ISC

Unpacked Size

2.67 kB

Total Files

3

Last publish

Collaborators

  • ferahl