Giter VIP home page Giter VIP logo

my-react-app-starter's Introduction

my-react-app-starter

Build Status Demo

create-react-app is a great toolkit. It removes a lot of boilerplate to manage. Though, a few features are not shipped by default because each developer has different needs.

If you tend to use the same kind of configuration / devDependencies accross all of your create-react-app based projects, there isn't a perfect solution. This project is an attempt to fix this problem and share it with you.

What's in it ?

I added the specific configuration / devDependencies I tend to use on my projects, such as:

  • 9c0fa1b eslint with advanced rules such as config-airbnb + prettier with precommit hook
  • b2a4026 local test server
  • 74d81b2 setup build metadatas in index.html
  • 62fbc3a generate-changelog npm run task
  • f69bb96 setup default .travis.yml
  • 0f2c3d6 add deploy task

Each feature added can be identified by its commit, if you want to repeat only one of the steps on your own project.

This configuration has been inspired by topheman/npm-registry-browser, a project where I use all of the above (and more).

This remains an un-ejected create-react-app project, which means that you can:

  • update react-scripts
  • customize or remove any of the features added

The original CRA guidelines are still available here

Prerequisites

  • Nodejs v8
  • npm v5

Install

git clone https://github.com/topheman/my-react-app-starter.git
cd my-react-app-starter
npm install

Run

npm start

Build

npm run build

Will build a production version of the website in the build folder.

Serve

Once you've built you're app, you can test the build on a local server with:

npm run serve

Test

The following command will run all your tests in a single run mode.

npm test

Unit

  • npm run test:unit : single run of the unit tests
  • npm run test:unit:watch : run the unit tests in watch mode

End to end

No end to end test configured yet.

Linter

I use eslint to check the coding style, with the following presets:

The following command will run the linter on your code base. This task is ran at pre-commit to ensure code quality.

npm run lint

Prettier

Prettier is a great tool that enforces a consistent style accross your code base (usefull when working in teams).

Here is how to integrate it with your editor.

Once it's done, when you'll save a file, it will reformat it.

The following command will let you format your code base. This task is ran at pre-commit.

npm run pretty

Commit guidelines

To have uniform commit messages, I follow the AngularJS git commit guidelines, please take a look at it. I helps generate changelogs:

npm run generate-changelog -- v1.1.0 v1.2.0

Continuous Integration (CI)

This part is optional. A .travis.yml file is ready to use.

Each git push triggers a test suite on travis. The following will be ran:

  • linting
  • unit tests

One of the following npm task will take care of the testing according of the commit:

  • For PRs: npm run test:travis:pr Travis CI doesn't share env vars on PR builds (this is so that your build would not fail if you were using those vars)
  • For other types of commits: npm run test:travis

Deploy

You can use github-pages to host your project. All you need to do is to push your build on a gh-pages orphan branch, your project will be accessible at https://<owner>.github.io/<repo>.

This task can be automated using the gh-pages package, as specified in the CRA Readme. This task is already setup. All you have to do is:

npm run deploy

The demo of this website is hosted at topheman.github.io/my-react-app-starter.

my-react-app-starter's People

Contributors

topheman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

my-react-app-starter's Issues

should I add a deploy to github pages npm task ?

Pros:

  • Lots of people use it
  • It can expose how the build folder contains the artefacts generated from the build step (not tracked in master which only tracks the sources)

Cons:

  • Might be too opiniated ? (there are other hosting service such as surge / now ... though it would make an example - at the end, the deploy task would work the same way)

Add ๐Ÿ‘ or ๐Ÿ‘Ž (with comments if you may) to vote for the feature.

The implementation would be like https://github.com/topheman/npm-registry-browser#deploy

Update eslint-config-airbnb from v16 to v17

updating eslint-config-airbnb from v16 to v17 outputs the following message

npm WARN [email protected] requires a peer of ajv@^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of eslint@^4.19.1 || ^5.3.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of eslint-plugin-import@^2.14.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of eslint-plugin-jsx-a11y@^6.1.1 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of eslint-plugin-react@^7.11.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of eslint@^4.19.1 || ^5.3.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of eslint-plugin-import@^2.14.0 but none is installed. You must install peer dependencies yourself.

The reason is that eslint-config-airbnb relies on a bunch of modules that are also installed by react-scripts. In the previous version those modules were in the correct version range.

If we follow the instruction and install peer-dependencies:

npm install --save-dev eslint-config-airbnb@^17.1.0 ajv@^6.0.0 eslint@^5.3.0 eslint-plugin-import@^2.14.0 eslint-plugin-jsx-a11y@^6.1.1 eslint-plugin-react@^7.11.0

We end up with an other warning:

npm WARN [email protected] requires a peer of eslint@^4.1.1 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of eslint-plugin-jsx-a11y@^5.1.1 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of eslint@>=1.6.0 <5.0.0 but none is installed. You must install peer dependencies yourself.

This warning is about react-scripts dependencies which now have trouble with their peer dependencies because the previous install has done some deduplication of modules.

Action to take

  • find out if dedupe can be avoided ?

Infos

npm --version
6.1.0
node --version
v8.9.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.