Skip to content

Commit

Permalink
Refactor to use CSS Modules (#1)
Browse files Browse the repository at this point in the history
* Move config.json into package.json.

* Update dependencies.

* Add react-fastclick.

* Add react-router-scroll.

* Remove Radium dependency.

* Add Eslint rule to allow jsx in .js files.

* Disable react/require-extension rule.

* Add dependencies for CSS modules.

* Add CSS modules & PostCSS to Webpack config.

* Update dev_server to run on 0.0.0.0

* Commit isomorphic Webpack config.

* Add CSS bundle support for build_static.

* Refactor components to CSS Modules.

* Add normalize.css dependency.

* Update README.

* Bump version.
  • Loading branch information
webyak authored Aug 19, 2016
1 parent 9d3bbff commit db153a4
Show file tree
Hide file tree
Showing 23 changed files with 295 additions and 210 deletions.
44 changes: 15 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,43 @@
# React Static Plate

> Build static sites with React to host on [Amazon S3](https://aws.amazon.com/s3/), [Github Pages](https://pages.github.com/), [Surge](https://surge.sh/) et cetera<br>
> (React.js, React Router, Radium, Babel 6, Webpack)
> Build static sites with React & CSS Modules to host on [Amazon S3](https://aws.amazon.com/s3/), [Github Pages](https://pages.github.com/), [Surge](https://surge.sh/) etc.
> *React | React Router | Babel 6 | CSS Modules | PostCSS | Webpack*
### Features

&nbsp; &nbsp;ES6+.<br>
&nbsp; &nbsp;Hot Reloading.<br>
&nbsp; &nbsp;ESLint rules based on Airbnb's Javascript Styleguide.<br>
&nbsp; &nbsp;Every route is completely rendered into a `.html` page with `renderToString`.<br>
&nbsp; &nbsp;Deferred script loading, so the browser can render the html without waiting for the js bundle first.<br>
&nbsp; &nbsp;Hash is added to every asset's filename, so you can cache all assets forever.<br>
&nbsp; &nbsp;Title, Meta and other SEO tags with [react-helmet](https://github.com/nfl/react-helmet).<br>
&nbsp; &nbsp;SEO friendly, no JavaScript required to view a page.<br>
&nbsp; &nbsp;Generates sitemap.xml <br>
- ES6+.
- Hot Reloading.
- ESLint rules based on Airbnb's Javascript Styleguide.
- Every route is completely rendered into a `.html` page with `renderToString`.
- Deferred script loading, so the browser can render the html without waiting for the js bundle first.
- Hash is added to every asset's filename, so you can cache all assets forever.
- Title, Meta and other SEO tags with [react-helmet](https://github.com/nfl/react-helmet).
- SEO friendly, no JavaScript required to view a page.
- Generates sitemap.xml

### Getting Started

Clone the repo, install Node modules and run the development server:
Fork the repo, install the node modules and run the dev server:

```
$ git clone -o react-static-plate -b master --single-branch \
https://github.com/webyak/react-static-plate.git my-site
$ cd my-site
$ npm install
$ npm start
```

Then open [http://localhost:3000](http://localhost:3000) and have fun ;)
Open [http://localhost:3000](http://localhost:3000) & have fun. 🐒

### Deploy

Set your `host` in `config.json` and generate all the static files with `npm run build`. Then upload the contents of the `build/` folder to your hosting solution of choice. Finish.
Set your `host` in `config.json` and generate all the static files with `npm run build`. Then upload the contents of the `build/` folder to your hosting solution of choice. Finish!

You can also see the production site on your local machine using `http-server`:
You can also check out the production build on your local machine using `http-server`:

```
$ npm install -g http-server
$ cd build
$ http-server
```

### Update

You can fetch and merge recent changes from this repo into your own project:

```
$ git checkout master
$ git fetch react-static-plate
$ git merge react-static-plate/master
$ npm install
```

### FAQ

**My site is not working properly on Amazon S3**:<br>
Expand Down
33 changes: 0 additions & 33 deletions client/components/hello.js

This file was deleted.

15 changes: 15 additions & 0 deletions client/components/hello/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// ==================================================
// Hello
// ==================================================

import React from 'react';
import { wrap, heading } from './style.css';

const Hello = () => (
<div className={wrap}>
<h1 className={heading}>Hello React</h1>
<div>🙈</div>
</div>
);

export default Hello;
13 changes: 13 additions & 0 deletions client/components/hello/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.wrap {
padding-top: rem(150);
text-align: center;
}

.heading {
font-size: rem(45);
line-height: 2;
cursor: default;
}
.heading:hover {
font-weight: bold;
}
35 changes: 0 additions & 35 deletions client/components/layout.js

This file was deleted.

28 changes: 28 additions & 0 deletions client/components/layout/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// ==================================================
// Layout
// ==================================================

import React from 'react';
import Helmet from 'react-helmet';
import './style.css';

const Layout = ({ children }) => (
<div>
<Helmet
title="My site"
meta={[
{ name: 'description', content: 'A static site.' },
]}
link={[
{ rel: 'shortcut icon', href: require('../../assets/favicon.ico') },
]}
/>
{children}
</div>
);

Layout.propTypes = {
children: React.PropTypes.element,
};

export default Layout;
63 changes: 63 additions & 0 deletions client/components/layout/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
@import 'normalize.css';
@import '../../styling/colors.css';

html,
body {
width: 100%;
height: 100%;
}
body {
font-family: -apple-system, BlinkMacSystemFont, sans-serif;
font-weight: 400;
line-height: 1.4;
color: $darkGray;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

* {
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
box-sizing: border-box;
}

a {
color: inherit;
text-decoration: none;
}
a:hover {
color: inherit;
}

h1,
h2,
h3,
h4,
h5,
h6 {
padding: 0;
margin: 0;
font-weight: 400;
line-height: 1.2;
}

input,
textarea {
display: block;
padding: 0;
margin: 0;
border: 0;
outline: none;
}
input:-webkit-autofill: {
-webkit-box-shadow: 0 0 0 1000px #fff inset;
}
textarea {
resize: none;
}

ul,
p {
padding: 0;
margin: 0;
}
3 changes: 1 addition & 2 deletions client/components/not_found.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
// ==================================================

import React from 'react';
import Radium from 'radium';

const NotFound = () => (
<div>404</div>
);

export default Radium(NotFound);
export default NotFound;
9 changes: 7 additions & 2 deletions client/components/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
// ==================================================

import React from 'react';
import { Router, browserHistory } from 'react-router';
import { Router, browserHistory, applyRouterMiddleware } from 'react-router';
import { useScroll } from 'react-router-scroll';

import routes from '../routes.js';

const Root = () => (
<Router routes={routes} history={browserHistory} />
<Router
routes={routes}
history={browserHistory}
render={applyRouterMiddleware(useScroll())}
/>
);

export default Root;
1 change: 1 addition & 0 deletions client/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable global-require */
import 'react-fastclick';
import React from 'react';
import ReactDOM from 'react-dom';

Expand Down
4 changes: 2 additions & 2 deletions client/routes.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { Route, IndexRoute } from 'react-router';

import Layout from './components/layout.js';
import Hello from './components/hello.js';
import Layout from './components/layout/';
import Hello from './components/hello/';
import NotFound from './components/not_found.js';

const routes = (
Expand Down
1 change: 1 addition & 0 deletions client/styling/colors.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$darkGray: #323233;
5 changes: 0 additions & 5 deletions client/styling/colors.js

This file was deleted.

10 changes: 0 additions & 10 deletions client/styling/common_styles.js

This file was deleted.

3 changes: 0 additions & 3 deletions config.json

This file was deleted.

Loading

0 comments on commit db153a4

Please sign in to comment.