commit 25ef9a176ee9bab902579f79415bd6047a77a62f
Author: Simon Bailey <simon@newtriks.com>
Date: Thu May 15 19:51:45 2014 +0100
Updated README
Signed-off-by: Simon Bailey <simon@newtriks.com>
commit 1b0020c8fd248bc0dc892bed1f3e315867378274
Merge: d8fd494 c468b98
Author: Edd <accounts@edd.fm>
Date: Sat Apr 26 11:13:52 2014 +0100
Merged with Master
commit d8fd494478cb7fd0d97a47a90986f4c1b29eb996
Author: Edd <accounts@edd.fm>
Date: Thu Apr 24 22:09:19 2014 +0100
Trimming redundant options from Gruntfile
commit b5015ae42b0beb770ae1b146f152b5f38764987e
Author: Edd <accounts@edd.fm>
Date: Sun Mar 30 21:32:14 2014 +0100
Moved development mode to webpack-dev-server to imrove rebuild times
commit 7d31ade8085a8d415b95c67dba69ae5157ebf9b4
Author: Edd <accounts@edd.fm>
Date: Wed Feb 26 00:18:56 2014 +0000
Changed JSX filenames to .jsx over .js
commit 00faa6182b6cb4ae46b05dd12db1e73da4b47953
Author: Edd <accounts@edd.fm>
Date: Mon Feb 24 23:39:18 2014 +0000
Updated engines & Travis build targets
commit e58e0d70639f3c3e9acc7d085b6a795365a140a6
Author: Edd <accounts@edd.fm>
Date: Mon Feb 24 23:26:04 2014 +0000
Added auto generation of a template CSS file for a component
commit f6c67351aead570224b2457261d457a1954277dc
Author: Edd <accounts@edd.fm>
Date: Mon Feb 24 00:06:42 2014 +0000
Updated default app test
commit 996d769685d1a4f20ae2c4117422790bbc347594
Author: Edd <accounts@edd.fm>
Date: Sun Feb 23 23:32:37 2014 +0000
Added test for default main component (currently identical to any other component tests)
commit 31dfcbaff6ee9aef339886897e053a339f98021b
Author: Edd <accounts@edd.fm>
Date: Sun Feb 23 22:54:04 2014 +0000
Moved webpack configuration to a separate file
- Added webpack config file
- Added Uglify to webpack config
- Added source maps in webpack config
Moved entry file back in to Gruntfile
commit 6b3a3e92b80f3121e1128e4f166cf36aa32cfa26
Author: Edd <accounts@edd.fm>
Date: Sun Feb 23 17:23:07 2014 +0000
Added distribution folder & Grunt tasks to deal with it
- Created Distribution build folder (script link broken)
- Added grunt-contrib-copy
- Added grunt-uglify
- Bumped React version number
- Switched source map types
Signed-off-by: Simon Bailey <simon@newtriks.com>
generator-react-webpack

Yeoman generator for ReactJS - lets you quickly set up a project including karma test runner and Webpack module system.
Usage
Install generator-react-webpack:
npm install -g generator-react-webpack
Make a new directory, and cd into it:
mkdir my-new-project && cd $_
Run yo react-webpack, optionally passing an app name:
yo react-webpack [app-name]
Run grunt for building and grunt serve for preview in the browser at localhost.
Generators
Available generators:
Note: Generators are to be run from the root directory of your app.
App
Sets up a new ReactJS app, generating all the boilerplate you need to get started. The app generator also facilitates the following:
- Configures a Gruntfile to run the app on a local server.
- Configures Webpack to modularise the app enabling loading of various file formats e.g. JSON, CSS, PNG, etc.
- Configures Karma to run all tests.
- Watches for changes and recompiles JS and refreshes the browser.
Example:
yo react-webpack
Component
Generates a JSX component in src/scripts/components and it's corresponding test in src/spec/components.
Example:
yo react-webpack:component foo
Produces src/scripts/components/Foo.jsx (javascript - JSX):
/**
* @jsx React.DOM
*/
'use strict';
var React = require('react/addons');
var Foo = React.createClass({
/*jshint ignore:start */
render: function () {
return (
<div>
<p>Content for Foo</p>
</div>
)
}
/*jshint ignore:end */
});
module.exports = Foo;
And test/spec/components/Foo.js (javascript - jasmine):
'use strict';
describe('Foo', function () {
var Foo, component;
beforeEach(function () {
Foo = require('../../../src/scripts/components/Foo');
component = Foo();
});
it('should create a new instance of Foo', function () {
expect(component).toBeDefined();
});
});
And src/styles/Foo.css:
.Foo{
border: 1px dashed #f00;
}
Testing
Running grunt test will run the unit tests with karma. Tests are written using Jasmine by default.
Further Information
Project Structure
The react-webpack generator automates the setup of a ReactJS project using the specific structure detailed below:
project
- src
- scripts
-components
ComponentOne.js
ComponentTwo.js
main.js
- styles
main.css
reset.css
index.html
- test
- spec
- components
ComponentOne.js
ComponentTwo.js
- helpers
- react
addons.js
phantomjs-shims.js
Gruntfile.js
karma.conf.js
I have tried to keep the project structure as simple as possible and understand it may not suit everyone.
Naming Components
I have opted to follow @floydophone convention of uppercase for component file naming e.g. Component.js. I am open to suggestions if there is a general objection to this decision.
Modules
Each component is a module and can be required using the Webpack module system. Webpack uses Loaders which means you can also require CSS and a host of other file types. Read the Webpack documentation to find out more.
Grunt
Out the box the Gruntfile is configured with the following:
- webpack: uses the grunt-webpack plugin to load all required modules and output to a single JS file
src/scripts/main.js. This is included in thesrc/index.htmlfile by default and will reload in the browser as and when it is recompiled. - webpack-dev-server: uses the webpack-dev-server to watch for file changes and also serve the webpack app in development.
- connect: uses the grunt-connect plugin to start a webserver at localhost.
- karma: uses the grunt-karma plugin to load the Karma configuration file
karma.conf.jslocated in the project root. This will run all tests using PhantomJS by default but supports many other browsers.
CSS
Included in the project is Eric Meyer's reset.css script. There is also a src/styles/main.css script that's required by the core src/scripts/components/App.js component using Webpack.
Props
Thanks to all who contributed to generator-angular as the majority of code here has been shamelessy sourced from that repos.
Contribute
Contributions are welcomed. When submitting a bugfix, write a test that exposes the bug and fails before applying your fix. Submit the test alongside the fix.