Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/colemars/react-config

A minimal react configuration with webpack, babel, hot-loader, and eslint
https://github.com/colemars/react-config

Last synced: 8 days ago
JSON representation

A minimal react configuration with webpack, babel, hot-loader, and eslint

Awesome Lists containing this project

README

        

# React Application Configuration

#### By **Phil Mass**

## Description

_This is a configuration setup for a React application. In this setup, I use the latest versions of all of the npm packages and the most current recommendations to be as future-proof as possible_

_You can see the deployed app [here](https://philrmass.github.io/react-config/)._

## To Build a New Project from this Configuration

* Git clone the repository at https://github.com/philrmass/react-config.git to a local directory
* Add your own project code

## Steps to Recreate this Configuration

* Create the directory, init git and npm (you can accept the defaults, creates package.json)
```console
mkdir react-config
cd react-config
git init
npm init
```
* Install webpack, webpack-cli, and webpack-dev-server
* _Note: all packages are installed locally in the project (no globals) and can be accessed via package.json scripts_
```console
npm install --save-dev webpack webpack-cli webpack-dev-server
```
* Install the babel packages
```console
npm install --save-dev @babel/core @babel/preset-env @babel/preset-react babel-loader
```
* Install the hot module replacement
```console
npm install --save-dev react-hot-loader
```
* Install eslint and the eslint webpack loader
```console
npm install --save-dev eslint eslint-loader eslint-plugin-react
```
* Install react and react-dom
```console
npm install --save react react-dom
```
* Add scripts to `./package.json` by adding the content:
```text
"scripts": {
"dev": "webpack --mode development",
"build": "webpack --mode production",
"start": "webpack-dev-server --mode production",
"lint": "eslint src/** src/**/**"
},
```
* Create `./.gitignore` with the content:
```text
# npm and build, allow index.html
node_modules/
public/*
!public/index.html

# mac
.DS_STORE/

# vim
*.swp
```
* Add the webpack configuration file `./webpack.config.js` with the content:
```text
const webpack = require('webpack');
const path = require('path');

module.exports = {
entry: './src/index.jsx',
module: {
rules: [
{
test: /\.(js|jsx)$/,
enforce: 'pre',
exclude: /node_modules/,
use: ['eslint-loader']
},
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ['babel-loader']
}
]
},
resolve: {
extensions: ['*', '.js', '.jsx']
},
output: {
publicPath: '/',
path: path.resolve(__dirname, 'public'),
filename: 'bundle.js'
},
plugins: [
new webpack.HotModuleReplacementPlugin()
],
devServer: {
contentBase: './public',
hot: true
}
};
```
* Create a babel configuration file at `./.babelrc` with the content:
```text
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
]
}
```
* Create an eslint configuration file at `./.eslintrc.json` with the content:
```text
{
"env": {
"browser": true,
"es6": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:react/recommended"
],
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": [
"react"
],
"rules": {
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"windows"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
]
}
}
```
* Create a `./public` directory and base file `.public/index.html` with the content:
```html


React Application




```
* Create a `./src` directory and entry point file `./src/index.jsx` with the content:
```javascript
import React from 'react';
import ReactDOM from 'react-dom';
import App from './components/App';

ReactDOM.render(
,
document.getElementById('app')
);

module.hot.accept();
```
* Create a `./src/components` directory and an app component file `./src/components/App.jsx` with the content:
```javascript
import React from 'react';

function App() {
return (


React Application



);
}

export default App;
```

I put together the information contained here from the following sources:
* https://webpack.js.org/guides/installation/
* https://webpack.js.org/guides/getting-started/
* https://www.robinwieruch.de/minimal-react-webpack-babel-setup/
* https://github.com/webpack-contrib/eslint-loader
* https://www.learnhowtoprogram.com/react

## Known Bugs

_None_

## Support and Contact Details

If you have any issues or questions, please email me at [email protected]

## Legal

Copyright (c) 2018 Phil Mass

This software is licensed under the MIT License