<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Alyona Rodin on Medium]]></title>
        <description><![CDATA[Stories by Alyona Rodin on Medium]]></description>
        <link>https://medium.com/@alyona.rodin?source=rss-f3a12dace0aa------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*JydPDQgNe3cReiKxb0ngmA.jpeg</url>
            <title>Stories by Alyona Rodin on Medium</title>
            <link>https://medium.com/@alyona.rodin?source=rss-f3a12dace0aa------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 15:58:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alyona.rodin/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Create Database]]></title>
            <link>https://medium.com/@alyona.rodin/create-database-476128f3e035?source=rss-f3a12dace0aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/476128f3e035</guid>
            <category><![CDATA[diagrams]]></category>
            <category><![CDATA[normal-form]]></category>
            <category><![CDATA[normalization]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[entity-relationship-model]]></category>
            <dc:creator><![CDATA[Alyona Rodin]]></dc:creator>
            <pubDate>Tue, 12 Nov 2019 06:35:43 GMT</pubDate>
            <atom:updated>2019-12-14T22:08:38.260Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lxYXR-a-6uyviB9sezOBhw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/oLhTLD-RBsc">Igor Miske</a> on <a href="https://unsplash.com/photos/oLhTLD-RBsc">Unsplash</a></figcaption></figure><h3>Create Entity Relationship Diagram (ERD) and Normalization</h3><p><a href="https://www.lucidchart.com/pages/?noHomepageRedirect=true">Online Diagram Software &amp; Visual Solution | Lucidchart</a></p><p>An <strong>Entity Relationship (ER) Diagram</strong> is a type of flowchart, which shows how entities (people, objects) relate to each other within a system. <strong>Flowchart</strong> is a type of diagram that represents the process. ERD uses a defined set of symbols such as rectangles, diamonds, ovals and lines to depict interconnectedness of entities, relationships, and their attributes.</p><p>ER Diagrams are composed of entities, relationships, and attributes. And depict cardinality, which defines relationships in terms of numbers.</p><p>Steps to draw an ER Diagram:</p><p>1.Define the purpose and scope of what is analyzed or modeled. For example, to model Art Gallery database, which will keep track of the Artists’ Artworks.</p><p>2.Identify the entities that are involved, labeling as nouns. <strong>Entity</strong> is a thing — such as a person, object, concept or event — that have data stored about it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/242/0*UYdvrW5oWJC_Gkgb" /><figcaption>Entities for Art Gallery ER Diagram</figcaption></figure><p>Entity can be weak and strong. The weak<strong> </strong>entity has no primary keys, has no meaning without its parent entity (strong entity). Strong entities, for example, are ArtWorks and Exhibition, and weak entity will be Art_Exhibition event in this case, because the event will not happen if there are no artworks in the exhibition. Tables are another way representing entities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/0*0dpTZn_Ats10vbmY" /><figcaption>Relationships for Art Gallery ER Diagram</figcaption></figure><p>3. Determine how the entities are all related, using verbs. <strong>Relationships</strong> — how entities are associated with each other. For example, entities Artist and Artwork, and the relationship depicted is the act of creating, connects the entities in that way. Relationship’s symbol is diamond.</p><p>4. Add attributes. <strong>Attributes </strong>— characteristics of an entity, and has an oval symbol. For example, entity Artist has FirstName, LastName, BirthDate, etc. attributes. Attributes represent the columns in the table entity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s90NEPXlwRTJwHq6W4lvlg.png" /><figcaption>Attributes for each Entity in Art Gallery ER Diagram</figcaption></figure><p>5. Show cardinality. <strong>Cardinality </strong>— defines the numerical attributes of the relationship between two entities. The three main cardinal relationships are one-to-one, one-to-many, and many-many. For example, Artist creates 0..* ArtWorks but ArtWork created by 1..1 Artist.</p><p><strong><em>Sentences of relationships to the Art Gallery Diagram with Cardinality:</em></strong></p><p>One artist <strong>MAY BE </strong>creating <strong>ONE or MORE </strong>pieces of artwork.</p><p>One piece of artwork <strong>MUST BE</strong> created by <strong>ONE and ONLY ONE</strong> artist.</p><p>One piece of artwork <strong>MUST BE</strong> present at <strong>ONE and ONLY ONE</strong> art exhibition.</p><p>One art exhibition <strong>MAY BE</strong> presenting <strong>ONE or MORE </strong>pieces of artwork.</p><p>One exhibition <strong>MUST BE</strong> putting on <strong>ONE and ONLY ONE</strong> art exhibition.</p><p>One art exhibition<strong> MAY BE</strong> put on by <strong>ONE or MORE</strong> exhibitions.</p><p>One piece of artwork <strong>MAY BE</strong> rented via <strong>ONE or MORE</strong> rentals.</p><p>One rental <strong>MUST BE</strong> agreed upon to rent <strong>ONE and ONLY ONE </strong>piece of artwork.</p><p>One piece of artwork <strong>MAY BE</strong> ordered via <strong>ONE or MORE</strong> orders to buy.</p><p>One order to buy <strong>MUST BE </strong>agreed upon to buy <strong>ONE and ONLY ONE </strong>piece of artwork.</p><p>One rental <strong>MUST BE </strong>a rental agreement for <strong>ONE and ONLY ONE</strong> customer.</p><p>One customer <strong>MAY BE</strong> renting <strong>ONE or MORE</strong> rental.</p><p>One customer <strong>MAY BE</strong> placing <strong>ONE or MORE</strong> order to buy.</p><p>One order to buy <strong>MUST BE </strong>placed by <strong>ONE and ONLY ONE </strong>customer.</p><p>There are three levels (stages) of details of ER models: Conceptual, Logical, and Physical. Conceptual ER model is highly abstract. Conceptual ER model contains only entities. Logical ER model has attributes for each entity, key attributes, and non-key attributes, primary key-foreign key relationships. Physical ER diagram is the most granular level of ER diagram. Physical ER show all table structures (entities referred to as tables), such as column name, primary keys, foreign keys, relationships between tables, cardinalities, indexes, constrains, data types.</p><p><strong>Relational Model:</strong></p><p><em>Keys</em> serve integral part in the normalization process. There are two types of keys: <strong>primary key (key) </strong>and <strong>foreign key (fk)</strong>. The primary key is a unique identifier of each value in the table, with that said it cannot be changed and cannot be NULL. The good example of the primary key can be U.S. Social Security number. In many cases, these primary keys need to be created. The created primary keys are artificial keys. The foreign key is the key in the table B, which is primary key in the different table A. The foreign keys let us to link together two tables. The keys are defined in the Relational Model. <strong>Relational Model</strong> represents the collection of relations.</p><p>In Art Gallery relational model, the table Artist has primary key Artist_ID, which was created (artificial key):</p><p><em>Artist(Artist_ID (key), FirstName, LastName, BirthDate, BirthPlace, City, State, Zip, Phone_Number, Style)</em></p><p>The table Customer has artificially created primary key Customer_ID:</p><p><em>Customer(Customer_ID (key), FirstName, LastName, PhoneNumber, Address, City, State, Zip, Country)</em></p><p>The table Exhibition has artificially created primary key Exhibition_ID:</p><p><em>Exhibition( Exhibition_ID (key), Name, StartDate, EndDate, Country, City, State, Zip )</em></p><p>The table Order_To_Buy has created primary key OrderID and foreign key Art_ID (table B) which is primary key in table ArtWorks (table A), linking Order_To_Buy and ArtWorks tables together. The table Order_To_Buy has foreign key Customer_ID (table B) which is primary key in table Customer (table A), linking Order_To_Buy and Customer tables together.</p><p><em>Order_To_Buy(OrderID (key), Order_Price, OrderDate, Art_ID (fk), Customer_ID (fk))</em></p><p>The table Rental has created primary key RentalID and foreign key Art_ID (table B) which is primary key in table ArtWorks (table A), linking Rental and ArtWorks tables together. The table Rental has foreign key Customer_ID (table B) which is primary key in table Customer (table A), linking Rental and Customer tables together.</p><p><em>Rental(RentalID (key), Rental_Start_Date, Rental_End_Date, Rental_Price, Art_ID (fk), Customer_ID (fk))</em></p><p>The table Artwork has created primary key and foreign key Artist_ID (table B) which is primary key in table Artist (table A), linking Artwork and Artist tables together.</p><p>Artwork(Art_ID (key), Year, Title, Price, Description, Type, Artist_ID (fk), RentalID (fk)?, OrderID (fk)?)</p><p>The table Art_Exhibition is the weak entity. Weak entities don’t have primary keys. Art_Id and Exhibition_Id are foreign keys.</p><p>Art_Exhibition(Art_Id (fk), Exhibition_Id (fk))</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WDW-7scBB99XThOAPJfR9w.png" /><figcaption>Entity Relationship Diagram (ERD), made using <a href="https://www.lucidchart.com/">Lucid chart</a></figcaption></figure><p><strong>Normalization</strong> is the process of the eliminating the data repetitions, undesirable characteristics like Insertion, Update and Deletion anomalies, and making sure the data logically stored that can disrupt the integrity of the database. Problems, which can appear without normalization are extra memory space and hard to handle and update the database without data loss. During normalization the database will be changed according to the rules, which called normal forms. In this example, the first three normal forms (1NF, 2NF, 3NF) will be considered (but there are more than three normal forms: BCNF and 4NF).</p><p>All relations are in the first Normal Form (1NF) if each column contains one value, tables does not have repeating groups of related data, the order in which data stored does not matter, values have to belong to one domain. For example, if the table has whole address (number of the building, street, apartment, zip code, state, city) in one line it will violate the first normal form, because each column (each attribute) has to contain only one value. Another example of violating the first normal form would be having similar names of the columns, such as Art_name_1, Art_name_2. Each column has to have unique name. After 1NF, there is possibility of increased redundancy but each row will be unique.</p><p>If a relation is in 2NF it means that the database is already in the 1NF and all non-key attributes are dependent upon all key attributes (primary key).</p><p>If a relation is in 3NF, it means that the database is in the 2NF and there are no transitive dependencies. A transitive dependency is an indirect relationship between attributes in the same table that causes a functional dependency. <strong>Boyce and Codd Normal Form</strong> is a improved version of the Third Normal form, when for each functional dependency ( x → y ), a should be a super Key. In 4NF, the relation doesn’t have Multi-Valued Dependency.</p><p>In Art Gallery Database, the first relationship is</p><p><strong>Artist(Artist_ID (key), FirstName, LastName, BirthDate, BirthPlace, City, State, Zip, Phone_Number, Style)</strong></p><p>The primary key is Artist_ID. <strong>Functional Dependency (FD)</strong> is the relation of one attribute to another attribute in a database management system (DBMS) system and denoted by the arrow →.</p><p>FD1: Artist_ID → FirstName, LastName, BirthDate, BirthPlace, City, State, Zip, Phone_Number, Style, Country</p><p>FD2: Zip → City, State, Country</p><p><em>1NF: Meets the definition of a relation</em></p><p><em>2NF: No partial Key dependencies</em></p><p><em>3NF: this is not in 3N due to the existence of the transitive dependency:</em></p><p>Artist_ID → FirstName, LastName, BirthDate, BirthPlace,Zip, Phone_Number, Style and Zip → City, State, Country</p><p>Solution: Split the relation into two new relations named Artist_Address<strong>, </strong>Artist_Info:</p><p>Artist_Address(Zip, City, State)</p><p>FD1: Zip → City, State</p><p><em>1NF: Meets the definition of a relation</em></p><p><em>2NF: No partial Key dependencies</em></p><p><em>3NF: No transitive dependency</em></p><p>Artist_Info(Artist_ID, FirstName, LastName, BirthDate, BirthPlace, Zip, PhoneNumber, Style)</p><p>FD1: Artist_ID → FirstName, LastName, BirthDate, BirthPlace, Zip, PhoneNumber, Style</p><p><em>1NF: Meets the definition of a relation</em></p><p><em>2NF: No partial Key dependencies</em></p><p><em>3NF: No transitive dependency</em></p><p><strong>Customer(Customer_ID (key), FirstName, LastName, PhoneNumber, Address, City, State, Zip, Country)</strong></p><p>Key: Customer_ID</p><p>FD1: Customer_ID → FirstName, LastName, PhoneNumber, Address, City, State, Zip, Country</p><p>FD2: Zip → City, State, Country</p><p><em>1NF: Meets the definition of a relation</em></p><p><em>2NF: No partial Key dependencies</em></p><p><em>3NF: this is not in 3N due to existence of transitive dependency:</em></p><p>Customer_ID → FirstName, LastName, PhoneNumber, Address, Zip, Country and Zip → City, State, Country</p><p>Solution: Split User relation into two new relations named Customer_Address<strong>, </strong>Customer_Info:</p><p>Customer_Address(Zip, City, State, Country)</p><p>FD1: Zip → City, State, Country</p><p><em>1NF: Meets the definition of a relation</em></p><p><em>2NF: No partial Key dependencies</em></p><p><em>3NF: No transitive dependency</em></p><p>Customer_Info(Customer_ID, FirstName, LastName, PhoneNumber, Address, Zip)</p><p>FD1: Customer_ID → FirstName, LastName, PhoneNumber, Address, Zip)</p><p><em>1NF: Meets the definition of a relation</em></p><p><em>2NF: No partial Key dependencies</em></p><p><em>3NF: No transitive dependency</em></p><p><strong>Exhibition(Exhibition_ID (key), Name, StartDate, EndDate, Country, City, State, Zip )</strong></p><p>Key: Exhibition_ID</p><p>FD1: Exhibition_ID → Name, StartDate, EndDate, Country, City, State, Zip</p><p>FD2: Zip → Country, City, State</p><p><em>1NF: Meets the definition of a relation</em></p><p><em>2NF: No partial Key dependencies</em></p><p><em>3NF: this is not in 3N due to existence of transitive dependency</em></p><p>Exhibition_ID → Name, Start_Date, End_Date, Zip and Zip → Country, City, State</p><p>Solution: Split User relation into two new relations named Exhibition_Address<strong>, </strong>Exhibition_Info:</p><p>Exhibition_Address(Zip(key), Country, City, State)</p><p>FD1: Zip → Country, City, State</p><p><em>1NF: Meets the definition of a relation</em></p><p><em>2NF: No partial Key dependencies</em></p><p><em>3NF: No transitive dependency</em></p><p>Exhibition_Info(Exhibition_ID(key), Name, StartDate, EndDate, Zip(fk))</p><p>FD1: Exhibition_ID → Name, Start_Date, End_Date, Zip</p><p><em>1NF: Meets the definition of a relation</em></p><p><em>2NF: No partial Key dependencies</em></p><p><em>3NF: No transitive dependency</em></p><p><strong>Art_Exhibition(Exhibition_ID (fk), Art_ID (fk))</strong></p><p><strong>Order_To_Buy(OrderID (key), Order_Price, OrderDate, Art_ID (fk), Customer_ID (fk))</strong></p><p>Key: OrderID</p><p>FD1: OrderID → Order_Price, OrderDate, Art_ID, Customer_ID</p><p><em>1NF: Meets the definition of a relation</em></p><p><em>2NF: No partial Key dependencies</em></p><p><em>3NF: No transitive dependency</em></p><p><strong>Rental(RentalID (key), Rental_Start_Date, Rental_End_Date, Rental_Price, Art_ID (fk), Customer_ID (fk))</strong></p><p>Key: RentalID</p><p>FD1: RentalID → Rental_Start_Date, Rental_End_Date, Rental_Price, Art_ID, Customer_ID</p><p><em>1NF: Meets the definition of a relation</em></p><p><em>2NF: No partial Key dependencies</em></p><p><em>3NF: No transitive dependency</em></p><p><strong>Artwork(Art_ID (key), Year, Title, Price, Description, Type, Artist_ID (fk))</strong></p><p>Key: Art_ID</p><p>FD1: Art_ID → Year, Title, Price, Description, Type, Artist_ID</p><p><em>1NF: Meets the definition of a relation</em></p><p><em>2NF: No partial Key dependencies</em></p><p><em>3NF: No transitive dependency</em></p><p>Final relations normalized to Third Normal Form:</p><p><strong>Artist_Address</strong>(Zip(key), City, State, Country)</p><p><strong>Artist_Info</strong>(Artist_ID(key), First_Name, Last_Name, Birth_Date, Birth_Place, Zip(fk), Address, Phone_Number, Style)</p><p><strong>Customer_Address</strong>(Zip(key), City, State, Country)</p><p><strong>Customer_Info</strong>(Customer_ID(key), First_Name, Last_Name, Phone_Number, Address, Zip(fk))</p><p><strong>Exhibition_Address</strong>(Zip(key), Country, City, State)</p><p><strong>Exhibition_Info</strong>(Exhibition_ID(key), Name, Start_Date, End_Date, Zip(fk))</p><p><strong>Art_Exhibition</strong>( Exhibition_ID (fk)(key), Art_ID (fk)(key))</p><p><strong>Order_To_Buy</strong>(Order_ID (key), Order_Price, Order_Date, Art_ID (fk), Customer_ID (fk))</p><p><strong>Rental</strong>(Rental_ID (key), Rental_Start_Date, Rental_End_Date, Rental_Price, Art_ID (fk), Customer_ID (fk))</p><p><strong>Artwork</strong>(Art_ID (key), Year, Title, Price, Description, Type, Artist_ID (fk), Order_ID (fk), Rental_ID (fk))</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=476128f3e035" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build React Project from Scratch]]></title>
            <link>https://medium.com/@alyona.rodin/build-react-project-from-scratch-c6fa4ca65303?source=rss-f3a12dace0aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/c6fa4ca65303</guid>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[babel]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[create-react-app]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Alyona Rodin]]></dc:creator>
            <pubDate>Sun, 03 Nov 2019 04:54:27 GMT</pubDate>
            <atom:updated>2019-11-23T05:50:30.345Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Photo by Andrik Langfield on Unsplash" src="https://cdn-images-1.medium.com/max/1024/1*BrK7flP7RtWa8AVy0gkKtw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@andriklangfield?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Andrik Langfield</a> on <a href="https://unsplash.com/@andriklangfield?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>One way quickly and without any efforts to create a React Project is <a href="https://github.com/facebook/create-react-app">create-react-app</a>. Create-react-app will set up web app by running only one command. Make sure to have the latest version of Node.js. Run the command to check what version:</p><pre>npm -v </pre><p>Install the newest npm update:</p><pre>npm install npm@latest -g</pre><ul><li><strong>-g</strong> means globally</li></ul><p><strong>npx</strong> is used to run packages without downloading. Run the commands in terminal:</p><pre>npx create-react-app my-app <br>cd my-app <br>npm start</pre><ul><li><strong>my-app</strong> is a name of the folder</li><li><strong>cd </strong>change directory</li><li><strong>npm start</strong> runs the app in development mode. It will open <a href="http://localhost:3000/">http://localhost:3000</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_v0EBKQNKm9RRFig45MQLA.png" /></figure><p>Another way to create React Project is manually. First, install<a href="https://docs.npmjs.com/downloading-and-installing-node-js-and-npm"> npm</a>. <strong>npm</strong> is the software registry, which allows to share, use code, and lets easy to update the shared code. npm is distributed with Node.js and is installed with <a href="https://nodejs.org/en/download/">Node.js</a>.<br><strong>Node.js</strong> is a JavaScript runtime built on Chrome’s <a href="https://v8.dev/">V8</a> JavaScript engine.<br>Engine<em> </em>processes JavaScript in the browser. Another words, it compiles the JavaScript code to native machine code.</p><p>Create directories by running the following commands in terminal:</p><pre>mkdir [name]<br>cd [name]<br>mkdir -p src/components src/styles</pre><ul><li><strong>[name]</strong> is the name of the folder</li><li><strong>mkdir</strong> creates new folder — makes directory</li><li><strong>cd</strong> changes directory</li><li><strong>mkdir -p src/components src/styles</strong> creates a folder <strong>src</strong> with folders <strong>styles</strong> and <strong>components (</strong>-p is path)</li></ul><p>Additional commands:</p><ul><li><strong>pwd</strong> prints working directory</li><li><strong>ls</strong> lists information about files</li><li><strong>mv</strong> move or rename files or directories (mv -f [file name] [new place])</li></ul><p>To start new Node.js project, run the command <strong>npm init</strong> to answer the following questions below or press ENTER to skip questions one by one. These questions is the starting point in the package.json.</p><pre>npm init </pre><pre>package name: (react_project)<br>version: (1.0.0)<br>description:<br>entry point: (index.js)<br>test command:<br>git repository:<br>keywords:<br>author:<br>license: (ISC)</pre><pre>Is this OK? (yes) ENTER</pre><ul><li><strong>package name </strong>is<strong> </strong>the name of your project</li></ul><p>To skip the questions at all just run the command with -y flag:</p><pre>npm init -y</pre><p><strong>npm init</strong> command creates <strong>package.json </strong>file, which contains the skipped/answered questions.</p><pre>{<br>  &quot;name&quot;: &quot;react_project&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;&quot;,<br>  &quot;main&quot;: &quot;index.js&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;<br>  },<br>  &quot;author&quot;: &quot;&quot;,<br>  &quot;license&quot;: &quot;ISC&quot;<br>}</pre><p>Install <a href="https://www.npmjs.com/package/webpack">webpack</a>. <strong>Webpack</strong> is a module bundler for Javascript applications. Programs, in <a href="https://en.wikipedia.org/wiki/Modular_programming">modular programming</a>, consist of discrete chunks of functionality called a <strong>module</strong>. Webpack builds a dependency graph which maps modules for project and generates one or more bundles. The situation when one file depends from another file, webpack treats this as <strong>dependency</strong>. To install webpack, run the command:</p><pre>npm install webpack webpack-cli --save-dev</pre><ul><li><strong>- - save-dev </strong>saves into devDependencies in package.json file. Installing webpack and webpack-cli, allows interact with webpack either from its Command Line Interface (CLI) or API. <a href="https://www.npmjs.com/package/webpack-cli"><strong>Webpack-cli</strong></a> is the tool to run webpack on the command line. New files were added into project, which are package-lock.json and node_modules. Package.json got ‘devDependencies’:</li></ul><pre>{ <br>  &quot;name&quot;: &quot;react_project&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;&quot;,<br>  &quot;main&quot;: &quot;index.js&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;<br>},<br>  &quot;author&quot;: &quot;&quot;,<br>  &quot;license&quot;: &quot;ISC&quot;,<br> + &quot;devDependencies&quot;: {<br>   + &quot;webpack&quot;: &quot;^4.41.2&quot;,<br>   + &quot;webpack-cli&quot;: &quot;^3.3.10&quot;<br> }<br>}</pre><p><strong>React</strong> is a Javascript library for creating user interfaces (UI). To install React run the commands:</p><pre>npm install react <br>npm install react-dom</pre><p><a href="https://www.npmjs.com/package/react">React</a> package contains the functionality necessary to define React components. It used usually with React renderers <a href="https://www.npmjs.com/package/react-dom">react-dom</a> (web) or react-native. Package.json got ‘dependencies’:</p><pre>{ <br>  &quot;name&quot;: &quot;react_project&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;&quot;,<br>  &quot;main&quot;: &quot;index.js&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;<br>},<br>  &quot;author&quot;: &quot;&quot;,<br>  &quot;license&quot;: &quot;ISC&quot;,<br>  &quot;devDependencies&quot;: {<br>    &quot;webpack&quot;: &quot;^4.41.2&quot;,<br>    &quot;webpack-cli&quot;: &quot;^3.3.10&quot;<br> },<br> + &quot;dependencies&quot;: {<br>  +  &quot;react&quot;: &quot;^16.11.0&quot;,<br>  +  &quot;react-dom&quot;: &quot;^16.11.0&quot;<br> }<br>}</pre><p>Babel is a Javascript compiler. Install <a href="https://babeljs.io/docs/en/">Babel</a> by running the commands:</p><pre>npm install --save-dev @babel/core babel-loader @babel/preset-env @babel/preset-react</pre><ul><li><strong>@</strong><a href="https://babeljs.io/docs/en/babel-core"><strong>babel/core</strong></a> transforms ES6 code to ES5</li><li><strong>@</strong><a href="https://babeljs.io/docs/en/babel-cli"><strong>babel/cli</strong></a><strong> </strong>can be used to compile files from the command line</li><li><strong>babel-loader</strong> webpack helper to transpile code, given the preset. Transpiler (source-to-source compilers) is a tool which reads source code in one programming language to converts it into another language.</li><li><strong>@</strong><a href="https://babeljs.io/docs/en/babel-preset-env"><strong>babel/preset-env</strong></a> preset which helps Babel to convert ES6, ES7, ES8 code to ES5. <a href="https://babeljs.io/docs/en/presets">Preset</a> is a predetermined set of <a href="https://babeljs.io/docs/en/plugins">plugins</a>. Transformations come in the form of plugins, which are small JavaScript programs that instruct Babel on how to carry out transformations to the code.</li><li><strong>@</strong><a href="https://babeljs.io/docs/en/babel-preset-react"><strong>babel/preset-react</strong></a> preset which transforms JSX to JavaScript</li></ul><p>Package.json:</p><pre>{ <br>  &quot;name&quot;: &quot;react_project&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;&quot;,<br>  &quot;main&quot;: &quot;index.js&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;<br>},<br>  &quot;author&quot;: &quot;&quot;,<br>  &quot;license&quot;: &quot;ISC&quot;,<br>  &quot;devDependencies&quot;: {<br>   + &quot;@babel/core&quot;: &quot;^7.6.4&quot;,<br>   + &quot;@babel/preset-env&quot;: &quot;^7.6.3&quot;,<br>   + &quot;@babel/preset-react&quot;: &quot;^7.6.3&quot;,<br>   + &quot;babel-loader&quot;: &quot;^8.0.6&quot;,<br>    &quot;webpack&quot;: &quot;^4.41.2&quot;,<br>    &quot;webpack-cli&quot;: &quot;^3.3.10&quot;<br> },<br>  &quot;dependencies&quot;: {<br>    &quot;react&quot;: &quot;^16.11.0&quot;,<br>    &quot;react-dom&quot;: &quot;^16.11.0&quot;<br> }<br>}</pre><p>Create <strong>index.html</strong> file inside of <strong>src</strong> file [<strong>src/index.html</strong>] and add the code:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>  &lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;title&gt;[project name]&lt;/title&gt;<br>  &lt;/head&gt;<br>  &lt;body&gt;<br>    &lt;div id=&quot;root&quot;&gt;</pre><pre>    &lt;/div&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;</pre><ul><li><strong>&lt;meta charset=”UTF-8&quot;&gt;</strong> the character encoding for the HTML document and <a href="https://www.w3schools.com/charsets/ref_html_utf8.asp">UTF-8</a> is the preferred encoding for e-mail and web pages.</li></ul><p>Create <strong>index.js</strong> file inside of <strong>src</strong> file [<strong>src/index.js</strong>] and add the code:</p><pre>import React from &quot;react&quot;;<br>import ReactDOM from &quot;react-dom&quot;;<br>import App from &quot;./components/App.js&quot;;</pre><pre>ReactDOM.render(&lt;App /&gt;, document.getElementById(&quot;root&quot;));</pre><ul><li>imported react from ‘react’, react-dom(web) from ‘react-dom’, and component App.js as App [&lt;App /&gt;]</li><li>document is any web page loaded in the browser, which is an entry point into the web page’s content (DOM tree). <strong>DOM</strong> — document object model.</li><li><a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById"><strong>document.getElementById()</strong></a> is a method that returns an element object representing the element whose id property matches the specified string. Id is ‘root’ matches in the index.html id in the tag &lt;div&gt;.</li></ul><pre>ReactDOM.render(element, container[, callback])</pre><p>Create <strong>App.js</strong> file inside the src/components [<strong>src/components/App.js</strong>] and add the code:</p><pre>import React, { Component } from &quot;react&quot;; <br>import &#39;../styles/App.css&#39;; </pre><pre>class App extends Component {    <br>   render() {        <br>       return (            <br>            &lt;div&gt;                <br>                  &lt;h1&gt;REACT!&lt;/h1&gt;<br>            &lt;/div&gt;);    <br>            }<br>} <br>export default App;</pre><p>Create <strong>App.css</strong> file inside the src/styles [<strong>src/styles/App.css</strong>] and add the code:</p><pre>h1 {    <br>     color: #37474f;    <br>     text-align: center;<br>}</pre><p>Create <strong>webpack.config.js</strong> file in the root directory. When webpack processes the application, it starts from a list of modules defined on the command line or in its config file webpack.config.js. Starting from these entry points, webpack recursively builds a dependency graph that includes every module the application needs and bundles them to be loaded by the browser. Entry points in the webpack.config.js:</p><pre>module.exports = {<br>  entry: &#39;./path/to/my/entry/file.js};</pre><p>Add in webpack.config.js the code:</p><pre>module.exports = {<br>   entry: &quot;./src/index.js&quot;,<br>   };</pre><p>Output configurations tells webpack how to write the compiled files to disk. This configuration would output a single <strong>budle.js</strong> file into the <strong>dist</strong> directory [<strong>dist/bundle.js</strong>]. In webpack.config.js add the output:</p><pre>const path = require(&quot;path&quot;);</pre><pre>module.exports = {<br>  entry: &quot;./src/index.js&quot;,<br>  output: {path: path.join(__dirname, &quot;/dist&quot;),   <br>           filename: &quot;bundle.js&quot;<br>          }<br>};</pre><ul><li><strong>__dirname</strong> directory name of the current module, which is ‘dist’</li></ul><p>Create <strong>.babelrc</strong> configuration file in the root directory. es2015 and react do not require configuration. Add the code below:</p><pre>{&quot;presets&quot;:[&quot;@babel/preset-env&quot;,&quot;@babel/preset-react&quot;]}</pre><p>Loaders (babel-loader also) are transformations that are applied on the source code of a module. They allow to preprocess imported/ ‘loaded’ files. Loaders are evaluated/executed from right to left (or from bottom to top). To tell webpack to load a CSS file or styles, install the loaders by running a command:</p><pre>npm install --save-dev css-loader style-loader</pre><p>Add babel-loader, css-loader, style-loader into webpack.config.js:</p><pre>const path = require(&quot;path&quot;);</pre><pre>module.exports = {<br>  entry: &quot;./src/index.js&quot;,<br>  output: {path: path.join(__dirname, &quot;/dist&quot;),   <br>           filename: &quot;bundle.js&quot;<br>          },<br>  module: { rules:<br>             [{test: /\.js$/,<br>               exclude: /node_modules/,<br>               use: [&quot;babel-loader&quot;]},<br>              {test: /\.css$/,<br>               use: [&quot;style-loader&quot;, &quot;css-loader&quot;]}<br>             ]<br>           }<br>};</pre><ul><li>/\.css$/ is a regular expression that says test if it matches .css till end of input, use css loader and style loader</li><li>/\.js$/ is a regular expression that says test if it matches .js till end of input, use babel loader, and exclude node_modules</li></ul><p>Package.json has additional devDependencies:</p><pre>{ <br>  &quot;name&quot;: &quot;react_project&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;&quot;,<br>  &quot;main&quot;: &quot;index.js&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;<br>},<br>  &quot;author&quot;: &quot;&quot;,<br>  &quot;license&quot;: &quot;ISC&quot;,<br>  &quot;devDependencies&quot;: {<br>    &quot;@babel/core&quot;: &quot;^7.6.4&quot;,<br>    &quot;@babel/preset-env&quot;: &quot;^7.6.3&quot;,<br>    &quot;@babel/preset-react&quot;: &quot;^7.6.3&quot;,<br>    &quot;babel-loader&quot;: &quot;^8.0.6&quot;,<br>   + &quot;css-loader&quot;: &quot;^3.2.0&quot;,<br>   + &quot;style-loader&quot;: &quot;^1.0.0&quot;,<br>    &quot;webpack&quot;: &quot;^4.41.2&quot;,<br>    &quot;webpack-cli&quot;: &quot;^3.3.10&quot;<br> },<br>  &quot;dependencies&quot;: {<br>    &quot;react&quot;: &quot;^16.11.0&quot;,<br>    &quot;react-dom&quot;: &quot;^16.11.0&quot;<br> }<br>}</pre><p>There are two modes, which are development and production. The goal of development is strong source mapping and live reloading of localhost server (hot module replacement). The goal of production is minified bundles, lighter weight source maps, and optimized assets to improve load time.</p><p>In package.json add the code into ‘scripts’. It lets not to be concerned about their full paths (usage via the CLI):</p><pre>&quot;start&quot;: &quot;webpack --mode development --watch&quot;,<br>&quot;build&quot;: &quot;webpack --mode production&quot;</pre><ul><li><strong>- watch</strong> means that after initial build, webpack will continue to watch for changes in any of the resolved files</li></ul><p>HtmlWebpackPlugin will generate an HTML5 file that includes all the webpack bundles in the body using &lt;script&gt;. Install html-webpack-plugin by running the command:</p><pre>npm install --save-dev html-webpack-plugin</pre><p>Add the plugin to webpack.config.js:</p><pre>const path = require(&quot;path&quot;);<br>const HtmlWebpackPlugin = require(&quot;html-webpack-plugin&quot;);</pre><pre>module.exports = { <br>              entry: &quot;./src/index.js&quot;,<br>              output: { path: path.join(__dirname, &quot;/dist&quot;),<br>                        filename: &quot;bundle.js&quot;},<br>              module: {rules: <br>                 [{test: /\.js$/,<br>                   exclude: /node_modules/,<br>                   use: [&quot;babel-loader&quot;]},<br>                  {test: /\.css$/,<br>                   use: [&quot;style-loader&quot;, &quot;css-loader&quot;]}]},    <br>              plugins: <br>                   [new HtmlWebpackPlugin({<br>                        template: &quot;./src/index.html&quot;})]<br>};</pre><p>Package.json</p><pre>{&quot;name&quot;: &quot;react_project&quot;,<br> &quot;version&quot;: &quot;1.0.0&quot;,<br> &quot;description&quot;: &quot;&quot;,<br> &quot;main&quot;: &quot;index.js&quot;,<br> &quot;scripts&quot;: { &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;,<br>              + &quot;start&quot;: &quot;webpack --mode development --watch&quot;,<br>              + &quot;build&quot;: &quot;webpack --mode production&quot;</pre><pre>},<br> &quot;author&quot;: &quot;&quot;,<br> &quot;license&quot;: &quot;ISC&quot;,<br> &quot;devDependencies&quot;: { &quot;@babel/core&quot;: &quot;^7.6.4&quot;,<br>                      &quot;@babel/preset-env&quot;: &quot;^7.6.3&quot;,<br>                      &quot;@babel/preset-react&quot;: &quot;^7.6.3&quot;,<br>                      &quot;babel-loader&quot;: &quot;^8.0.6&quot;,<br>                      &quot;webpack&quot;: &quot;^4.41.1&quot;,<br>                      &quot;webpack-cli&quot;: &quot;^3.3.9&quot;,<br>                      + &quot;html-webpack-plugin&quot;: &quot;^3.2.0&quot;,<br>                      &quot;css-loader&quot;: &quot;^3.2.0&quot;,<br>                      &quot;style-loader&quot;: &quot;^1.0.0&quot;,</pre><pre>},<br> &quot;dependencies&quot;: {&quot;react&quot;: &quot;^16.10.2&quot;,<br>                 &quot;react-dom&quot;: &quot;^16.10.2&quot;}<br>}</pre><p>Run the command in terminal, which generate in <strong>dist</strong> file <strong>bundle.js </strong>which contains the transpiled ES5 code from <strong>index.js</strong> file:</p><pre>npm start</pre><p>It will also generate a file <strong>dist/index.html</strong> with the code:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>&lt;meta charset=&quot;UTF-8&quot;&gt;<br>&lt;title&gt;[project name]&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>&lt;div id=&quot;root&quot;&gt;<br>&lt;/div&gt;<br>&lt;script type=&quot;text/javascript&quot; src=&quot;bundle.js&quot;&gt;&lt;/script&gt;&lt;/body&gt;<br>&lt;/html&gt;</pre><p>Install the module <a href="https://github.com/webpack/webpack-dev-server"><strong>webpack-dev-server</strong></a>.<strong> </strong>It<strong> </strong>will start a server instance and begin listening for connections from localhost on port: 8080:</p><pre>npm install webpack-dev-server --save-dev</pre><p>In package.json change “start”:</p><pre>&quot;start&quot;: &quot;webpack-dev-server --mode development --open --hot&quot;</pre><ul><li><strong>— open</strong> tells dev-server to open the browser after server had been started. It set to true to open the default browser or</li></ul><pre>&quot;start&quot;: &quot;webpack-dev-server --mode development --open &#39;Google Chrome&#39; --hot&quot;</pre><ul><li>— open ‘Google Chrome’ opens Chrome on macOS or simply ‘Chrome’. ‘google-chrome’ on Linux and ‘chrome’ on Windows</li><li>— hot (Hot Module Replacement) exchanges, adds, removes modules while an application is running, without a full reload to speed up development.</li></ul><p><a href="https://github.com/webpack/webpack-dev-server/tree/master/examples/cli/host-and-port">Webpack-dev-server opens port: 8080 by default. To change the port:</a></p><pre>&quot;start&quot;: &quot;webpack-dev-server --mode development --open --port 5000 --hot&quot;</pre><ul><li><strong>— port 5000 </strong>will<strong> </strong>open localhost on port 5000. It’s also possible to change the host</li></ul><p>Package.json</p><pre>{&quot;name&quot;: &quot;react_project&quot;,<br> &quot;version&quot;: &quot;1.0.0&quot;,<br> &quot;description&quot;: &quot;&quot;,<br> &quot;main&quot;: &quot;index.js&quot;,<br> &quot;scripts&quot;: { &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;<br>              &quot;start&quot;: &quot;webpack-dev-server --mode development --open --hot&quot;,<br>              &quot;build&quot;: &quot;webpack --mode production&quot;},<br> &quot;author&quot;: &quot;&quot;,<br> &quot;license&quot;: &quot;ISC&quot;,<br> &quot;devDependencies&quot;: { &quot;@babel/core&quot;: &quot;^7.6.4&quot;,<br>                      &quot;@babel/preset-env&quot;: &quot;^7.6.3&quot;,<br>                      &quot;@babel/preset-react&quot;: &quot;^7.6.3&quot;,<br>                      &quot;babel-loader&quot;: &quot;^8.0.6&quot;,<br>                      &quot;webpack&quot;: &quot;^4.41.1&quot;,<br>                      &quot;webpack-cli&quot;: &quot;^3.3.9&quot;,<br>                      &quot;css-loader&quot;: &quot;^3.2.0&quot;,<br>                      &quot;style-loader&quot;: &quot;^1.0.0&quot;,<br>                      &quot;webpack-dev-server&quot;: &quot;^3.9.0&quot;</pre><pre>},<br> &quot;dependencies&quot;: {&quot;react&quot;: &quot;^16.10.2&quot;,<br>                 &quot;react-dom&quot;: &quot;^16.10.2&quot;}<br>}</pre><p>Run the command in terminal if it “start” in Package.json. It can also be “start:dev” if it be “start:dev”: “webpack-dev-server --mode development --open --hot”.</p><pre>npm start</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dZ42aiPho0TRcRVRLcg3Rg.png" /><figcaption>this is what to see</figcaption></figure><p>see it in <a href="https://github.com/TalRodin/react-project">GITHUB</a></p><p><em>Additional Information:</em></p><p>It’s good to use separate files for configurations, because development and production has different goals. It means to have separate webpack configurations for each environment. After separating the configurations, they have to be merged. To merge configurations install webpack-merge:</p><pre>npm install — save-dev webpack-merge</pre><p>Webpack.common.js will stay the same:</p><pre>const path = require(&quot;path&quot;);<br>const HtmlWebpackPlugin = require(&quot;html-webpack-plugin&quot;);<br>module.exports = {<br>       entry: &quot;./src/index.js&quot;,<br>       output: { <br>                path: path.join(__dirname, &quot;/dist&quot;),<br>                filename: &quot;bundle.js&quot;<br>               },<br>       module: {rules:<br>                     [{test: /\.js$/,<br>                       exclude: /node_modules/,<br>                       use: [&quot;babel-loader&quot;]},<br>               {test: /\.css$/,<br>                use: [&quot;style-loader&quot;, &quot;css-loader&quot;]}]},<br>       plugins:<br>               [new HtmlWebpackPlugin({<br>                template: &quot;./src/index.html&quot;})]};</pre><p>Create webpack.dev.js:</p><pre>const merge = require(&#39;webpack-merge&#39;);<br>const common = require(&#39;./webpack.config.js&#39;);<br>             <br>module.exports = merge(common, {<br>                       mode: &#39;development&#39;,<br>                       devtool: &#39;inline-source-map&#39;,<br>                       devServer: {contentBase: &#39;./dist&#39;,<br>                      },<br>                    });</pre><ul><li><strong>devtool</strong> controls if and how the source maps are generated. inline-source-map is added as a DataUrl to the bundle.</li></ul><p>Create webpack.prod.js:</p><pre>const merge = require(&#39;webpack-merge&#39;);<br>const common = require(&#39;./webpack.config.js&#39;);</pre><pre>module.exports = merge(common, {<br>                       mode: &#39;production&#39;<br>                 });</pre><p>In package.json, change ‘scripts’:</p><pre>&quot;start&quot;: &quot;webpack-dev-server --open --config webpack.dev.js&quot;,<br>&quot;build&quot;: &quot;webpack --config webpack.prod.js&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0mKZuqm8yxaQEKs9J_Wj4A.png" /><figcaption>this is what to see</figcaption></figure><p>see it in <a href="https://github.com/TalRodin/react-project-webpack">GITHUB</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c6fa4ca65303" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>