GithubHelp home page GithubHelp logo

ry / parcel Goto Github PK

View Code? Open in Web Editor NEW

This project forked from parcel-bundler/parcel

12.0 2.0 2.0 1.01 MB

๐Ÿ“ฆ๐Ÿš€ Blazing fast, zero configuration web application bundler

Home Page: https://parceljs.org

License: MIT License

JavaScript 97.20% CSS 0.59% HTML 1.79% CoffeeScript 0.01% OCaml 0.01% Rust 0.09% TypeScript 0.31%

parcel's Introduction

Parcel

Backers on Open Collective Sponsors on Open Collective Travis CI Build Status Appveyor Build status Coverage David Dependancy Status npm package npm package Slack Twitter Follow

Features

  • ๐Ÿš€ Blazing fast bundle times - multicore compilation, and a filesystem cache for fast rebuilds even after a restart.
  • ๐Ÿ“ฆ Out of the box support for JS, CSS, HTML, file assets, and more - no plugins to install.
  • ๐Ÿ  Automatically transforms modules using Babel, PostCSS, and PostHTML when needed - even node_modules.
  • โœ‚๏ธ Zero configuration code splitting using dynamic import() statements.
  • ๐Ÿ”ฅ Built in support for hot module replacement
  • ๐Ÿšจ Friendly error logging experience - syntax highlighted code frames help pinpoint the problem.

Getting started

  1. Install with yarn:
yarn global add parcel-bundler

or with npm:

npm install -g parcel-bundler
  1. Parcel can take any type of file as an entry point, but an HTML or JavaScript file is a good place to start. If you link your main JavaScript file in the HTML using a relative path, Parcel will also process it for you, and replace the reference with a URL to the output file.
<html>
<body>
  <script src="./index.js"></script>
</body>
</html>
  1. Parcel has a development server built in, which will automatically rebuild your app as you change files and supports hot module replacement for fast development. Just point it at your entry file:
parcel index.html
  1. Now open http://localhost:1234/ in your browser. If needed, you can also override the default port with the -p option. Add --open to automatically open a browser.

See parceljs.org for more documentation!

Benchmarks

Based on a reasonably sized app, containing 1726 modules, 6.5M uncompressed. Built on a 2016 MacBook Pro with 4 physical CPUs.

Bundler Time
browserify ย  ย  ย  22.98s
webpack ย  ย  ย  ย  ย  20.71s
parcel 9.98s
parcel - with cache 2.64s

Why parcel?

There are many web application bundlers out there with huge adoption, including webpack and browserify. So, why do we need another one? The main reasons are around developer experience.

Many bundlers are built around configuration and plugins, and it is not uncommon to see applications with upwards of 500 lines of configuration just to get things working. This configuration is not just tedious and time consuming, but is also hard to get right and must be duplicated for each application. Oftentimes, this can lead to sub-optimized apps shipping to production. parcel is designed to need zero configuration: just point it at the entry point of your application, and it does the right thing.

Existing bundlers are also very slow. Large applications with lots of files and many dependencies can take minutes to build, which is especially painful during development when things change all the time. File watchers can help with rebuilds, but the initial launch is often still very slow. parcel utilizes worker processes to compile your code in parallel, utilizing modern multicore processors. This results in a huge speedup for initial builds. It also has a file system cache, which saves the compiled results per file for even faster subsequent startups.

Finally, existing bundlers are built around string loaders/transforms, where the transform takes in a string, parses it, does some transformation, and generates code again. Oftentimes this ends up causing many parses and code generation runs on a single file, which is inefficient. Instead, parcel's transforms work on ASTs so that there is one parse, many transforms, and one code generation per file.

How it works

parcel transforms a tree of assets to a tree of bundles. Many other bundlers are fundamentally based around JavaScript assets, with other formats tacked on - for example, by default inlined as strings into JS files. parcel is file-type agnostic - it will work with any type of assets the way you'd expect, with no configuration.

parcel takes as input a single entry asset, which could be any file type: JS, HTML, CSS, image, etc. There are various asset types defined in parcel which know how to handle specific file types. The assets are parsed, their dependencies are extracted, and they are transformed to their final compiled form. This creates a tree of assets.

Once the asset tree has been constructed, the assets are placed into a bundle tree. A bundle is created for the entry asset, and child bundles are created for dynamic imports, which cause code splitting to occur. Child bundles are also created when assets of a different type are imported, for example if you imported a CSS file from JavaScript, it would be placed into a sibling bundle to the corresponding JavaScript. If an asset is required in more than one bundle, it is hoisted up to the nearest common ancestor in the bundle tree so it is not included more than once.

After the bundle tree is constructed, each bundle is written to a file by a packager specific to the file type. The packagers know how to combine the code from each asset together into the final file that is loaded by a browser.

Community

All feedback and suggestions are welcome!

  • ๐Ÿ’ฌ Chat: Join us on slack.
  • ๐Ÿ“ฃ Stay up to date on new features and announcements on @parceljs.

Contributors

This project exists thanks to all the people who contribute. [Contribute]. contributors

Backers

Thank you to all our backers! ๐Ÿ™ [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

License

MIT

parcel's People

Contributors

aicest avatar albizures avatar brandon93s avatar bwrrp avatar chee avatar davidnagli avatar derekdreery avatar devongovett avatar fansenze avatar fathyb avatar gongpeione avatar ipmb avatar jamiebuilds avatar jdanyow avatar kootoopas avatar ksafranski avatar lbguilherme avatar marcioj avatar niicojs avatar philipodev avatar rakannimer avatar richieahb avatar ronami avatar rrdelaney avatar shawwn avatar sheeldotme avatar spalger avatar ssuman avatar ukoloff avatar yeskunall avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.