0

Webpack how to build production code and how to use it

  • Above question came very near to answering this. But I am stressing on the second part.
  • I am new to Nodejs let alone Webpack. I tried this tutorial https://blog.risingstack.com/using-react-with-webpack-tutorial/ Which really threw light into many aspects of Webpack.
  • But, what I want is a build which can run "on its own", that is, without node modules and other unnecessary files.

  • I tried Webpack -p with production configuration and that runs fine and creates a dist directory. And I thought that directory was what I was looking for. But I can't find a way to run it.

  • What am I missing ?

EDIT:

  • I tried to run means i tried to open the index.html
  • I looked at the browser console now and its showing file not found for both my JS file and CSS file.

  • I will provide a screenshot of the console output. My dist directory contains four files index.html, main-d9103c44e6f452183f46.min.css, main-d9103c44e6f452183f46.min.js, webpack.stats.json.

  • As I mentioned above, pretty much a noob. If you tell me what information I should provide, I'll be happy to provide that. Thank you.

enter image description here

Community
  • 1
  • 1
Pavanan M S
  • 157
  • 1
  • 2
  • 13
  • Are you trying to run this on the server with node? or on a client's browser? Webpack is usually used to generate files that are served to browsers. – rossipedia Jun 30 '16 at 14:56
  • I ran the app in a virtualbox successfully using npm start. Then I made a production build and tried to run the files in dist folder separately using a browser in my local. And it didn't work. – Pavanan M S Jun 30 '16 at 15:09
  • Gonna need a lot more info. What error messages are you getting? What _exactly_ did you do when you say you "tried to run" it? More detail is always helpful. – rossipedia Jun 30 '16 at 15:15
  • 1
    `dist` should contain everything you need run the application, including an `index.html` file that contains a relative path to your bundle.js that was generated. Now that we have index.html and bundle.js, that's all we need. Take a peek here: https://github.com/mikechabot/react-boilerplate – lux Jun 30 '16 at 19:12
  • The react boilerplate is working as expected – Pavanan M S Jul 01 '16 at 06:28

0 Answers0