21

I'm in a big trouble. Working in a part time in a company they're looking for a new web technology to build "web-component" in their website.

They have started to use AngularJS (first version) and I told them that, with the recent evolution of this framework, it's not the right period of time to deal with it.

That's why I began to be interested in ReactJS. However, they don't have a node.js server infrastructure (and that's why AngularJS suits to them, only one browser is sufficient) so it's impossible to run it with something like "npm start".

SO ! My question is (as my post's title says...) :

Is it possible to run ReactJS without server side ?

I've tried with the following line in my header

<script src="https://unpkg.com/react@15/dist/react.js"></script> <script src="https://unpkg.com/react-dom@15/dist/react-dom.js"></script>

But it remains a blank page.

Maybe there is something I don't understant in the react structure and that's why I'm looking for some help/explanations from you.

I hope I have been clear enough ! Thank you in advance for answer.

Bram'in
  • 618
  • 1
  • 7
  • 18
  • which server are they using? – Shankar Shastri Feb 16 '17 at 16:15
  • It depends. For big application in production they have Websphere server technology. But for now, they want me to prove that "ReactJS deserves to buy new infrastructure". That's why it will be cool to run ReactJS on browser or PHP server. Is it possible ? – Bram'in Feb 16 '17 at 16:21
  • 1
    Instead you can make use of webpack in npm which now the most of industry is following – Shankar Shastri Feb 16 '17 at 16:24

4 Answers4

20

It is absolutely possible to run a React app without a production node server. Facebook provides an easy-to-use project bootstrapper that you can read about here

That being said, developers may need to use a node dev server locally via npm start, as well as using node to perform production builds via npm run build. But one can take the build output from npm run build and serve it from any static server and have a working react application.

CaptEmulation
  • 4,416
  • 2
  • 17
  • 14
  • Can you please shed some light on why it is impossible? [As far as I know](https://stackoverflow.com/questions/59025093/how-to-export-react-app-to-pure-static-html) react apps can be baked into static HTML, CSS, and Javascript that can be served from a static site host such as GitHub Pages. – Quazi Irfan Oct 16 '22 at 01:04
  • @QuaziIrfan orry I don't understand. What are are saying is impossible? I agree with your statement that react apps can be served statically. However for local development it is usually faster to use a hotreload server like webpack dev server. Next.JS is another option as well that has come on the market more recently. – CaptEmulation Oct 17 '22 at 02:26
1

For those who are getting 404's after deploying in a sub directory. Make sure to add the path in package.json as homepage.

"homepage": "https://example.com/SUB-DIRECTORY",
Hamza Waleed
  • 1,334
  • 10
  • 12
1

You should insert "homepage": "./" into your package.json file, then use building react-script command like npm run build.

Haitham6373
  • 1,139
  • 8
  • 10
-1

I did it by using serve, as part of the build step in Jenkins. To install it, execute the command:

npm install -g serve

Then, to serve it:

serve -s build

Please, refer to project page for more information: https://github.com/zeit/serve