Coder Social home page Coder Social logo

0m15 / generator-react-coffee-webpack Goto Github PK

View Code? Open in Web Editor NEW

This project forked from react-webpack-generators/generator-react-webpack

4.0 3.0 3.0 291 KB

Yeoman generator for ReactJS and Webpack, with CoffeeScript support

License: MIT License

JavaScript 99.01% CSS 0.30% CoffeeScript 0.56% HTML 0.13%

generator-react-coffee-webpack's Introduction

generator-react-coffee-webpack Build Status Built with Grunt

Yeoman generator for ReactJS - lets you quickly set up a project including karma test runner and Webpack module system. Adds CoffeeScript support. Based on generator-react-webpack.

Usage

Install generator-react-coffee-webpack:

npm install -g generator-react-coffee-webpack

Make a new directory, and cd into it:

mkdir my-new-project && cd $_

Run yo react-coffee-webpack, optionally passing an app name:

yo react-coffee-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:

  1. Configures a Gruntfile to run the app on a local server.
  2. Configures Webpack to modularise the app enabling loading of various file formats e.g. JSON, CSS, PNG, etc.
  3. Configures Karma to run all tests.
  4. Watches for changes and recompiles JS and refreshes the browser.

Example:

yo react-coffee-webpack

Component

Generates a JSX component in src/scripts/components/<name> and it's corresponding test in src/spec/components/<name>.

Example:

yo react-coffee-webpack:component foo

Produces src/scripts/components/Foo/Foo.coffee (javascript - JSX):

/**
 * @jsx React.DOM
 */

'use strict';

React = require 'react/addons'

var Foo = React.createClass
  render: -> 
    `<div>
      <p>Content for Foo</p>
    </div>`

module.exports = Foo

And test/spec/components/Foo/Foo.coffee (javascript - jasmine):


`'use strict';`

describe 'Foo', -> 

  beforeEach ->
    Foo = require '../../../src/scripts/components/Foo/Foo.coffee'
    component = Foo()

  it 'should create a new instance of Foo', ->
    expect(component).toBeDefined()

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
          ComponentOne.coffee
        - ComponentTwo
          ComponentTwo.coffee
      main.js
    - styles
      main.css
      reset.css
    index.html
  - test
    - spec
      - components
        - ComponentOne
          ComponentOne.coffee
        - ComponentTwo
          ComponentTwo.coffee
    - 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:

  1. 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 the src/index.html file by default and will reload in the browser as and when it is recompiled.
  2. watch: uses the grunt-watch plugin and watches for file changes. Livereload support is included by default and thus on file change the webpack task is run and the browser will auto update.
  3. connect: uses the grunt-connect plugin to start a webserver at localhost.
  4. karma: uses the grunt-karma plugin to load the Karma configuration file karma.conf.js located 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.

License

BSD license

generator-react-coffee-webpack's People

Contributors

0m15 avatar bitdeli-chef avatar newtriks avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  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.