1 | [![NPM Version](http://img.shields.io/npm/v/persistify.svg?style=flat)](https://npmjs.org/package/persistify)
|
2 |
|
3 | # persistify
|
4 | `persistify` is a wrapper over watchify and browserify to make it easy to make incremental builds without having to rely on the `watch` mode for scenarios where a watch mode is not available. It reduces the build time from several seconds to milliseconds, without relying on a watch mode :)
|
5 |
|
6 | ## Motivation
|
7 | Just wanted to have a good wrapper over browserify/watchify that allow me to make incremental builds even when not using the watch mode.
|
8 |
|
9 | **DISCLAIMER**: this is done persisting the watchify arguments to disk using the [flat-cache](https://npmjs.org/package/flat-cache) and [file-entry-cache](https://npmjs.org/package/file-entry-cache) modules. The best results happen when only a few files were modified. Worse case scenario is when all the files are modified. In average you should experience a very noticeable reduction. As always keep in mind that your mileage may vary.
|
10 |
|
11 | ## TODO
|
12 |
|
13 | Add unit tests
|
14 |
|
15 | ## Install
|
16 |
|
17 | ```bash
|
18 | npm i -g persistify
|
19 | ```
|
20 |
|
21 | ## Examples
|
22 |
|
23 | ```bash
|
24 | # this will browserify src/foo.js and move it to dist/foo.js
|
25 | # the cache is constructed the first time the command is run so this might take a few
|
26 | # seconds depending on the complexity of the files you want to browserify
|
27 | persistify src/foo.js -o dist/foo.js
|
28 |
|
29 | # next builds will be benefited by the cache
|
30 | # noticeable reducing the building time
|
31 | persistify src/foo.js -o dist/foo.js
|
32 |
|
33 | # reconstruct the cache, this useful when a transform file has changed or
|
34 | # the cache just started to behave like a spoiled child
|
35 | persistify src/foo.js -o dist/foo.js --recreate
|
36 |
|
37 | # this will use the cache and watchify to provide faster startup times on watch mode
|
38 | persistify src/foo.js -o dist/foo.js --watch
|
39 |
|
40 | # this will just use the cache and use a transform
|
41 | # (all the parameters are just passed to browserify
|
42 | # so it should work with any transform)
|
43 | persistify src/foo.js -t babelify -o dist/foo.js --watch
|
44 | ```
|
45 |
|
46 | ## as a node module
|
47 |
|
48 | ```javascript
|
49 | var persistify = require( 'persistify' );
|
50 |
|
51 | var b = persistify( { }, { watch: true } );
|
52 |
|
53 | b.add( './demo/dep1.js' );
|
54 |
|
55 | b.on( 'bundle:done', function ( time ) {
|
56 | console.log( 'time', time );
|
57 | } );
|
58 |
|
59 | b.on( 'error', function ( err ) {
|
60 | console.log( 'error', err );
|
61 | } );
|
62 |
|
63 | function doBundle() {
|
64 | b.bundle( function ( err, buff ) {
|
65 | if ( err ) {
|
66 | throw err;
|
67 | }
|
68 | require( 'fs' ).writeFileSync( './dist/bundle.js', buff.toString() );
|
69 | } );
|
70 |
|
71 | }
|
72 |
|
73 | doBundle();
|
74 |
|
75 | b.on( 'update', function () {
|
76 | doBundle();
|
77 | } );
|
78 |
|
79 | ```
|
80 |
|
81 | ## FAQ
|
82 |
|
83 | ### your build does not include the latest changes to your files.
|
84 |
|
85 | Mmm... that's weird, but the option `--recreate` should destroy the cache and create it again
|
86 |
|
87 | ### I have added a new transform and the build is not using its
|
88 |
|
89 | Since persistify will only work on the files that have changed, and adding a transform
|
90 | does not cause a file change it is better to just use `--recreate` after adding a new trasform or plugin
|
91 |
|
92 | ## Changelog
|
93 |
|
94 | [Changelog](./changelog.md)
|
95 |
|
96 | ## License
|
97 |
|
98 | [MIT](./LICENSE)
|