Skip to content

jeantimex/react-webpack-boilerplate

Repository files navigation

React Webpack Boilerplate

Node Version React Version Build Status Dependency Status Coverage Status

React Webpack

This boilerplate helps you quickly setup React project, it includes the following features:

This project is based on react-es6-webpack-karma-boilerplate.

##React

The following features are supported:

Functional Component

const App = () => (
    <div className='main-app'>
        <h1>Hello, World!</h1>
    </div>
);

Class Component

class App extends Component {
    render() {
        return (
            <div className='main-app'>
                <h1>Hello, World!</h1>
            </div>
        );
    }
}

Class Properties

class Menu extends Component {
    static propTypes = {
        className: PropTypes.string,
    };
    ...
}

Export Default

export default App;

Import .scss in Component

import './styles.scss';
const App = () => <div />;

Localization

We use Yahoo's React Intl (v2.0) library to support localization.

1. To support a new locale, e.g. ja-JP, copy i18n/en-US.properties to i18n/ja-JP.properties, translate the locale messages.

2. Specify a LOCALE env var in npm start to debug for a specific locale:

$ LOCALE=en-US npm start

You can also build the bundle.js for a specific locale:

$ LOCALE=en-US npm run build

This will output the English bundle.js in dist/en-US folder. Note, if you don't specify LOCALE, default is en-US.

3. To build bundle.js for all languages:

$ npm run release

This will output each supported language bundle.js along with the style sheets in dist/{locale} folder.

Unit Test

Assert & Expect

import { assert, expect } from 'chai';
...

Enzyme

import { shallow } from 'enzyme';
describe('Testing', () => {
    it('should render the App', () => {
        const wrapper = shallow(<App />);
        ...
    });
});

Sinon

const sandbox = sinon.sandbox.create();
describe('Testing', () => {
    afterEach(() => sandbox.verifyAndRestore());
    it('should call the callback', () => {
        const callback = sandbox.stub();
        ...
    });
});

Coverage Report

Code coverage report is geneated by istanbul. npm run coveralls will submit the coverage report to coveralls.io.

Example:

==================== Coverage / Threshold summary =============================
Statements   : 100% ( 46/46 ) Threshold : 90%, 4 ignored
Branches     : 100% ( 31/31 ) Threshold : 90%, 13 ignored
Functions    : 100% ( 10/10 ) Threshold : 90%
Lines        : 100% (  6/6  ) Threshold : 90%
================================================================================

HTML and lcov reports can be found in the coverage folder.

How to use this package

Download or clone the package, then

$ npm install
$ npm start

navigate to http://localhost:5000 in your browser.

Hot-load for a lanuage

$ LOCALE=en-US npm start

Linting

ESLint with React linting options have been enabled.

$ npm run lint

Unit testing

Start Karma test runner.

$ npm run test

Build bundle.js

Build files for production

$ npm run build

Build bundle.js for a language

$ LOCALE=en-US npm run build

Build all language bundles

$ npm run release

Clean

Remove dist and coverage folders

$ npm run clean

About

React Webpack Boilerplate

Resources

License

Stars

Watchers

Forks

Packages

No packages published