Giter Club home page Giter Club logo

r3f-pack's Introduction

npm npm

R3F-Pack

A simplified and maintained react-scripts alternative.

R3F-Pack Logo

react-scripts is deprecated, but it was good while it lasted.

It now has many out of date dependencies and working with it sometimes requires quite a few manual band-aids.

So I created this R3F-Pack. I wrote it for my R3F examples, and it may work with your existing React code also.

Video Tutorial

R3F-Pack replacement for React-Scripts

About

R3F-Pack runs very similar to how react-scripts works, and your project structure remains the same.

  • It serves the dev version on port 3000
  • It auto opens the browser at address http://localhost:3000
  • It enables Hot Module Reloading (HMR) with fast refresh
  • It serves the development version from the ./public folder
  • npm run build builds a production quality version of your app, and will copy all static files & folders under ./public to the ./build folder ready for deployment
  • Production bundle.js contains a hash in its name to prevent caching
  • It supports building with TypeScript
  • It indicates 0 vulnerabilities when running npm install, at the time of writing this message

Zero vulnerabilities

Starting a new Project

To start a brand-new React project, run

npx new-cra@latest my-app

Or, to also include TypeScript

npx new-cra@latest my-app -ts

This will create a very basic React application named my-app that you can start developing from.

After the installation has finished,

cd my-app
npm start

Visit http://127.0.0.1:3000

You don't have to create an app named my-app, you could name it anything.

npx new-cra anything
cd anything
npm start

Name it anything you like.

Installing R3F-pack for Existing React Projects

If you already have an existing app that currently uses react-scripts, and you want to convert it to use R3F-pack, then use these steps below.

First uninstall react-scripts

npm uninstall react-scripts

Next, install r3f-pack

npm install r3f-pack --save-dev

And then replace the start and build commands in your existing scripts node in your projects package.json

{
    ...
    "scripts": {
-       "start": "react-scripts start",
+       "start": "r3f-pack start",
-       "build": "react-scripts build",
+       "build": "r3f-pack build"
    },
    ...
}

Development

To start in development mode,

npm start

Visit http://127.0.0.1:3000

Production

To build production

npm run build

A production quality bundle.js will be compiled and all static files and folders under ./public will be copied to the ./build folder ready for deployment.

Upload or deploy the contents of the ./build folder to the location served by your web server.

To test your production build locally you can use http-server

Install it if you don't already have it.

npm install --global http-server

Start it

http-server .\build\

or if using PowerShell

http-server.cmd .\build\

Visit http://127.0.0.1:8080

Boilerplate

I have many boilerplate branches that use R3F-pack by default. You can have a ready-made project to begin from by following these commands instead.

git clone https://github.com/Sean-Bradley/React-Three-Fiber-Boilerplate.git
cd React-Three-Fiber-Boilerplate
npm install
npm start

There are over 60 branches in the React-Three-Fiber-Boilerplate repository.

You may decide you want something more sophisticated to begin from, for example, you could switch to the componentize branch.

git checkout componentize
npm install
npm start

Troubleshooting

This is quite a minimal project, and only mimics the basic functionality of react-scripts. If it is missing something that you need, I may be able to add it, or if you know how to do it yourself, then you can make a pull request.

babel-loader doesn't exist

r3f-pack and react-scripts share some dependencies. However, you can uninstall react-scripts before you install r3f-pack if you want to keep your code and dependencies neater.

If you uninstall react-scripts after you've installed r3f-pack, then you will have also uninstalled some dependencies also required of r3f-pack

So, you will need to clean up your ./node_modules folder.

First uninstall react-scripts

npm uninstall react-scripts

Next, also uninstall r3f-pack just to be sure you got everything.

npm uninstall react-scripts

Then re-install r3f-pack

npm install r3f-pack --save-dev

Now start development.

npm start

Your browser should auto open to http://127.0.0.1:3000

Sponsoring

If you would like me to update your react-scripts/CRA project to use R3F-Pack, then consider sponsoring and notify me of your repository so I can make a pull request.

r3f-pack's People

Contributors

dafrok avatar dependabot[bot] avatar sean-bradley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

dafrok

r3f-pack's Issues

"You may need an appropriate loader to handle this file type" -errors after switching from react-scripts

Hi!

Thanks for making this alternative to react-scripts! ๐Ÿ˜„

I have several errors in regards to .svg and .jpg files after switching:

You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file.

My webpack.config.js file has rules for both .svg and .jpg files, and using either url-loader or file-loader results in the same error.

Is this an issue related to switching from react-scripts or something else?

HotModuleReload + fast refresh is too hasty. any existing way to temporarily turn off fast refresh?

Hello!
R3-F pack was an great upgrade from react-scripts and everything works flawlessly. But one change after upgrading to R3f pack is that the hot reload is triggered a way higher number of times. I mean forget waiting till a save, it starts throwing errors the moment i start writing a line of code and keeps refreshing with every keystroke. As you can imagine, it is a detriment to development flow.

I'm not sure if this is the intented effect and the desired behavior- or -if any of the other extensions i am using in VSCode might be contributing to it, but I humbly seek advice in disabling and enabling the fast refresh feature.

Ideally, I would like the hotModuleReload to trigger once the file is saved. I am not familiar enough with webpack configurations and do not wish to break what is already working.

Please advice. I appreciate your consideration.

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.