Coder Social home page Coder Social logo

react-seed's Introduction

React seed

A boilerplate for building React apps with ES6 and webpack.

What you get

  • React 0.13
  • Compilation of ES6 & JSX to ES5
  • Jest testing framework
  • webpack bundling with html, css & sass loaders
  • Basic flux architecture with app actions, events and stores

Getting started

Clone the project and remove the git repository:

git clone --depth=1 https://github.com/badsyntax/react-seed.git my-project
cd my-project
rm -rf .git

npm scripts

  • npm start - Build and start the app in dev mode at http://localhost:8000
  • npm test - Run the tests
  • npm run build - Run a production build

Examples

Writing components:

// Filename: Menu.jsx

'use strict';

import './_Menu.scss';

import React from 'react';
import MenuItem from '../MenuItem/MenuItem';

var { PropTypes } = React;

class Menu extends React.Component {

  constructor(...args) {
    super(...args);
    // Set initial state
    this.state = {
      foo: false
    };
  }

  getMenuItem(item) {
    return (
      <MenuItem item={item} key={'menu-item-' + item.id} />
    );
  }

  render() {
    return (
      <ul className={'menu'}>
        {this.props.items.map(this.getMenuItem, this)}
      </ul>
    );
  }
}

Menu.propTypes = {
  items: PropTypes.array.isRequired
};

export default Menu;

Writing tests:

// Filename: __tests__/Menu-test.js

'use strict';

import React from 'react/addons';

jest.dontMock('../Menu.jsx');
jest.dontMock('../../MenuItem/MenuItem.jsx');

import Menu from '../Menu.jsx';

var { TestUtils } = React.addons;

describe('Menu', () => {

  var menuItems = [
    { id: 1, label: 'Option 1' },
    { id: 2, label: 'Option 2' }
  ];

  var menu = TestUtils.renderIntoDocument(
    <Menu items={menuItems} />
  );
  var menuElem = React.findDOMNode(menu);

  it('Renders the menu items', () => {
    expect(menuElem.querySelectorAll('li').length).toEqual(2);
  });
});

Sass, CSS & webpack

import Sass and CSS files from within your JavaScript component files:

// Filename: app.jsx
import 'normalize.css/normalize.css';
import './scss/app.scss';
  • Sass include paths can be adjusted in the webpack.config.js file.
  • All CSS (compiled or otherwise) is run through Autoprefixer.
  • CSS files are combined in the order in which they are imported in JavaScript, thus you should always import your CSS/Sass before importing any other JavaScript files.
  • Use an approach like BEM to avoid specificity issues that might exist due to unpredicatable order of CSS rules.

HTML files

All required .html files are compiled with lodash.template and synced into the ./build directory:

// Filename: app.jsx
import './index.html';
  • You can adjust the lodash template data in the webpack.config.js file.

Releasing

Updating version:

  • npm version patch - Bump version
  • git push && git push --tags - Push to remote

Publishing package:

  • npm login - Login to npm
  • npm publish - Publish package

Credits

This project was initially forked from https://github.com/tcoopman/react-es6-browserify

License

Copyright (c) 2015 Richard Willis

MIT (http://opensource.org/licenses/MIT)

react-seed's People

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.