Skip to content

Instantly share code, notes, and snippets.

@mikoloism
Created June 16, 2021 17:53
Show Gist options
  • Save mikoloism/360b598420ae5bb2589d8d3c0c133b0b to your computer and use it in GitHub Desktop.
Save mikoloism/360b598420ae5bb2589d8d3c0c133b0b to your computer and use it in GitHub Desktop.
how create npm package from react-components

How create npm package from React components

Structur

  • src/
    • components/
      • COMPONENT_NAME/
        • COMPONENT_NAME.jsx // or js
        • index.js
    • stories
      • COMPONENT_NAME.stories.js
    • index.js
  • package.json

Steps

  • init npm npm init
    • set main file you should set main keyword
  • install react(-dom) npm install --save-dev react react-dom
  • use storybook npx sb init
  • run storybook npm run storybook
  • install babel react npm install --save-dev @babel/preset-react
// ./src/components/my-component/index.js
export * from './my-component.jsx';
// ./src/components/my-component/my-component.jsx
export const MyComponent = () => (
<div>
Hi, this is my component
</div>
);
// ./src/index.js
export * from './components/my-component';
// ./src/stories/my-componentn.stories.js
import React from 'react';
import { storiesOf } from '@storybook/react';
import { MyComponent } from '../components/my-component';
const stories = storiesOf('App Test', module);
stories.add('App', () => {
return( <MyComponent /> );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment