Skip to content

Commit

Permalink
Set up the project.
Browse files Browse the repository at this point in the history
  • Loading branch information
yamafaktory committed May 5, 2016
0 parents commit 5d05a77
Show file tree
Hide file tree
Showing 10 changed files with 262 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
build
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: node_js

node_js:
- 6.0.0

cache:
directories:
- node_modules

script:
- npm run build:dev
- npm run build

sudo: false
82 changes: 82 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# babel-react-rollup-starter [![Build Status](https://travis-ci.org/yamafaktory/babel-react-rollup-starter.svg?branch=master)](https://travis-ci.org/yamafaktory/babel-react-rollup-starter) [![npm version](https://img.shields.io/npm/v/babel-react-rollup-starter.svg?style=flat)](https://www.npmjs.com/package/babel-react-rollup-starter) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)

> A simple starter project to build cool [React](https://facebook.github.io/react/) applications with [Babel](http://babeljs.io/) and [Rollup](http://rollupjs.org/).
The aim of this project is to provide a simple boilerplate to get started with React bundled as an ES2015 module via Rollup, compiled by Babel.

To sum up and give an overview of what can be achieved like a breath of fresh air:

```JavaScript
// Import React and React-dom.
import React from 'react'
import ReactDOM from 'react-dom'

// Import the components.
import { DummyComponent } from './components/dummy-component.jsx'

// Define the root element.
const root = document.querySelector('main')

// Append the DummyComponent to the root element.
ReactDOM.render(<DummyComponent />, root)
```

Rollup will magically includes only what you need in your bundle depending on the imports!

## Prerequisite

### NodeJS

The easiest way to go is to use [nvm](https://github.com/creationix/nvm) and to install one of the recent NodeJS versions bundled with npm 3 by default (i.e. *NodeJS >= 5.0.0*).

## Installation

Clone this repository.

```bash
git clone https://github.com/yamafaktory/babel-react-rollup-starter
cd babel-react-rollup-starter
npm i
```

Or even better, use *npm*!

```bash
npm i babel-react-rollup-starter
```

## Usage

### Development

A basic workflow involving [Browsersync](https://www.browsersync.io/) is already implemented. Running the following command will open your default browser pointing to the `html/index-dev.html` file. Any modification of one of the files included in the *src* directory will trigger a new development build and refresh your browser:

```bash
npm test
```

You can also generate a development build by running the following command:

```bash
npm run build:dev
```

### Production

First run the following command:

```bash
npm run build
```

Then open the `html/index.html` file in your browser.

The Rollup production configuration file switch the NodeJS environment to production and minify the code with [UglifyJS](http://lisperator.net/uglifyjs/).

## Linting

The code quality is checked by the [JavaScript Standard Style](http://standardjs.com/).

## License

Released under the [MIT license](https://opensource.org/licenses/MIT) by Davy Duperron.
34 changes: 34 additions & 0 deletions config/dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Rollup plugins.
import babel from 'rollup-plugin-babel'
import cjs from 'rollup-plugin-commonjs'
import globals from 'rollup-plugin-node-globals'
import npm from 'rollup-plugin-npm'
import replace from 'rollup-plugin-replace'
import resolve from 'rollup-plugin-node-resolve'

export default {
dest: 'build/app.js',
entry: 'src/index.js',
format: 'iife',
plugins: [
babel({
babelrc: false,
exclude: 'node_modules/**',
presets: [ 'es2015-rollup', 'stage-0', 'react' ]
}),
cjs({
exclude: 'node_modules/process-es6/**',
include: [
'node_modules/fbjs/**',
'node_modules/object-assign/**',
'node_modules/react/**',
'node_modules/react-dom/**'
]
}),
globals(),
npm({ main: true }),
replace({ 'process.env.NODE_ENV': JSON.stringify('development') }),
resolve({ browser: true })
],
sourceMap: true
}
13 changes: 13 additions & 0 deletions config/prod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Rollup plugins.
import replace from 'rollup-plugin-replace'
import uglify from 'rollup-plugin-uglify'

// Import the development configuration.
import config from './dev'

// Inject the production settings.
config.dest = 'build/app.min.js'
config.plugins[4] = replace({ 'process.env.NODE_ENV': JSON.stringify('production') })
config.plugins.push(uglify())

export default config
13 changes: 13 additions & 0 deletions html/index-dev.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>babel-react-rollup-starter</title>
</head>
<body>
<main></main>
<script src="build/app.js"></script>
</body>
</html>
13 changes: 13 additions & 0 deletions html/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>babel-react-rollup-starter</title>
</head>
<body>
<main></main>
<script src="../build/app.min.js"></script>
</body>
</html>
67 changes: 67 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"name": "babel-react-rollup-starter",
"version": "1.0.0",
"title": "babel-react-rollup-starter",
"description": "A simple starter project to build cool React applications with Babel and Rollup.",
"keywords": [
"Babel",
"Browsersync",
"React",
"Rollup",
"StandardJS"
],
"homepage": "https://github.com/yamafaktory/babel-react-rollup-starter",
"author": {
"name": "Davy Duperron",
"url": "https://github.com/yamafaktory"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/yamafaktory/babel-react-rollup-starter"
},
"engines": {
"npm": ">=3.0.0",
"node": ">=5.0.0"
},
"dependencies": {
"react": "15.0.2",
"react-dom": "15.0.2"
},
"devDependencies": {
"babel-cli": "6.7.7",
"babel-preset-es2015-rollup": "1.1.0",
"babel-preset-react": "6.5.0",
"babel-preset-stage-0": "6.5.0",
"browser-sync": "2.12.5",
"npm-run-all": "1.6.0",
"onchange": "2.2.0",
"rollup": "0.26.1",
"rollup-plugin-babel": "2.4.0",
"rollup-plugin-commonjs": "2.2.1",
"rollup-plugin-node-globals": "1.0.5",
"rollup-plugin-node-resolve": "1.5.0",
"rollup-plugin-npm": "1.4.0",
"rollup-plugin-replace": "1.1.0",
"rollup-plugin-uglify": "0.3.1",
"snazzy": "3.0.1",
"standard": "6.0.8"
},
"scripts": {
"prebuild": "npm run std",
"build": "rollup -c config/prod.js",
"build:dev": "rollup -c config/dev.js",
"browse": "browser-sync start --s --index 'html/index-dev.html' --files 'html/**/*.html, build/**/*.js' --no-notify",
"std": "standard --verbose | snazzy",
"test": "npm-run-all --parallel watch browse",
"watch": "onchange src -- npm run build:dev",
"preversion": "git pull && npm up && npm run std",
"version": "npm run build && git add -A .",
"postversion": "git push --tags origin HEAD"
},
"standard": {
"ignore": [
"build"
]
}
}
12 changes: 12 additions & 0 deletions src/components/dummy-component.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react'

export class DummyComponent extends React.Component {
render () {
return (
<article>
<h1>Hi from DummyComponent.</h1>
<em>Now let's play with React!</em>
</article>
)
}
}
12 changes: 12 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Import React and React-dom.
import React from 'react'
import ReactDOM from 'react-dom'

// Import the components.
import { DummyComponent } from './components/dummy-component.jsx'

// Define the root element.
const root = document.querySelector('main')

// Append the DummyComponent to the root element.
ReactDOM.render(<DummyComponent />, root)

0 comments on commit 5d05a77

Please sign in to comment.