Skip to content

Commit b331928

Browse files
committed
feat(setup): initital commit with working test
0 parents  commit b331928

15 files changed

+8897
-0
lines changed

.babelrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"presets": ["@babel/preset-env", "@babel/preset-react"],
3+
"plugins": ["@babel/plugin-proposal-class-properties"]
4+
}

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
#node/weback dirs
9+
dist
10+
node_modules
11+
12+
.DS_Store

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# apexad's personal react redux webpack setup
2+
- I set this up so I don't have to do i every time I want to start a poject
3+
- Uses React, Redux, Webpack, Axios and has a fake server using `json-server`
4+
- That is all

package-lock.json

Lines changed: 8647 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "apexad-react-redux-webpack",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "webpack-dev-server --open --mode development",
8+
"build": "webpack --mode production",
9+
"start:server": "json-server --watch test.json",
10+
"test": "echo \"Error: no test specified\" && exit 1"
11+
},
12+
"keywords": [],
13+
"author": "",
14+
"license": "ISC",
15+
"devDependencies": {
16+
"@babel/core": "^7.8.6",
17+
"@babel/plugin-proposal-class-properties": "^7.8.3",
18+
"@babel/preset-env": "^7.8.6",
19+
"@babel/preset-react": "^7.8.3",
20+
"babel-loader": "^8.0.6",
21+
"html-loader": "^0.5.5",
22+
"html-webpack-plugin": "^3.2.0",
23+
"webpack": "^4.41.6",
24+
"webpack-cli": "^3.3.11",
25+
"webpack-dev-server": "^3.10.3"
26+
},
27+
"dependencies": {
28+
"axios": "^0.19.2",
29+
"json-server": "^0.16.1",
30+
"react": "^16.13.0",
31+
"react-dom": "^16.13.0",
32+
"react-redux": "^7.2.0",
33+
"redux": "^4.0.5",
34+
"redux-thunk": "^2.3.0"
35+
}
36+
}

src/actions/test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import axios from 'axios';
2+
3+
export const testAction = () => dispatch => {
4+
dispatch({
5+
type: 'TEST_ACTION',
6+
payload: 'test-action-result'
7+
})
8+
}
9+
10+
export const testFetch = () => dispatch => {
11+
axios.get('http://localhost:3000/tests')
12+
.then((response) => {
13+
dispatch({
14+
type: 'TEST_FETCH',
15+
payload: response.data,
16+
});
17+
})
18+
.catch(error => {
19+
dispatch({
20+
type: 'TEST_ERROR'
21+
});
22+
})
23+
}
24+

src/components/App.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import React, { Component } from "react";
2+
import { connect } from 'react-redux';
3+
import { testFetch } from '../actions/test';
4+
5+
class App extends Component {
6+
constructor() {
7+
super();
8+
9+
this.state = {
10+
value: ""
11+
};
12+
}
13+
14+
componentDidMount() {
15+
this.props.testFetch();
16+
}
17+
18+
render() {
19+
return (
20+
<div>
21+
<h1>Test</h1>
22+
{this.props.test.error && <p>Did you run npm start:server?</p>}
23+
<ul>
24+
{
25+
this.props.test.test.map(item => {
26+
return <li key={item.name}>{item.name} - {item.data}</li>
27+
})
28+
}
29+
</ul>
30+
</div>
31+
);
32+
}
33+
}
34+
35+
const mapStateToProps = state => ({
36+
test: state.testReducer,
37+
})
38+
39+
const mapDispatchToProps = dispatch => ({
40+
testFetch: () => dispatch(testFetch())
41+
})
42+
43+
export default connect(mapStateToProps, mapDispatchToProps)(App);

src/index.css

Whitespace-only changes.

src/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Test Demo</title>
6+
</head>
7+
<body>
8+
<div id="container"></div>
9+
</body>
10+
</html>

src/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
src/index.js
3+
*/
4+
5+
import React from 'react';
6+
import ReactDOM from 'react-dom';
7+
import { Provider } from 'react-redux'
8+
import configureStore from './store';
9+
import './index.css';
10+
import App from './components/App';
11+
12+
ReactDOM.render(
13+
<Provider store={configureStore()}>
14+
<App />
15+
</Provider>,
16+
document.getElementById('container')
17+
);

src/reducers/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { combineReducers } from 'redux';
2+
import testReducer from './test';
3+
4+
export default combineReducers({
5+
testReducer,
6+
});

src/reducers/test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const inititalState = {
2+
test: [],
3+
error: false,
4+
};
5+
6+
export default (state = inititalState, action) => {
7+
switch (action.type) {
8+
case 'TEST_FETCH':
9+
return { ...state,
10+
test: action.payload
11+
};
12+
case 'TEST_ERROR':
13+
return { ...state,
14+
error: true,
15+
};
16+
default:
17+
return state;
18+
}
19+
}

src/store.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* src/store.js
3+
* No initialState
4+
*/
5+
import { createStore, applyMiddleware } from 'redux';
6+
import thunk from 'redux-thunk';
7+
import rootReducer from './reducers/';
8+
9+
export default function configureStore() {
10+
return createStore(
11+
rootReducer,
12+
applyMiddleware(thunk)
13+
);
14+
}

test.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"tests": [
3+
{
4+
"name": "test1",
5+
"data": "data1"
6+
},
7+
{
8+
"name": "test2",
9+
"data": "data2"
10+
},
11+
{
12+
"name": "test3",
13+
"data": "data3"
14+
},
15+
{
16+
"name": "test4",
17+
"data": "data4"
18+
},
19+
{
20+
"name": "test5",
21+
"data": "data5"
22+
},
23+
{
24+
"name": "test6",
25+
"data": "data6"
26+
},
27+
{
28+
"name": "test7",
29+
"data": "data7"
30+
}
31+
]
32+
}

webpack.config.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const HtmlWebPackPlugin = require("html-webpack-plugin");
2+
3+
module.exports = {
4+
module: {
5+
rules: [
6+
{
7+
test: /\.(js|jsx)$/,
8+
exclude: /node_modules/,
9+
use: {
10+
loader: "babel-loader"
11+
}
12+
},
13+
{
14+
test: /\.html$/,
15+
use: [
16+
{
17+
loader: "html-loader"
18+
}
19+
]
20+
}
21+
]
22+
},
23+
plugins: [
24+
new HtmlWebPackPlugin({
25+
template: "./src/index.html",
26+
filename: "./index.html"
27+
})
28+
]
29+
};

0 commit comments

Comments
 (0)