Home

Awesome

Learning Parcel.js

Just one of the things I'm learning: https://github.com/hchiam/learning

Parcel is a web app bundler. It's like Webpack, but with much less friction to set up your build.

You can see an example here based directly off of a quick tutorial by Maks Akymenko.

Example Setup

npm install -g parcel
# v1 parcel-bundler has been deprecated

or with yarn:

yarn global add parcel

More: https://parceljs.org

Example Usage

parcel index.html

And then open http://localhost:1234 in a browser.

The command above will auto-rerun whenever you save a file.

Tree Shaking and Minification

In other words, to automatically trim off unused code, and to shorten the code that is used, you run a different command:

parcel build index.html --experimental-scope-hoisting

This does not auto-rerun whenever you save a file, but you'll notice the smaller .js file sizes in the dist folder.

Inline JS into HTML

  1. Make sure to use inline="inline" when you link the .js file to the .html file:

    <script src="./index.js" inline="inline"></script>
    
  2. Install parcel-plugin-inline-source as a development dependency:

    npm install parcel-plugin-inline-source --save-dev
    
  3. Then this command will use parcel-plugin-inline-source:

    parcel build index.html --no-source-maps --no-cache
    
  4. You might want to do this too: rm dist/*.js; rm dist/*.jpg

More options

https://parceljs.org/cli.html#options

For example: --out-dir, --port, --out-file, --https, --cache-dir

And this command to auto-open a browser tab:

parcel demo/index.html --open

Babel core-js 3 ponyfill

(To transform modern syntax into code accessible to older browsers without breaking native built-ins.)

https://github.com/kubenstein/parcel-babel-runtime-example