[under optimization] [working fine]
A purist style approach to make a react app from stretch (without creacte-react-app) based on webpack. This way create an auto-updated complete react app from 0 to 100.
Open your terminal in a folder and...
-
init a nodejs project...
npm init (or npm init -y)
-
install react (this version is not ssr)...
npm i --save react react-dom
-
install babel (for jsx and compiling)...
npm i --save-dev @babel/preset-react
-
install babel add-on (for get resurces)...
npm i --save-dev babel-loader file-loader style-loader css-loader
-
in root make .babelrc file with:
{ "presets": [[ "@babel/preset-react", { "runtime" : "automatic"}]] }
or global profiling with babel.config.json (not raccomended)
{ "presets": ["@babel/preset-react"], "env": { "development": { "presets": [["@babel/preset-react", { "development": true }]] } }
nodejs best and simple way. Insert into package.json:
"babel":{ "presets": [ [ "@babel/preset-react", { "runtime" : "automatic"}] ] },
install webpack (for editing and build it)
npm i --save-dev webpack webpack-cli html-webpack-plugin
in root make webpack.config.js confing file:
const HtmlPack = require('html-webpack-plugin') const HtmlList = [ "index", "test/secondpage" ] module.exports = { //https://stackoverflow.com/questions/70916332/webpack-bundle-files-for-multiple-pages // entry: { main: [ "./src/index.js", ], test: [ "./src/test/secondpage.js", ], }, entry: HtmlList.reduce( (config, page) => { config[page] = `./src/${page}.js`; return config; },{}), output: { path: __dirname+'/public/reactor', filename: '[name].bundle.js', clean: true }, devServer: { static: __dirname+'/src', port: 8080, open: true, hot: true }, module: { rules: [ { test: /\.js$/i, exclude: /node_modules/, use: [ 'babel-loader' ] }, { test: /\.css$/i, exclude: /node_modules/, use: [ 'style-loader', 'css-loader' ] }, { test: /\.(jpe?g|png|gif|webp|svg|ico|zip|json)$/i, exclude: /node_modules/, loader: 'file-loader', options: { name: '[path][name].[ext]' } } ] }, plugins : [].concat( // https://dev.to/marcinwosinek/tutorial-for-building-multipage-website-with-webpack-4gdk // https://github.com/jantimon/html-webpack-plugin HtmlList.map( page => new HtmlPack({ filename: `${page}.html`, })), ) }
server:
-
if not have express:
-
install a server
npm i --save-dev http-server
and/ornpm i --save-dev webpack-dev-server
-
open package.json and change
"scripts": {...},
with:"scripts": { "start": "start http://localhost:8080/ && npm run server", "server": "http-server -a localhost -p 8080 -c-1", "edit": "webpack serve --mode development", "build": "webpack --mode production" }
test server:
nb: for view result in server you need to compile app with last step
with:npm run start
for test build in public
with:npm run serve
for edit in srcif you use express:
coming soon...
- make a first index:
- react dir:
mkdir src
- make index.js
echo '' > src/index.js
copy index file content (we suggest see the simple exemple in "src"):
//: //: Main of react app project //: // get react import React from 'react' import ReactDOM from 'react-dom/client' //make app root const root = ReactDOM.createRoot(document.getElementsByTagName('div')[0]) //render app root.render( <React.StrictMode> <h1>HELLO FROM REACT!</h1> </React.StrictMode> )
npm run build
for make "public" folder and optimized app (ready to online server use)
react-base-app-nodejs-fullcli-webpack's People
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
- react dir:
-