What is it?
$ npm install -g fpack
$ yarn add global fpack
If everything worked well, you should be able to run:
$ fpack --help
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.
- source maps support;
- development server / hot module reloading;
- Windows support (currently works on MacOS & Linux only);
Here is an example of the
$ 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 2.148s. 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.jsdenotes the entry point, this is the only positional argument;
-ospecifies the name of the output directory, the bundle file will be named
--nmspecifies the paths for resolving the package dependencies;
--preprocessspecifies the filename patterns to be transpiled.
See detailed description of the configuration parameters here.
Fastpack would not be possible without prior work performed in following projects:
- OCaml: I cannot describe the pleasure working with this language, you should try it yourself!
- Flow: We used their parser/AST code as the base.
package.json-driven virtual environment for OCaml. 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.