Teaching boilerplate for teachers that are learning how to program with React

Overview

React course: react4teachers-zero2hero

Teaching boilerplate for teachers that are learning how to program with React.

Course offered by Conselleria d'Educació de les Illes Balears. 2022

Training perform by Alberto Soto Fernandez

System requirements

To follow this guide, you'll need to set up the following tools:

  • nodejs/npm
  • yarn
  • and IDE of your choice (I am in ♡ love with Intellij and Jetbrains tools)
  • git client

Most of the build process will be performed with yarn, due to the workspaces feature. Feel free to use npm if you are confident with it.

Content : Stage 1 - Intro to vanillaJS

Starting the project

We will set up a project based on vanillaJs, using webpack 5 as a base to stablish our knowledge

To achieve it, perform the following steps:

# yarn init --private
# Option for all yes by default and private
yarn init -yp
yarn add webpack webpack-cli webpack-dev-server --dev
touch webpack.config.js
mkdir src
mkdir dist
touch src/index.js

Inside the webpack.config.js insert the following

const path = require('path');
module.exports = {
"mode": "none",
"entry": "./src/index.js",
"output": {
"path": __dirname + '/dist',
"filename": "bundle.js"
},
devServer: {
contentBase: path.join(__dirname, 'dist')
}
}

Inside src/index.js, Introduce a basic console.log('hi there')

Introducing tasks for webpack 5

Webpack will act as our transpiler, making everything ready to work in any browser, integrating into our bundle all the tools we define and letting you work with any pipeline.

There are other bundlers in the market, but webpack is ready to fit any enterprise solution.

Years ago we were using Gulp, Grunt, Bower...but those days are gone.

Current bundle creators are: Webpack, Parcel & Rollup.

You can't have it all, so each of them perform in some tasks. From my point of view, webpack is amazing to perform deep details, but it brings more complexity. Anyway feel free to use any of them.

More info about it https://betterprogramming.pub/the-battle-of-bundlers-6333a4e3eda9

A bundler performs, basically the following tasks:

  • Configure your project and your custom tasks
  • Eliminate old code or non used
  • Transpile the code to ecma5/ecma6 Check differences on https://kangax.github.io/compat-table/es6/
  • Split your code
  • Live reload & hot module replacement
  • Transform your modules

Current ECMA version is 10!

  • ECMA 5 > Dec 2009
  • ECMA 6 > June 2015

More info at https://www.c-sharpcorner.com/article/comparison-between-ecmascript-5-and-ecmascript-6-versions-of-javascript/#:~:text=While%20ECMAScript%205%20introduced%20lots,functionality%20to%20create%20typed%20arrays.

Exercise 1: my first js bundle

Let's configure the basic tasks Open your package.json and write the following

{
"name": "caib-react4teachers",
  "version": "1.0.0",
  "main": "index.js",
  "repository": "https://github.com/albertoSoto/react4teachers-zero2hero.git",
  "author": "Alberto Soto",
  "license": "MIT",
  "private": true,
  "devDependencies": {
  "webpack": "^5.68.0",
    "webpack-cli": "^4.9.2",
    "webpack-dev-server": "^4.7.3"
  },
  "scripts": {
  "build": "webpack",
    "dev-server": "webpack-dev-server"
  }
}

Let's generate our first bundle

Now that we have our project with some tasks we can start with it, open a terminal and do the following

yarn run build
#or
npm run build

This is executing the task you need, generating a basic js file, under /dist folder that will be compatible If you open the content you'll see the following

    /******/ (() => { // webpackBootstrap
    var __webpack_exports__ = {};
    console.log('hi there')
    /******/ })()
;

Nothing great still!

Exercise 2: css pipelines

Let's prepare the CSS part

npm install --save-dev css-loader style-loader node-sass sass-loader 
#or
yarn add --dev css-loader style-loader node-sass sass-loader

Modify your webpackconfig with the following:

  • css-loader will inject the css into our js
  • style-loader will load the generate file
const path = require('path');
module.exports = {
 "mode": "none",
 "entry": "./src/index.js",
 "output": {
   "path": __dirname + '/dist',
   "filename": "bundle.js"
 },
 devServer: {
   contentBase: path.join(__dirname, 'dist')
 },
 "module": {
   "rules": [
     {
       "test": /\.css$/,
       "use": [
         "style-loader",
         "css-loader"
       ]
     },
   ]
 }
};

touch src/css/main.css

This will let you load the css from the js into index.js

import './css/main.css';
console.log('hi there')

Now execute yarn build again and check you contents, differences start to appear!

Part II: Customize your build and introduce ECMA 6 features

From here we will prepare and generate some basic concepts on vanillaJS that will introduce basic concepts used by React

http://es6-features.org/#Constants

You might also like...

Jekyllist - Modern Boilerplate on Jekyll

Jekyllist - Modern Boilerplate on Jekyll Jekyllist is a production ready boilerplate for humans who wants to build simple websites (portfolio sites, b

Jul 21, 2022

Very minimalistic boilerplate to start most Typescript Express projects. Includes Mongodb connection via Mongoose with a sample post model.

Very minimalistic boilerplate to start most Typescript Express projects. Includes Mongodb connection via Mongoose with a sample post model.

Minimalist express-typescript-boilerplate Available Scripts - `tsc' - builds the tsc project to the dist folder - `build` - cleans the previous build

Dec 13, 2022

Express typescript boilerplate using @types/node, @types/express

Express framework boilerplate in typescript.

Sep 21, 2022

Vite Electron Builder Boilerplate

This is template for secure electron applications. Written following the latest safety requirements, recommendations and best practices.

Dec 15, 2022

Next Boilerplate with TypeScript, Redux Toolkit and Styled-Component.. For now

This is a Next.js project bootstrapped with create-next-app. Getting Started First, run the development server: npm run dev # or yarn dev Open http://

Feb 17, 2022

A boilerplate application for building Node.js back-end application in TypeScript

RESTful API Node Server Boilerplate A boilerplate/starter project for quickly building RESTful APIs and with typescript 🚀 Installation Install the de

Nov 23, 2022

Boilerplate for HTML, CSS, JS and TailwindCSS

tailwind-vanillajs-boilerplate 🔨 Boilerplate for HTML, CSS, JS and TailwindCSS

Aug 10, 2022

Next Boilerplate was created to be a template for starting NextJS projects with pre-configured settings like Linters, Test Setup, Storybook and Commit Hooks.

Next Boilerplate was created to be a template for starting NextJS projects with pre-configured settings like Linters, Test Setup, Storybook and Commit Hooks.

Next Boilerplate was created to be a template for starting NextJS projects with pre-configured settings like Linters, Test Setup, Storybook and Commit Hooks.

Feb 22, 2022

@code-collabo's node-mongo API boilerplate template (typescript)

@code-collabo's node-mongo API boilerplate template (typescript) This is the manual download option for the API boilerplate template generated by @cod

May 31, 2022
Owner
Alberto Soto
Alberto Soto
Solana Boilerplate - Lightweight boilerplate for Solana dapps. Allows quick building and prototyping.

Lightweight boilerplate for Solana dapps. Allows quick building and prototyping. Feel free to contribute or fork this repository. Make it yours! Leave us a ⭐️ if this repo helped you.

null 21 Nov 15, 2022
React Starter Kit — isomorphic web app boilerplate (Node.js, Express, GraphQL, React.js, Babel, PostCSS, Webpack, Browsersync)

React Starter Kit — "isomorphic" web app boilerplate React Starter Kit is an opinionated boilerplate for web development built on top of Node.js, Expr

Kriasoft 21.7k Jan 1, 2023
React + Redux starter kit / boilerplate with Babel, hot reloading, testing, linting and a working example app built in

A comprehensive starter kit for rapid application development using React. Why Slingshot? One command to get started - Type npm start to start develop

Cory House 9.8k Jan 3, 2023
An upgradable boilerplate for Progressive web applications (PWA) with server side rendering, build with SEO in mind and achieving max page speed and optimized user experience.

React PWA v2 A highly scalable, Progressive Web Application foundation,boilerplate, with the best Developer Experience. Demo: https://demo.reactpwa.co

Atyantik 2.5k Dec 26, 2022
A boilerplate for Node.js web applications

Hackathon Starter Live Demo: https://hackathon-starter.walcony.com Jump to What's new? A boilerplate for Node.js web applications. If you have attende

Sahat Yalkabov 34k Dec 28, 2022
DDD/Clean Architecture inspired boilerplate for Node web APIs

Node API boilerplate An opinionated boilerplate for Node web APIs focused on separation of concerns and scalability. Features Multilayer folder struct

Talysson de Oliveira Cassiano 3k Dec 30, 2022
A boilerplate for building production-ready RESTful APIs using Node.js, Express, and Mongoose

By running a single command, you will get a production-ready Node.js app installed and fully configured on your machine. The app comes with many built-in features, such as authentication using JWT, request validation, unit and integration tests, continuous integration, docker support, API documentation, pagination, etc. For more details, check the features list below.

Hagop Jamkojian 5k Dec 31, 2022
A MERN boilerplate repository with RBAC feature, following all production best practices.

Welcome to the RBAC MERN Boilerplate project A MERN boilerplate repository with RBAC feature, following all production best practices. In this reposit

Foyzul Karim 268 Dec 27, 2022
NextJS, TypeScript and Styled Components project boilerplate

This is a Next.js project bootstrapped with create-next-app. Getting Started First, run the development server: npm run dev # or yarn dev Open http://

Mateus 2 Sep 21, 2021
A boilerplate to kick off any Gatsby project.

A boilerplate to kick off any Gatsby project. This starter ships with: - Gatsby v4 - Material UI v5 with light/dark mode and a custom theme - Emotion JS (with access to Material UI custom theme) - React redux (with reduxjs/toolkit) - React intl for multilingual support - React helmet for SEO

Mario Duarte 1 Jul 6, 2022