|
| 1 | +# c4-barefoot-frontend |
| 2 | + |
| 3 | + |
| 4 | +[](https://codeclimate.com/github/atlp-rwanda/c4-barefoot-frontend/maintainability) |
| 5 | +[](https://coveralls.io/github/atlp-rwanda/c4-barefoot-frontend?branch=develop) |
| 6 | + |
| 7 | +## Setting react project from scratch |
| 8 | + |
| 9 | +- First of all you need to clone project reposotory by running |
| 10 | + `git clone git clone https://github.com/atlp-rwanda/c4-barefoot-frontend.git` |
| 11 | + |
| 12 | +## Initializing node module packages |
| 13 | + |
| 14 | +- run `npm init --yes` here package.json will be created imadiately |
| 15 | + |
| 16 | +## Installation dependencies |
| 17 | + |
| 18 | + Here we need to install all packgages that will be used to set up our project |
| 19 | + |
| 20 | +- `npm install react` |
| 21 | +- `npm i react-dom` |
| 22 | +- `npm i react-roouter-dom` |
| 23 | + |
| 24 | +## Transipiling babel |
| 25 | + |
| 26 | + We need compile our javascript file from ECMA2015 (ES6) to ES5 |
| 27 | + |
| 28 | +- `@babel/core` |
| 29 | +- `@babel/preset-env` |
| 30 | +- `@babel/preset-react` |
| 31 | +- `babel-loader` |
| 32 | +- `babel/core` |
| 33 | + |
| 34 | +## Installing plugins that will allow react to unstander html files |
| 35 | + |
| 36 | +- `npm i html-webpack-plugin` |
| 37 | +- `npm i htm-loader` |
| 38 | + |
| 39 | +## In our project we need to style the pages we need to install this dependencies |
| 40 | + |
| 41 | +- `npm i css-loader` |
| 42 | +- `npm i style-loader` |
| 43 | + |
| 44 | +After that we will need to run our project in devlopment |
| 45 | +we have to make sure that webpack dependencies are installed like: |
| 46 | + |
| 47 | +- `npm i webpack-cli` Note: here you have to pay more attation on version of webpack-cli I am using version: `3.3.12` other version is not working |
| 48 | +- `npm i webpack` |
| 49 | +- `npm i webpack-dev-server` This will helps us to run server automatically after save when you change any file content |
| 50 | + |
| 51 | +## After that we need to tell webpack what to do |
| 52 | + |
| 53 | +```const webpack = require('webpack'); |
| 54 | +const path = require('path'); |
| 55 | +const HtmlWebpackPlugin = require('html-webpack-plugin') |
| 56 | +process.env.NODE_ENV = 'development'; |
| 57 | +
|
| 58 | +module.exports = { |
| 59 | + mode: 'development', |
| 60 | + devtool: 'cheap-module-source-map', |
| 61 | + entry: './src/index.js', |
| 62 | + output: { |
| 63 | + path: path.resolve(__dirname, "build"), |
| 64 | + publicPath: '/', |
| 65 | + filename: 'bundle.js' |
| 66 | + }, |
| 67 | + devServer: { |
| 68 | + stats:'minimal', |
| 69 | + overlay: true, |
| 70 | + historyApiFallback: true, |
| 71 | + disableHostCheck: true, |
| 72 | + headers: { "Access-Control-Allow-Origin": "*"}, |
| 73 | + https: false |
| 74 | + }, |
| 75 | +
|
| 76 | + plugins: [ |
| 77 | + new HtmlWebpackPlugin({ |
| 78 | + template: "public/index.html" |
| 79 | + }) |
| 80 | + ], |
| 81 | + module : { |
| 82 | + rules: [ |
| 83 | + { |
| 84 | + test: /\.(js|jsx)$/, |
| 85 | + exclude: /node_modules/, |
| 86 | + use: ["babel-loader"] |
| 87 | + }, |
| 88 | + { |
| 89 | + test: /(\.css)$/, |
| 90 | + use: ["style-loader", "css-loader"] |
| 91 | + }, |
| 92 | + { |
| 93 | + test: /\.html$/, |
| 94 | + use: [ |
| 95 | + { |
| 96 | + loader: "html-loader" |
| 97 | + } |
| 98 | + ] |
| 99 | + } |
| 100 | + ] |
| 101 | + } |
| 102 | +}; |
| 103 | +``` |
| 104 | + |
| 105 | +### Here we go now we can start our project by running `npm start` |
| 106 | + |
| 107 | +you will get error that says `no start script available` now you can guess what do right now |
| 108 | + |
| 109 | +let jump into package.json and configure `start script` |
| 110 | + |
| 111 | +```"scripts": { |
| 112 | + "start": "webpack-dev-server --config webpack.config.js --port 3000 --open" |
| 113 | + } |
| 114 | +``` |
| 115 | + |
| 116 | +so far you can run `npm start` |
0 commit comments