Skip to content

Commit 18ec62c

Browse files
committed
initial
1 parent 3dee53b commit 18ec62c

25 files changed

+5275
-4
lines changed

.gitignore

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/dist
2+
3+
.eslintcache
4+
5+
.DS_STORE
6+
7+
# Logs
8+
logs
9+
*.log
10+
npm-debug.log*
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
17+
# Directory for instrumented libs generated by jscoverage/JSCover
18+
lib-cov
19+
20+
# Coverage directory used by tools like istanbul
21+
coverage
22+
23+
# nyc test coverage
24+
.nyc_output
25+
26+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
27+
.grunt
28+
29+
# node-waf configuration
30+
.lock-wscript
31+
32+
# Compiled binary addons (http://nodejs.org/api/addons.html)
33+
build
34+
35+
# Dependency directories
36+
node_modules
37+
jspm_packages
38+
39+
# Optional npm cache directory
40+
.npm
41+
42+
# Optional REPL history
43+
.node_repl_history
44+
45+
/lib/
46+
47+
assets/images/thumbs/
48+
49+
public

LICENSE

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
MIT License
1+
The MIT License (MIT)
22

3-
Copyright (c) 2017 Djamel Hassaine
3+
Copyright (c) 2015 Ali Al Dallal
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
@@ -19,3 +19,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
SOFTWARE.
22+

README.md

+97-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,97 @@
1-
# reactPureVsClass
2-
A comparison of using react pure components with higher order components and standard react classes
1+
# react-webpack-babel
2+
Simple React Webpack Babel Starter Kit
3+
4+
Tired of complicated starters with 200MB of dependencies which are hard to understand and modify?
5+
6+
Try this is a simple [React](https://facebook.github.io/react/), [Webpack](http://webpack.github.io/) and [Babel](https://babeljs.io/) application with nothing else in it.
7+
8+
### What's in it?
9+
10+
* Simple src/index.jsx and src/index.css (local module css).
11+
* Webpack configuration for development (with hot reloading) and production (with minification).
12+
* CSS module loading, so you can include your css by ```import styles from './path/to.css';```.
13+
* Both js(x) and css hot loaded during development.
14+
* [Webpack Dashboard Plugin](https://github.com/FormidableLabs/webpack-dashboard) on dev server.
15+
16+
### To run
17+
18+
* You'll need to have [git](https://git-scm.com/) and [node](https://nodejs.org/en/) installed in your system.
19+
* Fork and clone the project:
20+
21+
```
22+
git clone https://github.com/alicoding/react-webpack-babel.git
23+
```
24+
25+
* Then install the dependencies:
26+
27+
```
28+
npm install
29+
```
30+
31+
* Run development server:
32+
33+
```
34+
npm start
35+
```
36+
37+
* Or you can run development server with [webpack-dashboard](https://github.com/FormidableLabs/webpack-dashboard):
38+
39+
```
40+
npm run dev
41+
```
42+
43+
Open the web browser to `http://localhost:8888/`
44+
45+
### To build the production package
46+
47+
```
48+
npm run build
49+
```
50+
51+
### Nginx Config
52+
53+
Here is an example Nginx config:
54+
```
55+
server {
56+
# ... root and other options
57+
58+
gzip on;
59+
gzip_http_version 1.1;
60+
gzip_types text/plain text/css text/xml application/javascript image/svg+xml;
61+
62+
location / {
63+
try_files $uri $uri/ /index.html;
64+
}
65+
66+
location ~ \.html?$ {
67+
expires 1d;
68+
}
69+
70+
location ~ \.(svg|ttf|js|css|svgz|eot|otf|woff|jpg|jpeg|gif|png|ico)$ {
71+
access_log off;
72+
log_not_found off;
73+
expires max;
74+
}
75+
}
76+
```
77+
78+
### Eslint
79+
There is a .eslint.yaml config for eslint ready with React plugin.
80+
To use it, you need to install additional dependencies though:
81+
82+
```
83+
npm install --save-dev eslint eslint-plugin-react
84+
```
85+
86+
To do the actual linting, run:
87+
88+
```
89+
npm run lint
90+
```
91+
92+
### Notes on importing css styles
93+
* styles having /src/ in their absolute path are considered part of the application and exported as local css modules.
94+
* other styles are considered global styles used by many components and are included in the css bundle directly.
95+
96+
### Contribute
97+
Please contribute to the project if you know how to make it better, including this README :)

package.json

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"name": "react-webpack-babel",
3+
"version": "0.0.3",
4+
"description": "React Webpack Babel Starter Kit",
5+
"main": "''",
6+
"scripts": {
7+
"build": "webpack --config webpack.production.config.js --progress --profile --colors",
8+
"start": "webpack-dev-server --progress --profile --colors",
9+
"lint": "eslint --ext js --ext jsx src || exit 0",
10+
"dev": " webpack-dashboard -- webpack-dev-server --progress --profile --colors",
11+
"test": "NODE_PATH=./src mocha --require jsdom-global/register --compilers js:babel-core/register --recursive 'src/**/*.spec.@(js|jsx)'"
12+
},
13+
"repository": {
14+
"type": "git",
15+
"url": "https://github.com/alicoding/react-webpack-babel"
16+
},
17+
"author": "Ali Al Dallal",
18+
"license": "MIT",
19+
"homepage": "https://github.com/alicoding/react-webpack-babel#readme",
20+
"dependencies": {
21+
"node-sass": "^4.3.0",
22+
"react": "15.4.2",
23+
"react-dom": "15.4.2",
24+
"sass-loader": "^6.0.2"
25+
},
26+
"devDependencies": {
27+
"babel-core": "^6.23.1",
28+
"babel-eslint": "^7.2.3",
29+
"babel-loader": "^6.3.2",
30+
"babel-plugin-transform-class-properties": "^6.22.0",
31+
"babel-plugin-transform-decorators-legacy": "^1.3.4",
32+
"babel-plugin-transform-es2015-destructuring": "^6.23.0",
33+
"babel-plugin-transform-object-rest-spread": "^6.23.0",
34+
"babel-plugin-transform-runtime": "^6.22.0",
35+
"babel-preset-es2015": "6.22.0",
36+
"babel-preset-react": "^6.23.0",
37+
"babel-runtime": "^6.22.0",
38+
"chai": "^3.5.0",
39+
"css-loader": "0.26.1",
40+
"enzyme": "^2.8.2",
41+
"extract-text-webpack-plugin": "^v2.0.0-rc.1",
42+
"file-loader": "^0.10.0",
43+
"html-webpack-plugin": "^2.26.0",
44+
"jsdom": "^9.4.2",
45+
"jsdom-global": "^2.0.0",
46+
"mocha": "^3.3.0",
47+
"postcss-loader": "^1.2.2",
48+
"react-addons-test-utils": "^15.5.1",
49+
"react-hot-loader": "^3.0.0-beta.6",
50+
"sinon": "^2.1.0",
51+
"style-loader": "0.13.1",
52+
"url-loader": "0.5.7",
53+
"webpack": "^2.2.1",
54+
"webpack-cleanup-plugin": "^0.4.2",
55+
"webpack-dashboard": "^0.3.0",
56+
"webpack-dev-server": "^2.4.1"
57+
}
58+
}

postcss.config.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const AUTOPREFIXER_BROWSERS = [
2+
'Android 2.3',
3+
'Android >= 4',
4+
'Chrome >= 35',
5+
'Firefox >= 31',
6+
'Explorer >= 9',
7+
'iOS >= 7',
8+
'Opera >= 12',
9+
'Safari >= 7.1',
10+
];
11+
12+
module.exports = {
13+
plugins: [
14+
require('autoprefixer')({ browsers: AUTOPREFIXER_BROWSERS })
15+
]
16+
}

src/app.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react';
2+
import Toggle from './classBased/toggle';
3+
import Info from './classBased/info';
4+
5+
import PureInfo from './pure/info';
6+
import PureToggle from './pure/toggle';
7+
8+
export default class App extends React.Component {
9+
render() {
10+
return (
11+
<div>
12+
<h1>Keep your react components pure</h1>
13+
<section>
14+
<Toggle />
15+
<div>
16+
<Info>Pure functions are easier to reuse</Info>
17+
</div>
18+
</section>
19+
20+
<section>
21+
<PureToggle />
22+
<div>
23+
<PureInfo>Pure functions are simpler to reason about</PureInfo>
24+
</div>
25+
</section>
26+
</div>
27+
)
28+
}
29+
}

src/classBased/info.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React from 'react';
2+
3+
export default class Info extends React.Component {
4+
static propTypes = {
5+
visible: React.PropTypes.bool,
6+
children: React.PropTypes.node.isRequired
7+
};
8+
static defaultProps = {
9+
visible: false
10+
};
11+
state = {
12+
visible: this.props.visible
13+
};
14+
15+
toggle() {
16+
this.setState({ visible: !this.state.visible });
17+
}
18+
19+
render() {
20+
if (this.state.visible) {
21+
return (
22+
<span>
23+
<span id="toggleInfo" onClick={() => this.toggle()}>Hide info: </span>
24+
{this.props.children}
25+
</span>
26+
);
27+
} else {
28+
return <span id="toggleInfo" onClick={() => this.toggle()}>Show info</span>;
29+
}
30+
}
31+
}

src/classBased/info.spec.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
import React from 'react';
3+
import Info from './info';
4+
import { assert } from 'chai';
5+
import { shallow } from 'enzyme';
6+
7+
const infoMessage = 'Something important here';
8+
function renderInfoComponent(visible) {
9+
return shallow(
10+
<Info visible={visible}>
11+
{infoMessage}
12+
</Info>
13+
);
14+
}
15+
16+
function assertInfoVisible(wrapper) {
17+
assert.isOk(wrapper);
18+
const html = wrapper.html()
19+
assert.include(html, 'Show info');
20+
assert.notInclude(html, infoMessage);
21+
}
22+
23+
function assertInfoHidden(wrapper) {
24+
assert.isOk(wrapper);
25+
const html = wrapper.html()
26+
assert.include(html, 'Hide info');
27+
assert.include(html, infoMessage);
28+
}
29+
30+
describe('Info', function () {
31+
it('Renders "show info"', function () {
32+
const wrapper = renderInfoComponent(false);
33+
assertInfoVisible(wrapper);
34+
});
35+
36+
it('Renders info and "Hide info" button', function () {
37+
const wrapper = renderInfoComponent(true);
38+
assertInfoHidden(wrapper);
39+
});
40+
41+
it('Can toggle info', function () {
42+
const wrapper = renderInfoComponent(false);
43+
assertInfoVisible(wrapper);
44+
45+
wrapper.find('#toggleInfo').simulate('click');
46+
assertInfoHidden(wrapper);
47+
48+
wrapper.find('#toggleInfo').simulate('click');
49+
assertInfoVisible(wrapper);
50+
});
51+
});

src/classBased/toggle.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react';
2+
3+
export default class Toggle extends React.Component {
4+
static propTypes = {
5+
on: React.PropTypes.bool
6+
};
7+
static defaultProps = {
8+
on: false
9+
};
10+
state = {
11+
on: this.props.on
12+
};
13+
14+
toggle() {
15+
this.setState({on: !this.state.on});
16+
}
17+
18+
render() {
19+
return this.state.on ?
20+
<span onClick={() => this.toggle()}>On</span> :
21+
<span onClick={() => this.toggle()}>Off</span>
22+
}
23+
}

0 commit comments

Comments
 (0)