{"id":110,"date":"2019-09-25T07:18:52","date_gmt":"2019-09-25T07:18:52","guid":{"rendered":"https:\/\/docs.theironnetwork.org\/reactify\/?page_id=110"},"modified":"2019-10-10T07:27:33","modified_gmt":"2019-10-10T07:27:33","slug":"deployment","status":"publish","type":"page","link":"https:\/\/docs.theironnetwork.org\/reactify\/deployment\/","title":{"rendered":"Deployment"},"content":{"rendered":"\n<p>To create a production build you need to run the command <code>npm run build<\/code>. It will create the <code>dist<\/code> folder, that contains the production build files. Now you just need to upload the <code>dist<\/code> files on to the server.<\/p>\n\n\n\n<h5 id=\"static-server\">Static Server:<a href=\"#static-server\"><\/a><\/h5>\n\n\n\n<p>For environments using <a href=\"https:\/\/nodejs.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">Node<\/a>, the easiest way to handle this would be to install <a href=\"https:\/\/github.com\/zeit\/serve\" target=\"_blank\" rel=\"noreferrer noopener\">serve<\/a> and let it handle the rest:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">npm install -g serve<br>serve -s build<\/pre>\n\n\n\n<h5 id=\"other-solutions\">Other Solutions:<a href=\"#other-solutions\"><\/a><\/h5>\n\n\n\n<p>You don\u2019t necessarily need a static server in order to run a project in production. It works just as fine integrated into an existing dynamic one.<\/p>\n\n\n\n<p>Here\u2019s a programmatic example using <a rel=\"noreferrer noopener\" href=\"https:\/\/nodejs.org\/\" target=\"_blank\">Node<\/a> and <a rel=\"noreferrer noopener\" href=\"http:\/\/expressjs.com\/\" target=\"_blank\">Express<\/a>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">const express = require('express');<br>const path = require('path');<br>const app = express();<br>app.use(express.static(path.join(__dirname, 'build')));<br>app.get('\/', function (req, res) {<br>   res.sendFile(path.join(__dirname, 'build', 'index.html'));<br>});<br>app.listen(9000);<\/pre>\n\n\n\n<h5>Apache HTTP server:<\/h5>\n\n\n\n<p>If you\u2019re using <a href=\"https:\/\/httpd.apache.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">Apache HTTP Server<\/a>, you need to create a <code>.htaccess<\/code> file in the <code>public<\/code> folder that looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Options -MultiViews<br>RewriteEngine On<br>RewriteCond %{REQUEST_FILENAME} !-f<br>RewriteRule ^ index.html [QSA,L] <\/pre>\n\n\n\n<p>Upload the <code>dist<\/code> files in the public folder.<\/p>\n\n\n\n<h5 id=\"building-for-relative-paths\">Building for Relative Paths:<a href=\"#building-for-relative-paths\"><\/a><\/h5>\n\n\n\n<p>If you want to make your production build in different folder or sub directory. Like, if you want that the template run on the <code>test.com\/dist<\/code> rather then <code>test.com<\/code> then you need to follow the steps given below:<\/p>\n\n\n\n<p><strong>Step 1:<\/strong> Open <code>.webpack.config.js<\/code> file and search for<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">const publicPath = '\/';<\/pre>\n\n\n\n<p>and set your path as per requirement like:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">const publicPath = '\/dist\/';<\/pre>\n\n\n\n<p><strong>Step 2:<\/strong> Now go to <code>src&gt;App.js<\/code> file and set the <code>Router basename<\/code> to <code>dist<\/code> like following code:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> <br>&lt;Router basename={'\/dist'}&gt;<br>            &lt;Switch&gt;<br>               &lt;Route path=\"\/\" component={App} \/&gt;<br>            &lt;\/Switch&gt;<br>         &lt;\/Router&gt;  <\/pre>\n\n\n\n<p><strong>Step 3:<\/strong> Open <code>.htaccess<\/code> file and set the roots for subdirectory: We have added the screenshot for the <code>.htaccess<\/code> file location and also the code of the file.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" width=\"461\" height=\"228\" src=\"https:\/\/docs.theironnetwork.org\/reactify\/wp-content\/uploads\/sites\/4\/2019\/09\/htaccess.png\" alt=\"\" class=\"wp-image-37\" srcset=\"https:\/\/docs.theironnetwork.org\/reactify\/wp-content\/uploads\/sites\/4\/2019\/09\/htaccess.png 461w, https:\/\/docs.theironnetwork.org\/reactify\/wp-content\/uploads\/sites\/4\/2019\/09\/htaccess-300x148.png 300w\" sizes=\"(max-width: 461px) 100vw, 461px\" \/><figcaption>.htaccess File<\/figcaption><\/figure><\/div>\n\n\n\n<pre class=\"wp-block-preformatted\"># To be inside the \/Directory<br> <br>&lt;IfModule mod_rewrite.c&gt;<br>    RewriteEngine On<br>    RewriteBase \/dist\/<br>    RewriteRule ^index\\.html$ - [L]<br>    RewriteCond %{REQUEST_FILENAME} !-f<br>    RewriteCond %{REQUEST_FILENAME} !-d<br>    RewriteRule . \/dist\/index.html [L]<br>&lt;\/IfModule&gt; <\/pre>\n<div class=\"pld-like-dislike-wrap pld-template-1\">\n    <div class=\"pld-like-wrap  pld-common-wrap\">\n    <a href=\"javascript:void(0);\" class=\"pld-like-trigger pld-like-dislike-trigger \" title=\"\" data-post-id=\"110\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-ip-check=\"0\" data-user-check=\"1\">\n                        <i class=\"fas fa-thumbs-up\"><\/i>\n                    <\/a>\n    <span class=\"pld-like-count-wrap pld-count-wrap\">2    <\/span>\n<\/div><div class=\"pld-dislike-wrap  pld-common-wrap\">\n    <a href=\"javascript:void(0);\" class=\"pld-dislike-trigger pld-like-dislike-trigger \" title=\"\" data-post-id=\"110\" data-trigger-type=\"dislike\" data-ip-check=\"0\" data-restriction=\"cookie\" data-user-check=\"1\">\n                        <i class=\"fas fa-thumbs-down\"><\/i>\n                    <\/a>\n    <span class=\"pld-dislike-count-wrap pld-count-wrap\"><\/span>\n<\/div><\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>To create a production build you need to run the command npm run build. It will create the dist folder, that contains the production build files. Now you just need to upload the dist files on to the server. Static Server: For environments using Node, the easiest way to handle this would be to install [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":38,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/docs.theironnetwork.org\/reactify\/wp-json\/wp\/v2\/pages\/110"}],"collection":[{"href":"https:\/\/docs.theironnetwork.org\/reactify\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/docs.theironnetwork.org\/reactify\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/docs.theironnetwork.org\/reactify\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.theironnetwork.org\/reactify\/wp-json\/wp\/v2\/comments?post=110"}],"version-history":[{"count":3,"href":"https:\/\/docs.theironnetwork.org\/reactify\/wp-json\/wp\/v2\/pages\/110\/revisions"}],"predecessor-version":[{"id":115,"href":"https:\/\/docs.theironnetwork.org\/reactify\/wp-json\/wp\/v2\/pages\/110\/revisions\/115"}],"wp:attachment":[{"href":"https:\/\/docs.theironnetwork.org\/reactify\/wp-json\/wp\/v2\/media?parent=110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}