8

I'm a newbie with React, I have made a few apps using the create-react-app to help get me started(as followed by numerous tutorials). I heard that I now need to know how to create a react app from scratch without using the create-react-app boilerplate maker.

I know that i have to add a few sections such as:

  • React
  • React-dom
  • Webpack
  • Babel

here are the list of dependencies in my package.json file

"dependencies": {
    "prop-types": "^15.6.1",
    "react": "^16.4.0",
    "react-dom": "^16.4.0"
  },
  "devDependencies": {
    "babel": "^6.23.0",
    "babel-loader": "^7.1.4",
    "babel-preset-env": "^1.7.0",
    "babel-preset-react": "^6.24.1",
    "babel-preset-stage-0": "^6.24.1",
    "html-webpack-plugin": "^3.2.0",
    "webpack": "^3.8.3",
    "webpack-dev-server": "^3.1.4"
  }
}

webpack.config.js

var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
    devtool: 'cheap-module-eval-source-map',
    entry: {
        app:'./src/index',
    },
    output: {
        path: path.join(__dirname, 'dist'),
        filename: 'bundle.js',
        publicPath: '/static/'
    },
    plugins: [
        new HtmlWebpackPlugin(['app'])
    ],
    module: {
        loaders: [{
            test:/\.js/ + /\.jsx?$/, 
            loader: 'babel-loader',
            include: path.join(__dirname, 'src'),
        }]
    }
}

My .babelrc file

{
    "presents":["env","react"]
}

I've followed a few tutorials on how to make a React app from scratch, but with no success. I have a feeling that my Webpack config is not correct.

Unfortunately I am still unable to run this project

Git link to repo: https://github.com/tony2tones/scratch-react/tree/master

tony2tones
  • 1,422
  • 1
  • 18
  • 19
  • which version of webpack are you using? – PlayMa256 May 28 '18 at 12:30
  • 4.9.1. Although i was recommended to use version 3, not too sure if this has added to my problem – tony2tones May 28 '18 at 13:23
  • "I heard that I now need to know how to create a react app from scratch without using the create-react-app boilerplate maker" - where did you hear that? There's nothing wrong with using create-react-app for "serious" website building. – Patrick Hund Dec 26 '18 at 09:54
  • Check this tutorial for React v17 setup without create-react-app: https://frontendguruji.com/blog/how-to-setup-a-react-js-project-from-scratch-without-create-react-app/ – Mandeep Pasbola Jan 02 '22 at 08:33

3 Answers3

3

As mentioned earlier, you need an

index.js

and inside of it you will need to at least have: import React from 'react';

import ReactDOM from 'react-dom';

and

`ReactDOM.render(whatever you want to render, wherever you want to render(preferably document.getElementById('root')))

This shows what the app should render when it gets a request

Hope this will help. it's my first answer :)

Laz
  • 31
  • 8
0

Seems like you are missing a few things.

  1. To build your project, you can call npm run build.
  2. You need to add a index.html file to be rendered in browser.
  3. You need to add start in your script object inside package.json and do npm install again.

For 3, you can add, "start": "webpack-dev-server" Then to run you node server, you can do it by npm run start

Hope this helps.

Mahipal
  • 344
  • 2
  • 13
-1

Bascially Create-react-app abstract the setup of babel and webpack. If you want to setup those things directly and understand what is what. I recommend going through this blog

P-Srt
  • 31
  • 6