Image for post
Image for post

Getting Started With Parcel

Next Generation Web App Bundler

Installation

Image for post
Image for post

Initiating A New Project With Parcel

<!DOCTYPE html>
<html lang="en">
<head>
<title>Parcel Demo 01</title>
</head>
<body>
<div id="message"></div>
<script src="./app.js"></script>
</body>
</html>
document.getElementById('message').innerText = "Hello World!";
Image for post
Image for post
Image for post
Image for post

Adding A Module To The Project

export function square(x) {
return x * x;
}
import { square } from './lib';
document.getElementById('message').innerText = "The Square of 2 is " + square(2);
Image for post
Image for post
import { square } from './lib';
import $ from 'jquery';
let i = 2;function setMessageText(msg) {
$('#message').text(msg);
}
setMessageText("The Square of " + i + " is " + square(i));$('#message').click(() => {
i++;
setMessageText("The Square of " + i + " is " + square(i));
})

Adding CSS and SCSS Assets

body {
background-color: powderblue;
}
#message {
color: blue;
font-size: 3em;
text-align: center;
}
<link rel="stylesheet" href="styles.css">
Image for post
Image for post
$ npm install node-sass
$messagecolor: blue;
$bgcolor: powderblue;
body {
background-color: $bgcolor;
}
#message {
color: $messagecolor;
font-size: 3em;
text-align: center;
}
import './styles.scss';

Applying Transformations

Example: Setting Up A React Project With Parcel

$ mkdir react-parcel
$ cd react-parcel
$ npm init -y
$ npm install --save react
$ npm install --save react-dom
$ npm install --save-dev babel-preset-react
$ npm install --save-dev babel-preset-env
{
"presets": ["env", "react"]
}
<!DOCTYPE html>
<html>
<head>
<title>React Parcel Demo</title>
</head>
<body>
<div id="app"></div>
<script src="app.js"></script>
</body>
</html>
import React from "react";
import ReactDOM from "react-dom";
class HelloMessage extends React.Component {
render() {
return <div>Hello {this.props.name}</div>;
}
}
var mount = document.getElementById("app");
ReactDOM.render(<HelloMessage name="Sebastian" />, mount);
Image for post
Image for post

Building For Production


#1 The Complete Web Developer in 2018

#2 The Complete JavaScript Course — Build a Real-World Project

CodingTheSmartWay.com Blog

CodingTheSmartWay.com

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store