├── .babelrc ├── .editorconfig ├── .eslintrc.js ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .prettierrc.js ├── .vscode ├── extentions.json └── settings.json ├── LICENSE.md ├── README.md ├── jest.config.js ├── package-lock.json ├── package.json ├── public └── index.html ├── src ├── components │ └── Foo │ │ ├── Foo.js │ │ └── Foo.test.js ├── index.js ├── registerServiceWorker.js ├── scripts │ └── SetupEnzyme.js └── utils │ ├── ShallowWrappedComponent │ └── ShallowWrappedComponent.js │ └── TestUtils │ └── TestUtils.js └── webpack.config.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["@babel/preset-env", "@babel/preset-react"], 3 | "plugins": ["@babel/plugin-syntax-dynamic-import"] 4 | } -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | "env": { 3 | "node": true, 4 | "jest": true, 5 | "browser": true 6 | }, 7 | "parser": "babel-eslint", 8 | "extends": [ 9 | "airbnb", 10 | "plugin:react/recommended", // Following the preset's recommendation: https://github.com/yannickcr/eslint-plugin-react#configuration 11 | "plugin:prettier/recommended" 12 | ], 13 | "plugins": [ 14 | "react-hooks" // https://www.npmjs.com/package/eslint-plugin-react-hooks 15 | ], 16 | "rules": { 17 | "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }], 18 | "react/display-name": 0, // Comes from eslint-plugin-react's default recommendation. 19 | "import/no-extraneous-dependencies": ["error", {"devDependencies": true}], 20 | "import/prefer-default-export": 0, 21 | "linebreak-style": ["error", (process.platform === "win32" ? "windows" : "unix")], 22 | "import/prefer-default-export": 0, 23 | "react/jsx-one-expression-per-line": 0, 24 | "react-hooks/rules-of-hooks": "error", 25 | "react-hooks/exhaustive-deps": "warn" 26 | } 27 | }; 28 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: push 4 | 5 | jobs: 6 | lint: 7 | name: Lint 8 | runs-on: ubuntu-latest 9 | steps: 10 | - name: Checkout 11 | uses: actions/checkout@v1 12 | - name: Use Node.js 12 13 | uses: actions/setup-node@v1 14 | with: 15 | node-version: 12.x 16 | - name: Cache JS dependencies 17 | uses: actions/cache@v1 18 | with: 19 | path: node_modules 20 | key: ${{ runner.OS }}-js-dependencies-${{ hashFiles('**/package-lock.json') }} 21 | restore-keys: | 22 | ${{ runner.OS }}-js-dependencies- 23 | - name: Install dependencies 24 | run: npm install 25 | - name: Lint 26 | run: npm run lint 27 | test: 28 | name: Test 29 | runs-on: ubuntu-latest 30 | steps: 31 | - name: Checkout 32 | uses: actions/checkout@v1 33 | - name: Use Node.js 12 34 | uses: actions/setup-node@v1 35 | with: 36 | node-version: 12.x 37 | - name: Cache JS dependencies 38 | uses: actions/cache@v1 39 | with: 40 | path: node_modules 41 | key: ${{ runner.OS }}-js-dependencies-${{ hashFiles('**/package-lock.json') }} 42 | restore-keys: | 43 | ${{ runner.OS }}-js-dependencies- 44 | - name: Install dependencies 45 | run: npm install 46 | - name: Test coverage 47 | run: npm run test:coverage 48 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # node_modules 2 | /node_modules 3 | 4 | # production 5 | /dist 6 | 7 | # jest coverage 8 | /coverage 9 | 10 | # environment variables 11 | /.env 12 | -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | trailingComma: "es5", 3 | } 4 | -------------------------------------------------------------------------------- /.vscode/extentions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "editorconfig.editorconfig", 4 | "esbenp.prettier-vscode", 5 | "dbaeumer.vscode-eslint" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.formatOnSave": false, 3 | "editor.codeActionsOnSave": { 4 | "source.fixAll.eslint": true 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | 3 | Copyright (c) 2019 Zsolt Gomori 4 | 5 | 6 | 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: 7 | 8 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 9 | 10 | 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. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RB 2 | 3 | ## Core features 4 | - ESlint 5 | - Jest & Enzyme 6 | - PropTypes 7 | - Pre-commit 8 | - Prettier 9 | - CSS loader & styled-components 10 | - Environment variables 11 | - Automated Heroku deployment flow 12 | 13 | ## How to use? 14 | 15 | Start off by cloning the project. 16 | 17 | ```bash 18 | git clone https://github.com/gomorizsolt/react-boilerplate.git 19 | ``` 20 | 21 | Install dependencies. 22 | 23 | ```bash 24 | npm install 25 | ``` 26 | 27 | Launch the development environment. :rocket: 28 | 29 | ```bash 30 | npm run dev 31 | ``` 32 | 33 | ## Contribution 34 | 35 | Contributors are welcome and also expected to adhere to the [**Contributor Covenant**](https://www.contributor-covenant.org/). 36 | 37 | ## License 38 | 39 | The project is under the MIT license. For more information read the [**LICENSE.md**](./LICENSE.md) file. 40 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | setupFiles: ["/src/scripts/SetupEnzyme.js"], 3 | moduleNameMapper: { 4 | ".+\\.(png|jpg|css|svg)$": "identity-obj-proxy", 5 | }, 6 | }; 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-boilerplate", 3 | "version": "1.0.2", 4 | "description": "RB is a customizable boilerplate for React projects.", 5 | "main": "index.js", 6 | "scripts": { 7 | "build": "webpack --mode production", 8 | "dev": "webpack-dev-server --open --mode development", 9 | "heroku-postbuild": "npm run build", 10 | "lint": "eslint src", 11 | "prettior": "prettier --write src/**/*.js", 12 | "start": "serve -s dist", 13 | "test": "jest", 14 | "test:coverage": "jest --coverage", 15 | "test:watch-all": "jest --watchAll" 16 | }, 17 | "repository": { 18 | "type": "git", 19 | "url": "git+https://github.com/gomorizsolt/react-boilerplate.git" 20 | }, 21 | "keywords": [ 22 | "react", 23 | "boilerplate", 24 | "react-boilerplate" 25 | ], 26 | "author": "Zsolt Gomori", 27 | "license": "MIT", 28 | "bugs": { 29 | "url": "https://github.com/gomorizsolt/react-boilerplate/issues" 30 | }, 31 | "homepage": "https://github.com/gomorizsolt/react-boilerplate#readme", 32 | "devDependencies": { 33 | "@babel/core": "^7.2.2", 34 | "@babel/plugin-syntax-dynamic-import": "^7.2.0", 35 | "@babel/polyfill": "^7.2.5", 36 | "@babel/preset-env": "^7.3.1", 37 | "@babel/preset-react": "^7.0.0", 38 | "babel-eslint": "^10.0.1", 39 | "babel-jest": "^24.1.0", 40 | "babel-loader": "^8.0.5", 41 | "css-loader": "^2.1.0", 42 | "dotenv-webpack": "^1.7.0", 43 | "enzyme": "^3.8.0", 44 | "enzyme-adapter-react-16": "^1.9.1", 45 | "enzyme-to-json": "^3.3.5", 46 | "eslint": "^5.13.0", 47 | "eslint-config-airbnb": "^17.1.0", 48 | "eslint-config-prettier": "^4.0.0", 49 | "eslint-import-resolver-babel-module": "^5.0.1", 50 | "eslint-plugin-import": "^2.16.0", 51 | "eslint-plugin-jsx-a11y": "^6.2.1", 52 | "eslint-plugin-prettier": "^3.0.1", 53 | "eslint-plugin-react": "^7.12.4", 54 | "eslint-plugin-react-hooks": "^1.5.0", 55 | "file-loader": "^3.0.1", 56 | "html-loader": "^0.5.5", 57 | "html-webpack-plugin": "^5.5.0", 58 | "identity-obj-proxy": "^3.0.0", 59 | "jest": "^24.1.0", 60 | "pre-commit": "^1.2.2", 61 | "prettier": "^1.16.4", 62 | "style-loader": "^0.23.1", 63 | "sw-precache-webpack-plugin": "^0.11.5", 64 | "webpack": "^4.29.3", 65 | "webpack-cli": "^3.2.3", 66 | "webpack-dev-server": "^3.1.14", 67 | "webpack-manifest-plugin": "^2.0.4" 68 | }, 69 | "dependencies": { 70 | "prop-types": "^15.7.2", 71 | "react": "^16.8.4", 72 | "react-dom": "^16.8.4", 73 | "serve": "^10.1.2", 74 | "styled-components": "^4.1.3" 75 | }, 76 | "pre-commit": [ 77 | "test", 78 | "lint" 79 | ] 80 | } 81 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | RB 9 | 10 | 11 |
12 | 13 | 14 | -------------------------------------------------------------------------------- /src/components/Foo/Foo.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import PropTypes from "prop-types"; 3 | 4 | const foo = ({ name }) =>

Hello {name}!

; 5 | 6 | foo.propTypes = { 7 | name: PropTypes.string.isRequired, 8 | }; 9 | 10 | export default foo; 11 | -------------------------------------------------------------------------------- /src/components/Foo/Foo.test.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { shallow } from "enzyme"; 3 | import Foo from "./Foo"; 4 | 5 | describe("", () => { 6 | let fooWrapper; 7 | 8 | const name = "__buzz__"; 9 | 10 | beforeEach(() => { 11 | fooWrapper = shallow(); 12 | }); 13 | 14 | it("renders

", () => { 15 | expect(fooWrapper.find("p")).toHaveLength(1); 16 | }); 17 | 18 | it("greets the user", () => { 19 | const expectedH1 = `Hello ${name}!`; 20 | 21 | expect(fooWrapper.find("p").text()).toEqual(expectedH1); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import ReactDOM from "react-dom"; 3 | import Foo from "./components/Foo/Foo"; 4 | import registerServiceWorker from "./registerServiceWorker"; 5 | 6 | ReactDOM.render(, document.getElementById("index")); 7 | 8 | registerServiceWorker(); 9 | -------------------------------------------------------------------------------- /src/registerServiceWorker.js: -------------------------------------------------------------------------------- 1 | export default function register() { 2 | if (process.env.NODE_ENV === "production" && "serviceWorker" in navigator) { 3 | window.addEventListener("load", () => { 4 | const swUrl = "service-worker.js"; 5 | navigator.serviceWorker 6 | .register(swUrl) 7 | .then(registration => { 8 | // eslint-disable-next-line no-param-reassign 9 | registration.onupdatefound = () => { 10 | const installingWorker = registration.installing; 11 | installingWorker.onstatechange = () => { 12 | if (installingWorker.state === "installed") { 13 | if (navigator.serviceWorker.controller) { 14 | // Add your custom reload icon so that inform your users about the new content. 15 | console.log("New content is available; please refresh."); 16 | } else { 17 | console.log("Content is cached for offline use."); 18 | } 19 | } 20 | }; 21 | }; 22 | }) 23 | .catch(error => { 24 | console.error("Error during service worker registration:", error); 25 | }); 26 | }); 27 | } 28 | } 29 | 30 | export function unregister() { 31 | if ("serviceWorker" in navigator) { 32 | navigator.serviceWorker.ready.then(registration => { 33 | registration.unregister(); 34 | }); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/scripts/SetupEnzyme.js: -------------------------------------------------------------------------------- 1 | import { configure } from "enzyme"; 2 | import Adapter from "enzyme-adapter-react-16"; 3 | import "@babel/polyfill"; 4 | 5 | configure({ adapter: new Adapter() }); 6 | -------------------------------------------------------------------------------- /src/utils/ShallowWrappedComponent/ShallowWrappedComponent.js: -------------------------------------------------------------------------------- 1 | import { shallow } from "enzyme"; 2 | 3 | const shallowWrappedComponent = wrappedComponent => 4 | shallow(shallow(wrappedComponent).get(0)); 5 | 6 | export default shallowWrappedComponent; 7 | -------------------------------------------------------------------------------- /src/utils/TestUtils/TestUtils.js: -------------------------------------------------------------------------------- 1 | export const mockOriginalFunctionality = name => { 2 | const actualModule = require.requireActual(name); 3 | 4 | return { 5 | ...Object.getOwnPropertyNames(actualModule) 6 | .map(functionName => ({ 7 | [functionName]: jest 8 | .fn() 9 | .mockImplementation((...args) => actualModule[functionName](...args)), 10 | })) 11 | .reduce((accumulator, currentValue) => ({ 12 | ...accumulator, 13 | ...currentValue, 14 | })), 15 | }; 16 | }; 17 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require("path"); 2 | const Dotenv = require("dotenv-webpack"); 3 | const HtmlWebPackPlugin = require("html-webpack-plugin"); 4 | const ManifestPlugin = require("webpack-manifest-plugin"); 5 | const SwPrecachePlugin = require("sw-precache-webpack-plugin"); 6 | 7 | const manifestPlugin = new ManifestPlugin({ 8 | fileName: "asset-manifest.json", 9 | }); 10 | 11 | const htmlWebpackPlugin = new HtmlWebPackPlugin({ 12 | template: "./public/index.html", 13 | filename: "./index.html", 14 | }); 15 | 16 | const swPrecachePlugin = new SwPrecachePlugin({ 17 | dontCacheBustUrlsMatching: /\.\w{8}\./, 18 | filename: "service-worker.js", 19 | logger(message) { 20 | if (message.indexOf("Total precache size is") === 0) { 21 | // eslint-disable-next-line no-useless-return 22 | return; 23 | } 24 | }, 25 | minify: true, 26 | navigateFallback: "/index.html", 27 | staticFileGlobsIgnorePatterns: [/\.map$/, /asset-manifest\.json$/], 28 | }); 29 | 30 | module.exports = { 31 | entry: ["@babel/polyfill", path.join(__dirname, "src/index.js")], 32 | devtool: "source-map", 33 | module: { 34 | rules: [ 35 | { 36 | test: /\.(js|jsx)$/, 37 | exclude: /node_modules/, 38 | use: { 39 | loader: "babel-loader", 40 | }, 41 | }, 42 | { 43 | test: /\.html$/, 44 | use: [ 45 | { 46 | loader: "html-loader", 47 | }, 48 | ], 49 | }, 50 | { 51 | test: /\.css$/, 52 | use: ["style-loader", "css-loader"], 53 | }, 54 | { 55 | test: /\.(png|jpg|gif|svg|ico)$/, 56 | use: [ 57 | { 58 | loader: "file-loader", 59 | options: { 60 | name: "[name].[ext]", 61 | }, 62 | }, 63 | ], 64 | }, 65 | ], 66 | }, 67 | plugins: [manifestPlugin, htmlWebpackPlugin, new Dotenv(), swPrecachePlugin], 68 | devServer: { 69 | port: 3001, 70 | }, 71 | }; 72 | --------------------------------------------------------------------------------