Bundling React 15, Bootstrap 4, Storybook 3 with Webpack 2

Andrea Falzetti
May 29, 2017 · 5 min read

Challenge

Ingredients

Bootstrap SASS

Storybook

Dynamically loaded stories

// ./storybook/config.js
import { configure } from '@storybook/react';

const req = require.context('../src/components', true, /\.stories\.js$/)

function loadStories() {
require('../stories');
req.keys().forEach((filename) => req(filename))
}

configure(loadStories, module);
// ./src/components/MyBeautifulButton/MyBeautifulButton.stories.js
import React from 'react';
import { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import { linkTo } from '@storybook/addon-links';

import MyBeautifulButton from './MyBeautifulButton'

const Story = ({ name, icon }) => (
<MyBeautifulButton name='Test' icon='user' />
);

Story.propTypes = {
name: React.PropTypes.string.isRequired,
icon: React.PropTypes.string.isRequired
};

storiesOf('MyBeautifulButton', module)
.add('Incomplete', () => (
<MyBeautifulButton name="User" icon="user" status='0' />
))
.add('Started', () => (
<MyBeautifulButton name="User" icon="user" status='50' />
))
.add('Next', () => (
<MyBeautifulButton name="User" icon="user" status='0' isNext />
))
.add('Completed', () => (
<MyBeautifulButton name="User" icon="user" status={100} />
))
.add('Disabled', () => (
<MyBeautifulButton name="User" icon="user" disabled={true} />
));

Output

storybook-3-result
storybook-3-result
storybook-3-result
storybook-3-result
storybook-3-result
storybook-3-result

Customise Bootstrap

$navbar-height: 150px;
$navbar-default-bg: $brand-primary;
$brand-primary:         #58C7D6 !default; // Blue
$brand-success: #75C158 !default; // Green
$brand-info: #E6BE31 !default; // Yellow
$brand-warning: #ee7e2d !default; // Orange
$brand-danger: #d9534f !default; // Red
@import 'base';
@import "bootstrap.scss";
@import '~bootstrap/scss/bootstrap.scss';

// Some best-practice CSS that's useful for most apps
// Just remove them if they're not what you want
html {
box-sizing: border-box;
}

html,
body {
margin: 0;
padding: 0;
height: 100%;
}

*,
*:before,
*:after {
box-sizing: inherit;
}

Conclusions

Work with me

Andrea Falzetti

Written by

Backend & DevOps Engineer in London

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade