Get Started
What is it?
Fastpack is a lightweight JavaScript bundler, providing functionality similar to Webpack, Parcel or Rollup. The main feature, which makes it unique is its speed. It is truly fast, see benchmarks! Please note, that Fastpack is at the early pre-alpha stage, lacking a lot of features other bundlers provide. Use at your own risk! Feel free to report a bug or contribute in some other way!
Installation
$ npm install -g fastpack
Or
$ yarn add global fastpack
If everything worked well, you should be able to run:
$ fpack --help
Fastpack relies on watchman to track
the filesystem changes. If you plan to use fastpack for development, refer to
this page for
installing watchman
for your OS.
If you are planning to use the integration with Webpack loaders, you need to have Node version 8 or above.
In a nutshell
Fastpack currently can:
- quickly build bundle in development and production modes;
- apply tree shaking when used in production mode;
- utilize the persistent cache to speed up the building when restarted;
- watch for file changes and rebuild;
- transpile minimum required of non-standard features to work in evergreen browsers (React JSX, strip Flow, object spread & class properties/decorators);
- interoperate with the most common Webpack loaders to include CSS and static files;
- accept certain configuration parameters as command-line arguments;
Fastpack lacks (yet!):
- splitting bundle into multiple chunks (e.g.
import()
expressions); - source maps support;
- development server / hot module reloading;
- Windows support (currently works on MacOS & Linux only);
- easy JavaScript integration;
Most of the lacking features listed above are in a plan though. See roadmap and don't hesitate to contibute - working with ReasonML is so much fun!
Example
Here is an example of the fpack
usage:
$ fpack ./ui/index.js \
-o build \
-w \
--dev \
--nm "$(pwd)/node_modules" \
--nm node_modules \
--preprocess='^ui/.+\.js$' \
--preprocess='^node_modules/components/[^/]+\.js$'
Packed in 0.948s. Bundle: 5.87Mb. Modules: 1602. Cache: empty. Mode: development.
Watching file changes (Ctrl+C to stop)
$ fpack ./ui/index.js \
-o build \
-w \
--dev \
--nm "$(pwd)/node_modules" \
--nm node_modules \
--preprocess='^ui/.+\.js$' \
--preprocess='^node_modules/components/[^/]+\.js$'
Packed in 0.176s. Bundle: 5.87Mb. Modules: 1602. Cache: used. Mode: development.
Watching file changes (Ctrl+C to stop)
As you can see fpack
only accepts configuration as command-line arguments.
The second run is ~10 times faster than the first because of the persistent
cache. Rough flag meanings are:
./ui/index.js
denotes the entry point, this is the only positional argument;-o
specifies the name of the output directory, the bundle file will be namedbuild/index.js
;-w
watch mode;--nm
specifies the paths for resolving the package dependencies;--preprocess
specifies the filename patterns to be transpiled.
See detailed description of the configuration parameters here.
Thank you!
Fastpack would not be possible without prior work performed in following projects:
- OCaml / ReasonML: I cannot describe the pleasure working with this languages, you should try it yourself!
- Flow: We used their parser/AST code as the base.
- Esy:
package.json
-driven virtual environment for OCaml/ReasonML. Helps a lot to install/update dependencies, make releases and keep the environment sane. - All of these great libraries: Lwt, Cmdliner, Containers, and many more.