Skip to content

Commit

Permalink
Setup project.
Browse files Browse the repository at this point in the history
  • Loading branch information
yamafaktory committed May 16, 2016
0 parents commit 32aa34d
Show file tree
Hide file tree
Showing 11 changed files with 275 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
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Davy Duperron

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
83 changes: 83 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# buble-react-rollup-starter [![Build Status](https://travis-ci.org/yamafaktory/buble-react-rollup-starter.svg?branch=master)](https://travis-ci.org/yamafaktory/buble-react-rollup-starter) [![npm version](https://img.shields.io/npm/v/buble-react-rollup-starter.svg?style=flat)](https://www.npmjs.com/package/buble-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 [Bublé](https://buble.surge.sh/guide/) 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 Bublé.

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

```JavaScript
// Import React, ReactDOM and the component.
import React from 'react'
import ReactDOM from 'react-dom'
import { DummyComponent } from './components/dummy-component.js'

// Define the root element and instantiate the DummyComponent.
const root = document.querySelector('main')
const dummyComponent = React.createElement(DummyComponent)

// Append the DummyComponent instance to the root element.
ReactDOM.render(dummyComponent, root)
```

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

Please not that this starter project [doesn't use JSX templates which are not currently handled by Bublé](https://gitlab.com/Rich-Harris/buble/issues/26). If you really want JSX to be part of your workflow, please give [babel-react-rollup-starter](https://github.com/yamafaktory/babel-react-rollup-starter) a try!

## 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/buble-react-rollup-starter
cd buble-react-rollup-starter
npm i
```

Or even better, use *npm*!

```bash
npm i buble-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.
30 changes: 30 additions & 0 deletions config/dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Rollup plugins.
import buble from 'rollup-plugin-buble'
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: [
buble(),
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>
64 changes: 64 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"name": "buble-react-rollup-starter",
"version": "1.0.0",
"title": "buble-react-rollup-starter",
"description": "A simple starter project to build cool React applications with Bublé and Rollup.",
"keywords": [
"Bublé",
"Browsersync",
"React",
"Rollup",
"StandardJS"
],
"homepage": "https://github.com/yamafaktory/buble-react-rollup-starter",
"author": {
"name": "Davy Duperron",
"url": "https://github.com/yamafaktory"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/yamafaktory/buble-react-rollup-starter"
},
"engines": {
"npm": ">=3.0.0",
"node": ">=5.0.0"
},
"dependencies": {
"react": "15.0.2",
"react-dom": "15.0.2"
},
"devDependencies": {
"buble": "0.8.4",
"browser-sync": "2.12.5",
"npm-run-all": "1.6.0",
"onchange": "2.2.0",
"rollup": "0.26.3",
"rollup-plugin-buble": "0.8.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"
]
}
}
11 changes: 11 additions & 0 deletions src/components/dummy-component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Import React.
import React from 'react'

// Create the elements.
const title = React.createElement('h1', { key: 'title' }, 'Hi from DummyComponent.')
const content = React.createElement('em', { key: 'content' }, 'Now let\'s play with React!')
const article = React.createElement('article', null, [title, content])

export class DummyComponent extends React.Component {
render () { return article }
}
11 changes: 11 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Import React, ReactDOM and the component.
import React from 'react'
import ReactDOM from 'react-dom'
import { DummyComponent } from './components/dummy-component.js'

// Define the root element and instantiate the DummyComponent.
const root = document.querySelector('main')
const dummyComponent = React.createElement(DummyComponent)

// Append the DummyComponent instance to the root element.
ReactDOM.render(dummyComponent, root)

0 comments on commit 32aa34d

Please # to comment.